Skip to content

Commit b0d221e

Browse files
Merge branch 'master' of github.com:CiscoM31/openapi-generator into python-null-type
2 parents 6b9c0ce + 15d58dc commit b0d221e

File tree

134 files changed

+4960
-4044
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+4960
-4044
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,8 @@ If you want to join the committee, please kindly apply by sending an email to te
962962
| PowerShell | |
963963
| Python | @taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) @Jyhess (2019/01) @slash-arun (2019/11) @spacether (2019/11) |
964964
| R | @Ramanth (2019/07) @saigiridhar21 (2019/07) |
965-
| Ruby | @cliffano (2017/07) @zlx (2017/09) @autopp (2019/02) |
966-
| Rust | @frol (2017/07) @farcaller (2017/08) @bjgill (2017/12) @richardwhiuk (2019/07) |
965+
| Ruby | @cliffano (2017/07) @zlx (2017/09) @autopp (2019/02) |
966+
| Rust | @frol (2017/07) @farcaller (2017/08) @bjgill (2017/12) @richardwhiuk (2019/07) @paladinzh (2020/05) |
967967
| Scala | @clasnake (2017/07), @jimschubert (2017/09) [:heart:](https://www.patreon.com/jimschubert), @shijinkui (2018/01), @ramzimaalej (2018/03), @chameleon82 (2020/03), @Bouillie (2020/04) |
968968
| Swift | @jgavris (2017/07) @ehyche (2017/08) @Edubits (2017/09) @jaz-ah (2017/09) @4brunu (2019/11) |
969969
| TypeScript | @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) |

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,26 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
7474
public Set<String> allMandatory = new TreeSet<String>(); // with parent's required properties
7575

7676
public Set<String> imports = new TreeSet<String>();
77-
public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, isNullable, hasRequired, hasOptional, isArrayModel, hasChildren, isMapModel, isDeprecated;
77+
public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum;
78+
/**
79+
* Indicates the OAS schema specifies "nullable: true".
80+
*/
81+
public boolean isNullable;
82+
/**
83+
* Indicates the type has at least one required property.
84+
*/
85+
public boolean hasRequired;
86+
/**
87+
* Indicates the type has at least one optional property.
88+
*/
89+
public boolean hasOptional;
90+
public boolean isArrayModel;
91+
public boolean hasChildren;
92+
public boolean isMapModel;
93+
/**
94+
* Indicates the OAS schema specifies "deprecated: true".
95+
*/
96+
public boolean isDeprecated;
7897
public boolean hasOnlyReadOnly = true; // true if all properties are read-only
7998
public ExternalDocumentation externalDocumentation;
8099

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,7 @@ public String lowerCamelCase(String name) {
20072007
}
20082008

20092009
/**
2010-
* Output the type declaration of a given name
2010+
* Output the language-specific type declaration of a given OAS name.
20112011
*
20122012
* @param name name
20132013
* @return a string presentation of the type
@@ -2018,15 +2018,15 @@ public String getTypeDeclaration(String name) {
20182018
}
20192019

20202020
/**
2021-
* Output the type declaration of the property
2021+
* Output the language-specific type declaration of the property.
20222022
*
20232023
* @param schema property schema
20242024
* @return a string presentation of the property type
20252025
*/
20262026
public String getTypeDeclaration(Schema schema) {
20272027
if (schema == null) {
2028-
LOGGER.warn("Null schema found. Default type to `NULL_SCHMEA_ERR`");
2029-
return "NULL_SCHMEA_ERR";
2028+
LOGGER.warn("Null schema found. Default type to `NULL_SCHEMA_ERR`");
2029+
return "NULL_SCHEMA_ERR";
20302030
}
20312031

20322032
String oasType = getSchemaType(schema);
@@ -2812,7 +2812,7 @@ public String getterAndSetterCapitalize(String name) {
28122812
* Convert OAS Property object to Codegen Property object
28132813
*
28142814
* @param name name of the property
2815-
* @param p OAS property object
2815+
* @param p OAS property schema
28162816
* @return Codegen Property object
28172817
*/
28182818
public CodegenProperty fromProperty(String name, Schema p) {

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
417417
final Map<String, Object> processed = super.postProcessAllModels(objs);
418418
postProcessEnumRefs(processed);
419419
updateValueTypeProperty(processed);
420+
updateNullableTypeProperty(processed);
420421
return processed;
421422
}
422423

@@ -603,6 +604,25 @@ protected void updateValueTypeProperty(Map<String, Object> models) {
603604
}
604605
}
605606

607+
/**
608+
* Update property if it is a C# nullable type
609+
*
610+
* @param models list of all models
611+
*/
612+
protected void updateNullableTypeProperty(Map<String, Object> models) {
613+
for (Map.Entry<String, Object> entry : models.entrySet()) {
614+
String openAPIName = entry.getKey();
615+
CodegenModel model = ModelUtils.getModelByName(openAPIName, models);
616+
if (model != null) {
617+
for (CodegenProperty var : model.vars) {
618+
if (!var.isContainer && (nullableType.contains(var.dataType) || var.isEnum)) {
619+
var.vendorExtensions.put("x-csharp-value-type", true);
620+
}
621+
}
622+
}
623+
}
624+
}
625+
606626
@Override
607627
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
608628
super.postProcessOperationsWithModels(objs, allModels);
@@ -678,6 +698,9 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
678698
}
679699
}
680700
}
701+
} else {
702+
// Effectively mark enum models as enums
703+
updateCodegenParametersEnum(operation.allParams, allModels);
681704
}
682705

