Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Normalizing vendor extension naming #5192

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions modules/openapi-generator-cli/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@
<level>ERROR</level>
</filter>
</appender>
<appender name="ONCELOGGER_COLOR" class="ch.qos.logback.core.ConsoleAppender">
<target>System.err</target>
<withJansi>true</withJansi>
<evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
<marker>ONCE</marker>
</evaluator>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>[%thread] %highlight(%-5level) %logger{36} - %red(%msg)%n</pattern>
</encoder>
</appender>

<logger name="io.swagger" level="warn">
<!-- Colorize by passing -Dcolor -->
Expand Down
11 changes: 11 additions & 0 deletions modules/openapi-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,22 @@
<version>${kotlin-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
<version>28.2-jre</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.util.*;

import static org.openapitools.codegen.utils.OnceLogger.once;
import static org.openapitools.codegen.utils.StringUtils.camelize;

public abstract class AbstractApexCodegen extends DefaultCodegen implements CodegenConfig {
Expand Down Expand Up @@ -455,9 +456,16 @@ public CodegenModel fromModel(String name, Schema model) {
}
}

cm.vendorExtensions.put("hasPropertyMappings", !propertyMappings.isEmpty());
cm.vendorExtensions.put("hasDefaultValues", hasDefaultValues);
cm.vendorExtensions.put("propertyMappings", propertyMappings);
// TODO: 5.0: Remove this block and ensure templates use the newer property naming.
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");
cm.vendorExtensions.put("hasPropertyMappings", !propertyMappings.isEmpty()); // TODO: 5.0 Remove
cm.vendorExtensions.put("hasDefaultValues", hasDefaultValues); // TODO: 5.0 Remove
cm.vendorExtensions.put("propertyMappings", propertyMappings); // TODO: 5.0 Remove


cm.vendorExtensions.put("x-has-property-mappings", !propertyMappings.isEmpty());
cm.vendorExtensions.put("x-has-default-values", hasDefaultValues);
cm.vendorExtensions.put("x-property-mappings", propertyMappings);

if (!propertyMappings.isEmpty()) {
cm.interfaces.add("OAS.MappedProperties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.File;
import java.util.*;

import static org.openapitools.codegen.utils.OnceLogger.once;
import static org.openapitools.codegen.utils.StringUtils.camelize;

public abstract class AbstractCSharpCodegen extends DefaultCodegen implements CodegenConfig {
Expand Down Expand Up @@ -562,12 +563,15 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
* @param models list of all models
*/
protected void updateValueTypeProperty(Map<String, Object> models) {
// TODO: 5.0: Remove the camelCased vendorExtension within the below loop and ensure templates use the newer property naming.
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");
for (Map.Entry<String, Object> entry : models.entrySet()) {
String openAPIName = entry.getKey();
CodegenModel model = ModelUtils.getModelByName(openAPIName, models);
if (model != null) {
for (CodegenProperty var : model.vars) {
var.vendorExtensions.put("isValueType", isValueType(var));
var.vendorExtensions.put("isValueType", isValueType(var)); // TODO: 5.0 Remove
var.vendorExtensions.put("x-is-value-type", isValueType(var));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.*;

import static com.google.common.base.Strings.isNullOrEmpty;
import static org.openapitools.codegen.utils.OnceLogger.once;
import static org.openapitools.codegen.utils.StringUtils.camelize;
import static org.openapitools.codegen.utils.StringUtils.underscore;

Expand Down Expand Up @@ -234,16 +235,20 @@ public void postProcessParameter(CodegenParameter parameter) {

char firstChar = parameter.paramName.charAt(0);

// TODO: 5.0: Remove the camelCased vendorExtension below and ensure templates use the newer property naming.
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");

if (Character.isUpperCase(firstChar)) {
// First char is already uppercase, just use paramName.
parameter.vendorExtensions.put("x-exportParamName", parameter.paramName);

parameter.vendorExtensions.put("x-exportParamName", parameter.paramName); // TODO: 5.0 Remove
parameter.vendorExtensions.put("x-export-param-name", parameter.paramName);
}

// It's a lowercase first char, let's convert it to uppercase
StringBuilder sb = new StringBuilder(parameter.paramName);
sb.setCharAt(0, Character.toUpperCase(firstChar));
parameter.vendorExtensions.put("x-exportParamName", sb.toString());
parameter.vendorExtensions.put("x-exportParamName", sb.toString()); // TODO: 5.0 Remove
parameter.vendorExtensions.put("x-export-param-name", sb.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.File;
import java.util.*;

import static org.openapitools.codegen.utils.OnceLogger.once;
import static org.openapitools.codegen.utils.StringUtils.camelize;
import static org.openapitools.codegen.utils.StringUtils.underscore;

Expand Down Expand Up @@ -388,6 +389,10 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
@SuppressWarnings("unchecked")
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");

// TODO: 5.0: Remove the camelCased vendorExtension below and ensure templates use the newer property naming.
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");

for (CodegenOperation operation : operations) {
// http method verb conversion (e.g. PUT => Put)
operation.httpMethod = camelize(operation.httpMethod.toLowerCase(Locale.ROOT));
Expand Down Expand Up @@ -450,26 +455,31 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
imports.add(createMapping("import", "github.com/antihax/optional"));
addedOptionalImport = true;
}

// We need to specially map Time type to the optionals package
if ("time.Time".equals(param.dataType)) {
param.vendorExtensions.put("x-optionalDataType", "Time");
param.vendorExtensions.put("x-optionalDataType", "Time"); // TODO: 5.0 Remove
param.vendorExtensions.put("x-optional-data-type", "Time");
} else {
// Map optional type to dataType
param.vendorExtensions.put("x-optionalDataType",
param.dataType.substring(0, 1).toUpperCase(Locale.ROOT) + param.dataType.substring(1));
String optionalType = param.dataType.substring(0, 1).toUpperCase(Locale.ROOT) + param.dataType.substring(1);
param.vendorExtensions.put("x-optionalDataType", optionalType); // TODO: 5.0 Remove
param.vendorExtensions.put("x-optional-data-type", optionalType);
}
}

// set x-exportParamName
char nameFirstChar = param.paramName.charAt(0);
if (Character.isUpperCase(nameFirstChar)) {
// First char is already uppercase, just use paramName.
param.vendorExtensions.put("x-exportParamName", param.paramName);
param.vendorExtensions.put("x-exportParamName", param.paramName); // TODO: 5.0 Remove
param.vendorExtensions.put("x-export-param-name", param.paramName);
} else {
// It's a lowercase first char, let's convert it to uppercase
StringBuilder sb = new StringBuilder(param.paramName);
sb.setCharAt(0, Character.toUpperCase(nameFirstChar));
param.vendorExtensions.put("x-exportParamName", sb.toString());
param.vendorExtensions.put("x-exportParamName", sb.toString()); // TODO: 5.0 Remove
param.vendorExtensions.put("x-x-export-param-name", sb.toString());
}
}

Expand Down Expand Up @@ -502,16 +512,22 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
}

private void setExportParameterName(List<CodegenParameter> codegenParameters) {

// TODO: 5.0: Remove the camelCased vendorExtension below and ensure templates use the newer property naming.
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");

for (CodegenParameter param : codegenParameters) {
char nameFirstChar = param.paramName.charAt(0);
if (Character.isUpperCase(nameFirstChar)) {
// First char is already uppercase, just use paramName.
param.vendorExtensions.put("x-exportParamName", param.paramName);
param.vendorExtensions.put("x-exportParamName", param.paramName); // TODO: 5.0 Remove
param.vendorExtensions.put("x-export-param-name", param.paramName);
} else {
// It's a lowercase first char, let's convert it to uppercase
StringBuilder sb = new StringBuilder(param.paramName);
sb.setCharAt(0, Character.toUpperCase(nameFirstChar));
param.vendorExtensions.put("x-exportParamName", sb.toString());
param.vendorExtensions.put("x-exportParamName", sb.toString()); // TODO: 5.0 Remove
param.vendorExtensions.put("x-export-param-name", sb.toString());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.*;
import java.util.regex.Pattern;

import static org.openapitools.codegen.utils.OnceLogger.once;
import static org.openapitools.codegen.utils.StringUtils.*;

public abstract class AbstractJavaCodegen extends DefaultCodegen implements CodegenConfig {
Expand Down Expand Up @@ -998,8 +999,13 @@ public CodegenModel fromModel(String name, Schema model) {
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
if (serializeBigDecimalAsString) {
if (property.baseType.equals("BigDecimal")) {

// TODO: 5.0: Remove the camelCased vendorExtension below and ensure templates use the newer property naming.
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");

// we serialize BigDecimal as `string` to avoid precision loss
property.vendorExtensions.put("extraAnnotation", "@JsonSerialize(using = ToStringSerializer.class)");
property.vendorExtensions.put("extraAnnotation", "@JsonSerialize(using = ToStringSerializer.class)"); // TODO: 5.0 Remove
property.vendorExtensions.put("x-extra-annotation", "@JsonSerialize(using = ToStringSerializer.class)");

// this requires some more imports to be added for this model...
model.imports.add("ToStringSerializer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.openapitools.codegen.utils.OnceLogger.once;
import static org.openapitools.codegen.utils.StringUtils.camelize;
import static org.openapitools.codegen.utils.StringUtils.underscore;

Expand Down Expand Up @@ -668,10 +669,15 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");

// TODO: 5.0: Remove the camelCased vendorExtension below and ensure templates use the newer property naming.
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");

for (CodegenOperation op : operationList) {
// for API test method name
// e.g. public function test{{vendorExtensions.x-testOperationId}}()
op.vendorExtensions.put("x-testOperationId", camelize(op.operationId));
op.vendorExtensions.put("x-testOperationId", camelize(op.operationId)); // TODO: 5.0 Remove
op.vendorExtensions.put("x-test-operation-id", camelize(op.operationId));
}
return objs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@

import org.openapitools.codegen.*;
import org.openapitools.codegen.meta.features.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

import static org.openapitools.codegen.utils.OnceLogger.once;


public class Apache2ConfigCodegen extends DefaultCodegen implements CodegenConfig {
public static final String USER_INFO_PATH = "userInfoPath";
private static final Logger LOGGER = LoggerFactory.getLogger(Apache2ConfigCodegen.class);

protected String userInfoPath = "/var/www/html/";

@Override
Expand Down Expand Up @@ -89,6 +95,10 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
List<CodegenOperation> newOpList = new ArrayList<CodegenOperation>();

// TODO: 5.0: Remove the camelCased vendorExtension below and ensure templates use the newer property naming.
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");

for (CodegenOperation op : operationList) {
String path = op.path;

Expand All @@ -101,7 +111,8 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
splitPath.add(item);
op.path += item + "/";
}
op.vendorExtensions.put("x-codegen-userInfoPath", userInfoPath);
op.vendorExtensions.put("x-codegen-userInfoPath", userInfoPath); // TODO: 5.0 Remove
op.vendorExtensions.put("x-codegen-user-info-path", userInfoPath);
boolean foundInNewList = false;
for (CodegenOperation op1 : newOpList) {
if (!foundInNewList) {
Expand All @@ -113,7 +124,8 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
}
op.operationIdCamelCase = op1.operationIdCamelCase;
currentOtherMethodList.add(op);
op1.vendorExtensions.put("x-codegen-otherMethods", currentOtherMethodList);
op1.vendorExtensions.put("x-codegen-otherMethods", currentOtherMethodList); // TODO: 5.0 Remove
op1.vendorExtensions.put("x-codegen-other-methods", currentOtherMethodList);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@
import org.openapitools.codegen.*;
import org.openapitools.codegen.meta.features.*;
import org.openapitools.codegen.utils.ModelUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.*;

import static org.openapitools.codegen.utils.OnceLogger.once;
import static org.openapitools.codegen.utils.StringUtils.dashize;
import static org.openapitools.codegen.utils.StringUtils.underscore;

public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(ClojureClientCodegen.class);
private static final String PROJECT_NAME = "projectName";
private static final String PROJECT_DESCRIPTION = "projectDescription";
private static final String PROJECT_VERSION = "projectVersion";
Expand All @@ -43,7 +47,8 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
private static final String PROJECT_LICENSE_URL = "projectLicenseUrl";
private static final String BASE_NAMESPACE = "baseNamespace";

static final String X_BASE_SPEC = "x-baseSpec";
static final String X_BASE_SPEC = "x-baseSpec"; // TODO: 5.0 Remove
static final String VENDOR_EXTENSION_X_BASE_SPEC = "x-base-spec";
static final String X_MODELS = "x-models";

protected String projectName;
Expand Down Expand Up @@ -198,19 +203,16 @@ public String toModelName(String name) {
public CodegenModel fromModel(String name, Schema mod) {
CodegenModel model = super.fromModel(name, mod);

// TODO: 5.0: Remove the camelCased vendorExtension below and ensure templates use the newer property naming.
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");

// If a var is a base spec we won't need to import it
for (CodegenProperty var : model.vars) {
if (baseSpecs.contains(var.complexType)) {
var.vendorExtensions.put(X_BASE_SPEC, true);
} else {
var.vendorExtensions.put(X_BASE_SPEC, false);
}
var.vendorExtensions.put(X_BASE_SPEC, baseSpecs.contains(var.complexType)); // TODO: 5.0 Remove
var.vendorExtensions.put(VENDOR_EXTENSION_X_BASE_SPEC, baseSpecs.contains(var.complexType));
if (var.items != null) {
if (baseSpecs.contains(var.items.complexType)) {
var.items.vendorExtensions.put(X_BASE_SPEC, true);
} else {
var.items.vendorExtensions.put(X_BASE_SPEC, false);
}
var.items.vendorExtensions.put(X_BASE_SPEC, baseSpecs.contains(var.items.complexType)); // TODO: 5.0 Remove
var.items.vendorExtensions.put(VENDOR_EXTENSION_X_BASE_SPEC, baseSpecs.contains(var.items.complexType));
}
}

Expand Down
Loading