Skip to content

Commit

Permalink
Merge branch 'master' into ts-angular-ModuleWithProviders-fx
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMario authored Jul 21, 2021
2 parents 0f38d0c + f3710d3 commit 6c08748
Show file tree
Hide file tree
Showing 164 changed files with 3,190 additions and 633 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-generators</artifactId>
<version>1.0.24-SNAPSHOT</version>
<version>1.0.28-SNAPSHOT</version>
<packaging>jar</packaging>

<build>
Expand Down Expand Up @@ -252,10 +252,10 @@
</dependency>
</dependencies>
<properties>
<swagger-codegen-version>3.0.24-SNAPSHOT</swagger-codegen-version>
<swagger-parser-version>2.0.23</swagger-parser-version>
<swagger-core-version>2.1.4</swagger-core-version>
<jackson-version>2.10.3</jackson-version>
<swagger-codegen-version>3.0.28-SNAPSHOT</swagger-codegen-version>
<swagger-parser-version>2.0.27</swagger-parser-version>
<swagger-core-version>2.1.10</swagger-core-version>
<jackson-version>2.12.1</jackson-version>
<scala-version>2.11.1</scala-version>
<felix-version>3.3.0</felix-version>
<commons-io-version>2.4</commons-io-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,21 +396,25 @@ private String findEnumName(int truncateIdx, Object value) {
}