683706
processOperation(operation);
@@ -692,6 +715,37 @@ protected void processOperation(CodegenOperation operation) {
692715
// default noop
693716
}
694717

718+
private void updateCodegenParametersEnum(List<CodegenParameter> parameters, List<Object> allModels) {
719+
for (CodegenParameter parameter : parameters) {
720+
CodegenModel model = null;
721+
for (Object modelHashMap : allModels) {
722+
CodegenModel codegenModel = ((HashMap<String, CodegenModel>) modelHashMap).get("model");
723+
if (codegenModel.getClassname().equals(parameter.dataType)) {
724+
model = codegenModel;
725+
break;
726+
}
727+
}
728+
729+
if (model != null) {
730+
// Effectively mark enum models as enums and non-nullable
731+
if (model.isEnum) {
732+
parameter.isEnum = true;
733+
parameter.allowableValues = model.allowableValues;
734+
parameter.isPrimitiveType = true;
735+
parameter.vendorExtensions.put("x-csharp-value-type", true);
736+
}
737+
}
738+
739+
if (!parameter.isContainer && nullableType.contains(parameter.dataType)) {
740+
parameter.vendorExtensions.put("x-csharp-value-type", true);
741+
}
742+
743+
if (!parameter.required && parameter.vendorExtensions.get("x-csharp-value-type") != null) { //optional
744+
parameter.dataType = parameter.dataType + "?";
745+
}
746+
}
747+
}
748+
695749
@Override
696750
public String apiFileFolder() {
697751
return outputFolder + File.separator + sourceFolder + File.separator + packageName + File.separator + apiPackage();

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractScalaCodegen.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,4 +563,8 @@ public String toOperationId(String operationId) {
563563
return operationId;
564564
}
565565

566+
public void setInvokerPackage(String invokerPackage) {
567+
this.invokerPackage = invokerPackage;
568+
}
569+
566570
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,6 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
423423
postProcessEmitDefaultValue(property.vendorExtensions);
424424

425425
super.postProcessModelProperty(model, property);
426-
427-
if (!property.isContainer && (nullableType.contains(property.dataType) || property.isEnum)) {
428-
property.vendorExtensions.put("x-csharp-value-type", true);
429-
}
430426
}
431427

432428
@Override
@@ -461,14 +457,6 @@ public void postProcessParameter(CodegenParameter parameter) {
461457
postProcessPattern(parameter.pattern, parameter.vendorExtensions);
462458
postProcessEmitDefaultValue(parameter.vendorExtensions);
463459
super.postProcessParameter(parameter);
464-
465-
if (nullableType.contains(parameter.dataType)) {
466-
if (!parameter.required) { //optional
467-
parameter.dataType = parameter.dataType + "?";
468-
} else {
469-
parameter.vendorExtensions.put("x-csharp-value-type", true);
470-
}
471-
}
472460
}
473461

474462
/*

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ public void processOpts() {
240240
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
241241
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
242242

243+
final String authFolder = libFolder + File.separator + "auth";
244+
supportingFiles.add(new SupportingFile("auth/api_key_auth.mustache", authFolder, "api_key_auth.dart"));
245+
supportingFiles.add(new SupportingFile("auth/basic_auth.mustache", authFolder, "basic_auth.dart"));
246+
supportingFiles.add(new SupportingFile("auth/oauth.mustache", authFolder, "oauth.dart"));
247+
supportingFiles.add(new SupportingFile("auth/auth.mustache", authFolder, "auth.dart"));
248+
243249
if ("core".equals(dateLibrary)) {
244250
additionalProperties.put("core", "true");
245251
typeMapping.put("Date", "DateTime");

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public ScalaAkkaClientCodegen() {
9999
"trait", "try", "true", "type", "val", "var", "while", "with", "yield")
100100
);
101101

102-
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
103102
additionalProperties.put(CodegenConstants.GROUP_ID, groupId);
104103
additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId);
105104
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
@@ -112,7 +111,6 @@ public ScalaAkkaClientCodegen() {
112111
additionalProperties.put("fnCapitalize", new CapitalizeLambda());
113112
additionalProperties.put("fnCamelize", new CamelizeLambda(false));
114113
additionalProperties.put("fnEnumEntry", new EnumEntryLambda());
115-
additionalProperties.put("mainPackage", mainPackage);
116114

117115
importMapping.remove("Seq");
118116
importMapping.remove("List");
@@ -146,16 +144,25 @@ public ScalaAkkaClientCodegen() {
146144
@Override
147145
public void processOpts() {
148146
super.processOpts();
147+
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
148+
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
149+
}
149150
if (additionalProperties.containsKey("mainPackage")) {
150151
setMainPackage((String) additionalProperties.get("mainPackage"));
151152
additionalProperties.replace("configKeyPath", this.configKeyPath);
152-
apiPackage = mainPackage + ".api";
153-
modelPackage = mainPackage + ".model";
154-
invokerPackage = mainPackage + ".core";
155-
additionalProperties.put("apiPackage", apiPackage);
156-
additionalProperties.put("modelPackage", modelPackage);
157-
additionalProperties.put("invokerPackage", invokerPackage);
153+
if (!additionalProperties.containsKey(CodegenConstants.API_PACKAGE)){
154+
apiPackage = mainPackage + ".api";
155+
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
156+
}
157+
if (!additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)){
158+
modelPackage = mainPackage + ".model";
159+
additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
160+
}
161+
if (!additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)){
162+
invokerPackage = mainPackage + ".core";
163+
}
158164
}
165+
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
159166

160167
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
161168
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));

0 commit comments

Comments
 (0)