/**
* Returns the common prefix of variables for enum naming
* Returns the common prefix of variables for enum naming if
* two or more variables are present.
*
* @param vars List of variable names
* @return the common prefix for naming
*/
public String findCommonPrefixOfVars(List<Object> vars) {
try {
String[] listStr = vars.toArray(new String[vars.size()]);
String prefix = StringUtils.getCommonPrefix(listStr);
// exclude trailing characters that should be part of a valid variable
// e.g. ["status-on", "status-off"] => "status-" (not "status-o")
return prefix.replaceAll("[a-zA-Z0-9]+\\z", "");
} catch (ArrayStoreException e) {
return "";
if (vars.size() > 1) {
try {
String[] listStr = vars.toArray(new String[vars.size()]);
String prefix = StringUtils.getCommonPrefix(listStr);
// exclude trailing characters that should be part of a valid variable
// e.g. ["status-on", "status-off"] => "status-" (not "status-o")
return prefix.replaceAll("[a-zA-Z0-9]+\\z", "");
} catch (ArrayStoreException e) {
// do nothing, just return default value
}
}
return "";
}

/**
Expand Down Expand Up @@ -1475,6 +1479,8 @@ else if (schema instanceof ComposedSchema) {
addImport(codegenModel, "BigDecimal");
}
}
codegenModel.getVendorExtensions().put(CodegenConstants.IS_NULLABLE_EXT_NAME, Boolean.TRUE.equals(schema.getNullable()));

addVars(codegenModel, schema.getProperties(), schema.getRequired());
}

Expand Down Expand Up @@ -1580,9 +1586,8 @@ public CodegenProperty fromProperty(String name, Schema propertySchema) {
codegenProperty.defaultValue = toDefaultValue(propertySchema);
codegenProperty.defaultValueWithParam = toDefaultValueWithParam(name, propertySchema);
codegenProperty.jsonSchema = Json.pretty(propertySchema);
if (propertySchema.getNullable() != null) {
codegenProperty.nullable = propertySchema.getNullable();
}
codegenProperty.nullable = Boolean.TRUE.equals(propertySchema.getNullable());
codegenProperty.getVendorExtensions().put(CodegenConstants.IS_NULLABLE_EXT_NAME, Boolean.TRUE.equals(propertySchema.getNullable()));
if (propertySchema.getReadOnly() != null) {
codegenProperty.getVendorExtensions().put(CodegenConstants.IS_READ_ONLY_EXT_NAME, propertySchema.getReadOnly());
}
Expand Down Expand Up @@ -2150,8 +2155,12 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
codegenParameter.description = body.getDescription();
codegenParameter.unescapedDescription = body.getDescription();
codegenParameter.baseName = REQUEST_BODY_NAME;
codegenParameter.paramName = REQUEST_BODY_NAME;
String bodyName = REQUEST_BODY_NAME;
if (body.getExtensions() != null && body.getExtensions().get("x-codegen-request-body-name") != null) {
bodyName = body.getExtensions().get("x-codegen-request-body-name").toString();
}
codegenParameter.baseName = bodyName;
codegenParameter.paramName = bodyName;
codegenParameter.dataType = "Object";
codegenParameter.baseType = "Object";

Expand Down Expand Up @@ -2230,11 +2239,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
}
}

for (String i : imports) {
if (needToImport(i)) {
codegenOperation.imports.add(i);
}
}
addOperationImports(codegenOperation, imports);

codegenOperation.bodyParam = bodyParam;
codegenOperation.httpMethod = httpMethod.toUpperCase();
Expand Down Expand Up @@ -2288,6 +2293,14 @@ public int compare(CodegenParameter one, CodegenParameter another) {
return codegenOperation;
}

protected void addOperationImports(CodegenOperation codegenOperation, Set<String> operationImports) {
for (String operationImport : operationImports) {
if (needToImport(operationImport)) {
codegenOperation.imports.add(operationImport);
}
}
}

/**
* Convert Swagger Response object to Codegen Response object
*
Expand Down Expand Up @@ -2516,14 +2529,14 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
LOGGER.warn("warning! Schema not found for parameter \"" + parameter.getName() + "\", using String");
parameterSchema = new StringSchema().description("//TODO automatically added by swagger-codegen.");
}
if (Boolean.TRUE.equals(parameterSchema.getNullable())) {
codegenParameter.nullable = true;
}
CodegenProperty codegenProperty = fromProperty(parameter.getName(), parameterSchema);

// set boolean flag (e.g. isString)
setParameterBooleanFlagWithCodegenProperty(codegenParameter, codegenProperty);
setParameterNullable(codegenParameter, codegenProperty);
setParameterNullable(codegenParameter, codegenProperty); //todo: needs to be removed

codegenParameter.nullable = Boolean.TRUE.equals(parameterSchema.getNullable());
codegenParameter.getVendorExtensions().put(CodegenConstants.IS_NULLABLE_EXT_NAME, Boolean.TRUE.equals(parameterSchema.getNullable()));

codegenParameter.dataType = codegenProperty.datatype;
codegenParameter.dataFormat = codegenProperty.dataFormat;
Expand Down Expand Up @@ -2653,8 +2666,13 @@ else if (parameter instanceof FormParameter) {

public CodegenParameter fromRequestBody(RequestBody body, String name, Schema schema, Map<String, Schema> schemas, Set<String> imports) {
CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
codegenParameter.baseName = REQUEST_BODY_NAME;
codegenParameter.paramName = REQUEST_BODY_NAME;

String bodyName = REQUEST_BODY_NAME;
if (body.getExtensions() != null && body.getExtensions().get("x-codegen-request-body-name") != null) {
bodyName = body.getExtensions().get("x-codegen-request-body-name").toString();
}
codegenParameter.baseName = bodyName;
codegenParameter.paramName = bodyName;
codegenParameter.description = body.getDescription();
codegenParameter.unescapedDescription = body.getDescription();
codegenParameter.required = body.getRequired() != null ? body.getRequired() : Boolean.FALSE;
Expand Down Expand Up @@ -2765,7 +2783,7 @@ else if (schema instanceof BinarySchema) {
codegenParameter.getVendorExtensions().put(CodegenConstants.IS_BINARY_EXT_NAME, Boolean.TRUE);
}
else {
CodegenProperty codegenProperty = fromProperty(REQUEST_BODY_NAME, schema);
CodegenProperty codegenProperty = fromProperty(bodyName, schema);
codegenParameter.dataType = codegenProperty.datatype;
codegenParameter.baseType = codegenProperty.baseType;
if (codegenProperty.complexType != null) {
Expand Down Expand Up @@ -2892,6 +2910,11 @@ protected void setReservedWordsLowerCase(List<String> words) {
}
}

protected void setReservedWords(List<String> words) {
reservedWords = new HashSet<String>();
reservedWords.addAll(words);
}

protected boolean isReservedWord(String word) {
return word != null && reservedWords.contains(word.toLowerCase());
}
Expand Down Expand Up @@ -4368,8 +4391,11 @@ protected void addParameters(CodegenContent codegenContent, List<CodegenParamete

protected void addCodegenContentParameters(CodegenOperation codegenOperation, List<CodegenContent> codegenContents) {
for (CodegenContent content : codegenContents) {
addParameters(content, codegenOperation.bodyParams);
addParameters(content, codegenOperation.formParams);
if (content.getIsForm()) {
addParameters(content, codegenOperation.formParams);
} else {
addParameters(content, codegenOperation.bodyParams);
}
addParameters(content, codegenOperation.headerParams);
addParameters(content, codegenOperation.queryParams);
addParameters(content, codegenOperation.pathParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ protected CodegenModel processArrayItemSchema(String codegenModelName, CodegenPr
return null;
}
this.updatePropertyDataType(codegenProperty, composedModel.name, arraySchema);
this.updatePropertyDataType(codegenProperty.items, composedModel);
return composedModel;
}
return null;
Expand Down Expand Up @@ -208,6 +209,7 @@ protected void updatePropertyDataType(CodegenProperty codegenProperty, String sc
arraySchema.setItems(refSchema);
codegenProperty.setDatatype(this.codegenConfig.getTypeDeclaration(arraySchema));
codegenProperty.setDatatypeWithEnum(codegenProperty.getDatatype());
codegenProperty.vendorExtensions.put("x-is-composed", true);

codegenProperty.defaultValue = this.codegenConfig.toDefaultValue(arraySchema);
codegenProperty.defaultValueWithParam = this.codegenConfig.toDefaultValueWithParam(codegenProperty.baseName, arraySchema);
Expand All @@ -224,6 +226,8 @@ protected void updateArrayModel(CodegenModel codegenModel, String schemaName, Ar
this.codegenConfig.addParentContainer(codegenModel, codegenModel.name, arraySchema);
codegenModel.defaultValue = this.codegenConfig.toDefaultValue(arraySchema);
codegenModel.arrayModelType = this.codegenConfig.fromProperty(codegenModel.name, arraySchema).complexType;
boolean isInterface = codegenModel.arrayModelType.startsWith(ALL_OF_PREFFIX) || codegenModel.arrayModelType.startsWith(ONE_OF_PREFFIX) || codegenModel.arrayModelType.startsWith(ANY_OF_PREFFIX);
codegenModel.getVendorExtensions().put("x-array-model-type-is-interface", isInterface);

arraySchema.setItems(items);
}
Expand All @@ -233,5 +237,6 @@ private void updatePropertyDataType(CodegenProperty codegenProperty, CodegenMode
codegenProperty.datatypeWithEnum = composedModel.getClassname();
codegenProperty.baseType = composedModel.getClassname();
codegenProperty.complexType = composedModel.getClassname();
codegenProperty.vendorExtensions.put("x-is-composed", true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ public AbstractCSharpCodegen() {
Arrays.asList("IDictionary")
);

setReservedWordsLowerCase(
setReservedWords(
Arrays.asList(
// set "client" as a reserved word to avoid conflicts with IO.Swagger.Client
// this is a workaround and can be removed if c# api client is updated to use
// fully qualified name
"Client", "client", "parameter", "File",
"Client", "client", "parameter", "File", "List", "list",
// local variable names in API methods (endpoints)
"localVarPath", "localVarPathParams", "localVarQueryParams", "localVarHeaderParams",
"localVarFormParams", "localVarFileParams", "localVarStatusCode", "localVarResponse",
"localVarPostBody", "localVarHttpHeaderAccepts", "localVarHttpHeaderAccept",
"localVarHttpContentTypes", "localVarHttpContentType",
"localVarStatusCode",
"localVarStatusCode", "ApiResponse", "apiresponse",
// C# reserved words
"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked",
"class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else",
Expand Down Expand Up @@ -743,19 +743,14 @@ public String toDefaultValue(Schema schema) {
@Override
protected boolean isReservedWord(String word) {
// NOTE: This differs from super's implementation in that C# does _not_ want case insensitive matching.
return reservedWords.contains(word);
return reservedWords.contains(word.toLowerCase());
}

@Override
public String getSchemaType(Schema propertySchema) {
String swaggerType = super.getSchemaType(propertySchema);

if (propertySchema.get$ref() != null) {
final Schema refSchema = OpenAPIUtil.getSchemaFromName(swaggerType, this.openAPI);
if (refSchema != null && !isObjectSchema(refSchema) && !(refSchema instanceof ArraySchema || refSchema instanceof MapSchema) && refSchema.getEnum() == null) {
swaggerType = super.getSchemaType(refSchema);
}
}
swaggerType = getRefSchemaTargetType(propertySchema, swaggerType);

String type;

Expand All @@ -775,6 +770,20 @@ public String getSchemaType(Schema propertySchema) {
return toModelName(type);
}

protected String getRefSchemaTargetType(Schema schema, String schemaType) {
if (schemaType == null) {
return null;
}
if (schema != null && schema.get$ref() != null) {
final Schema refSchema = OpenAPIUtil.getSchemaFromName(schemaType, this.openAPI);
if (refSchema != null && !isObjectSchema(refSchema) && !(refSchema instanceof ArraySchema || refSchema instanceof MapSchema) && refSchema.getEnum() == null) {
schemaType = super.getSchemaType(refSchema);
}
}
return schemaType;

}

/**
* Provides C# strongly typed declaration for simple arrays of some type and arrays of arrays of some type.
* @param arr The input array property
Expand Down Expand Up @@ -1090,7 +1099,11 @@ public void addHandlebarHelpers(Handlebars handlebars) {
@Override
protected void addCodegenContentParameters(CodegenOperation codegenOperation, List<CodegenContent> codegenContents) {
for (CodegenContent content : codegenContents) {
addParameters(content, codegenOperation.bodyParams);
if (content.getIsForm()) {
addParameters(content, codegenOperation.formParams);
} else {
addParameters(content, codegenOperation.bodyParams);
}
addParameters(content, codegenOperation.headerParams);
addParameters(content, codegenOperation.queryParams);
addParameters(content, codegenOperation.pathParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import io.swagger.codegen.v3.CodegenProperty;
import io.swagger.codegen.v3.CodegenType;
import io.swagger.codegen.v3.SupportingFile;
import io.swagger.codegen.v3.generators.util.OpenAPIUtil;
import io.swagger.v3.oas.models.media.Schema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -492,19 +491,6 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
return objs;
}

@Override
public String getSchemaType(Schema schema) {
String schemaType = super.getSchemaType(schema);

if (schema.get$ref() != null) {
final Schema refSchema = OpenAPIUtil.getSchemaFromName(schemaType, this.openAPI);
if (refSchema != null && !isObjectSchema(refSchema) && (refSchema.getEnum() == null || refSchema.getEnum().isEmpty())) {
schemaType = super.getSchemaType(refSchema);
}
}
return schemaType;
}

@Override
public CodegenType getTag() {
return CodegenType.CLIENT;
Expand Down Expand Up @@ -614,8 +600,8 @@ public void postProcessPattern(String pattern, Map<String, Object> vendorExtensi

//Must follow Perl /pattern/modifiers convention
if (pattern.charAt(0) != '/' || i < 2) {
throw new IllegalArgumentException("Pattern must follow the Perl "
+ "/pattern/modifiers convention. " + pattern + " is not valid.");
pattern = String.format("/%s/", pattern);;
i = pattern.lastIndexOf('/');
}

String regex = pattern.substring(1, i).replace("'", "\'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ private Object resolveSchemaToExample(String propertyName, String mediaType, Sch
Schema innerType = ((ArraySchema) schema).getItems();
if (innerType != null) {
int arrayLength = schema.getMaxItems() != null ? schema.getMaxItems() : 2;
if (arrayLength > 10) {
logger.warn("value of maxItems of property {} is {}; limiting to 10 examples", schema, arrayLength);
arrayLength = 10;
}
Object[] objectProperties = new Object[arrayLength];
Object objProperty = resolveSchemaToExample(propertyName, mediaType, innerType, processedModels);
for(int i=0; i < arrayLength; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,7 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
imports.add(createMapping("import", "time"));
addedTimeImport = true;
}
}

// import "optionals" package if the parameter is primitive and optional
if (!param.required && param.getIsPrimitiveType()) {
} else {
if (!addedOptionalImport) {
imports.add(createMapping("import", "github.com/antihax/optional"));
addedOptionalImport = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void processOpts() {
* it will be processed by the template engine. Otherwise, it will be copied
*/
supportingFiles.add(new SupportingFile("swagger.mustache", "api", "swagger.yaml"));
supportingFiles.add(new SupportingFile("Dockerfile", "", "Dockerfile"));
supportingFiles.add(new SupportingFile("main.mustache", "", "main.go"));
supportingFiles.add(new SupportingFile("routers.mustache", apiPath, "routers.go"));
supportingFiles.add(new SupportingFile("logger.mustache", apiPath, "logger.go"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public String concat(String element, Options options) {
return builder.toString();
}

public String toLowerCase(String string) {
return string.toLowerCase();
}

public String backSlash() {
return "\\";
}
Expand Down
Loading

0 comments on commit 6c08748

Please sign in to comment.