diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index a13db5121fb6..2bb55e8dafea 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -2573,26 +2573,17 @@ public int compare(CodegenProperty one, CodegenProperty another) { } // process 'additionalProperties' - if (schema.getAdditionalProperties() == null) { - if (disallowAdditionalPropertiesIfNotPresent) { - m.isAdditionalPropertiesTrue = false; - } else { - m.isAdditionalPropertiesTrue = true; - CodegenProperty cp = fromProperty("", new Schema()); - m.setAdditionalProperties(cp); - } - } else if (schema.getAdditionalProperties() instanceof Boolean) { - if (Boolean.TRUE.equals(schema.getAdditionalProperties())) { - m.isAdditionalPropertiesTrue = true; - CodegenProperty cp = fromProperty("", new Schema()); - m.setAdditionalProperties(cp); - } else { - m.isAdditionalPropertiesTrue = false; - } + setAddProps(schema, m); + // additionalProperties == True means that empty object will be used + // per the openapi spec, if additionalProperties is omitted it is defaulted to empty object + // so if we do that, set isAdditionalPropertiesTrue to True + // if an explicit schema is passed in to additionalProperties, set isAdditionalPropertiesTrue to False + if (schema.getAdditionalProperties() == null && !disallowAdditionalPropertiesIfNotPresent) { + m.isAdditionalPropertiesTrue = true; + } else if (schema.getAdditionalProperties() instanceof Boolean && Boolean.TRUE.equals(schema.getAdditionalProperties())) { + m.isAdditionalPropertiesTrue = true; } else { m.isAdditionalPropertiesTrue = false; - CodegenProperty cp = fromProperty("", (Schema) schema.getAdditionalProperties()); - m.setAdditionalProperties(cp); } // post process model properties @@ -3037,6 +3028,7 @@ public String getterAndSetterCapitalize(String name) { * the (String name, Schema p) arguments. * Any subsequent processing of the CodegenModel return value must be idempotent * for a given (String name, Schema schema). + * Pass in null for the name to not use the schemaCodegenPropertyCache * * @param name name of the property * @param p OAS property schema @@ -3048,11 +3040,16 @@ public CodegenProperty fromProperty(String name, Schema p) { return null; } LOGGER.debug("debugging fromProperty for " + name + " : " + p); + boolean nullName = (name == null); NamedSchema ns = new NamedSchema(name, p); - CodegenProperty cpc = schemaCodegenPropertyCache.get(ns); - if (cpc != null) { - LOGGER.debug("Cached fromProperty for " + name + " : " + p.getName()); - return cpc; + if (!nullName) { + CodegenProperty cpc = schemaCodegenPropertyCache.get(ns); + if (cpc != null) { + LOGGER.debug("Cached fromProperty for " + name + " : " + p.getName()); + return cpc; + } + } else { + name = ""; } // unalias schema p = unaliasSchema(p, importMapping); @@ -3376,7 +3373,9 @@ public CodegenProperty fromProperty(String name, Schema p) { addVarsRequiredVarsAdditionaProps(p, property); LOGGER.debug("debugging from property return: " + property); - schemaCodegenPropertyCache.put(ns, property); + if (!nullName) { + schemaCodegenPropertyCache.put(ns, property); + } return property; } @@ -6162,6 +6161,25 @@ public CodegenParameter fromRequestBody(RequestBody body, Set imports, S return codegenParameter; } + private void setAddProps(Schema schema, IJsonSchemaValidationProperties property){ + Schema usedSchema = new Schema(); + if (schema.getAdditionalProperties() == null) { + if (!disallowAdditionalPropertiesIfNotPresent) { + CodegenProperty cp = fromProperty(null, usedSchema); + property.setAdditionalProperties(cp); + } + } else if (schema.getAdditionalProperties() instanceof Boolean) { + if (Boolean.TRUE.equals(schema.getAdditionalProperties())) { + CodegenProperty cp = fromProperty(null, usedSchema); + property.setAdditionalProperties(cp); + } + } else { + usedSchema = (Schema) schema.getAdditionalProperties(); + CodegenProperty cp = fromProperty(null, usedSchema); + property.setAdditionalProperties(cp); + } + } + private void addVarsRequiredVarsAdditionaProps(Schema schema, IJsonSchemaValidationProperties property){ if (!"object".equals(schema.getType())) { return; @@ -6178,20 +6196,7 @@ private void addVarsRequiredVarsAdditionaProps(Schema schema, IJsonSchemaValidat .filter(p -> Boolean.TRUE.equals(p.required)).collect(Collectors.toList()); property.setRequiredVars(requireCpVars); } - if (schema.getAdditionalProperties() == null) { - if (!disallowAdditionalPropertiesIfNotPresent) { - CodegenProperty cp = fromProperty("", new Schema()); - property.setAdditionalProperties(cp); - } - } else if (schema.getAdditionalProperties() instanceof Boolean) { - if (Boolean.TRUE.equals(schema.getAdditionalProperties())) { - CodegenProperty cp = fromProperty("", new Schema()); - property.setAdditionalProperties(cp); - } - } else { - CodegenProperty cp = fromProperty("", (Schema) schema.getAdditionalProperties()); - property.setAdditionalProperties(cp); - } + setAddProps(schema, property); return; } diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumArrays.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumArrays.ts index cfab553c7244..57c569031b47 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumArrays.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumArrays.ts @@ -33,6 +33,22 @@ export interface EnumArrays { arrayEnum?: Array; } +/** +* @export +* @enum {string} +*/ +export enum EnumArraysJustSymbolEnum { + GreaterThanOrEqualTo = '>=', + Dollar = '$' +}/** +* @export +* @enum {string} +*/ +export enum EnumArraysArrayEnumEnum { + Fish = 'fish', + Crab = 'crab' +} + export function EnumArraysFromJSON(json: any): EnumArrays { return EnumArraysFromJSONTyped(json, false); } @@ -62,21 +78,4 @@ export function EnumArraysToJSON(value?: EnumArrays | null): any { }; } -/** -* @export -* @enum {string} -*/ -export enum EnumArraysJustSymbolEnum { - GreaterThanOrEqualTo = '>=', - Dollar = '$' -} -/** -* @export -* @enum {string} -*/ -export enum EnumArraysArrayEnumEnum { - Fish = 'fish', - Crab = 'crab' -} - diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumTest.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumTest.ts index 3ba0162d6aba..fbd6a1cf2c8a 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumTest.ts @@ -88,6 +88,38 @@ export interface EnumTest { outerEnumIntegerDefaultValue?: OuterEnumIntegerDefaultValue; } +/** +* @export +* @enum {string} +*/ +export enum EnumTestEnumStringEnum { + Upper = 'UPPER', + Lower = 'lower', + Empty = '' +}/** +* @export +* @enum {string} +*/ +export enum EnumTestEnumStringRequiredEnum { + Upper = 'UPPER', + Lower = 'lower', + Empty = '' +}/** +* @export +* @enum {string} +*/ +export enum EnumTestEnumIntegerEnum { + NUMBER_1 = 1, + NUMBER_MINUS_1 = -1 +}/** +* @export +* @enum {string} +*/ +export enum EnumTestEnumNumberEnum { + NUMBER_1_DOT_1 = 1.1, + NUMBER_MINUS_1_DOT_2 = -1.2 +} + export function EnumTestFromJSON(json: any): EnumTest { return EnumTestFromJSONTyped(json, false); } @@ -129,39 +161,4 @@ export function EnumTestToJSON(value?: EnumTest | null): any { }; } -/** -* @export -* @enum {string} -*/ -export enum EnumTestEnumStringEnum { - Upper = 'UPPER', - Lower = 'lower', - Empty = '' -} -/** -* @export -* @enum {string} -*/ -export enum EnumTestEnumStringRequiredEnum { - Upper = 'UPPER', - Lower = 'lower', - Empty = '' -} -/** -* @export -* @enum {string} -*/ -export enum EnumTestEnumIntegerEnum { - NUMBER_1 = 1, - NUMBER_MINUS_1 = -1 -} -/** -* @export -* @enum {string} -*/ -export enum EnumTestEnumNumberEnum { - NUMBER_1_DOT_1 = 1.1, - NUMBER_MINUS_1_DOT_2 = -1.2 -} - diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/InlineObject2.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/InlineObject2.ts index fbbb7001c5fa..7c8694d56a47 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/InlineObject2.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/InlineObject2.ts @@ -33,6 +33,23 @@ export interface InlineObject2 { enumFormString?: InlineObject2EnumFormStringEnum; } +/** +* @export +* @enum {string} +*/ +export enum InlineObject2EnumFormStringArrayEnum { + GreaterThan = '>', + Dollar = '$' +}/** +* @export +* @enum {string} +*/ +export enum InlineObject2EnumFormStringEnum { + Abc = '_abc', + Efg = '-efg', + Xyz = '(xyz)' +} + export function InlineObject2FromJSON(json: any): InlineObject2 { return InlineObject2FromJSONTyped(json, false); } @@ -62,22 +79,4 @@ export function InlineObject2ToJSON(value?: InlineObject2 | null): any { }; } -/** -* @export -* @enum {string} -*/ -export enum InlineObject2EnumFormStringArrayEnum { - GreaterThan = '>', - Dollar = '$' -} -/** -* @export -* @enum {string} -*/ -export enum InlineObject2EnumFormStringEnum { - Abc = '_abc', - Efg = '-efg', - Xyz = '(xyz)' -} - diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MapTest.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MapTest.ts index de13e08cb689..ca67d6cc33cb 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MapTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MapTest.ts @@ -45,6 +45,15 @@ export interface MapTest { indirectMap?: { [key: string]: boolean; }; } +/** +* @export +* @enum {string} +*/ +export enum MapTestMapOfEnumStringEnum { + Upper = 'UPPER', + Lower = 'lower' +} + export function MapTestFromJSON(json: any): MapTest { return MapTestFromJSONTyped(json, false); } @@ -78,13 +87,4 @@ export function MapTestToJSON(value?: MapTest | null): any { }; } -/** -* @export -* @enum {string} -*/ -export enum MapTestMapOfEnumStringEnum { - Upper = 'UPPER', - Lower = 'lower' -} - diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Order.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Order.ts index 23c8e7524031..8ba94be0acd6 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Order.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Order.ts @@ -57,6 +57,16 @@ export interface Order { complete?: boolean; } +/** +* @export +* @enum {string} +*/ +export enum OrderStatusEnum { + Placed = 'placed', + Approved = 'approved', + Delivered = 'delivered' +} + export function OrderFromJSON(json: any): Order { return OrderFromJSONTyped(json, false); } @@ -94,14 +104,4 @@ export function OrderToJSON(value?: Order | null): any { }; } -/** -* @export -* @enum {string} -*/ -export enum OrderStatusEnum { - Placed = 'placed', - Approved = 'approved', - Delivered = 'delivered' -} - diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts index 24bb6915527e..f188f88dcee4 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts @@ -68,6 +68,16 @@ export interface Pet { status?: PetStatusEnum; } +/** +* @export +* @enum {string} +*/ +export enum PetStatusEnum { + Available = 'available', + Pending = 'pending', + Sold = 'sold' +} + export function PetFromJSON(json: any): Pet { return PetFromJSONTyped(json, false); } @@ -105,14 +115,4 @@ export function PetToJSON(value?: Pet | null): any { }; } -/** -* @export -* @enum {string} -*/ -export enum PetStatusEnum { - Available = 'available', - Pending = 'pending', - Sold = 'sold' -} - diff --git a/samples/client/petstore/typescript-fetch/builds/enum/models/InlineObject.ts b/samples/client/petstore/typescript-fetch/builds/enum/models/InlineObject.ts index a3b90dd840a1..e6592c5be29d 100644 --- a/samples/client/petstore/typescript-fetch/builds/enum/models/InlineObject.ts +++ b/samples/client/petstore/typescript-fetch/builds/enum/models/InlineObject.ts @@ -45,6 +45,24 @@ export interface InlineObject { nullableNumberEnum?: number | null; } +/** +* @export +* @enum {string} +*/ +export enum InlineObjectStringEnumEnum { + One = 'one', + Two = 'two', + Three = 'three' +}/** +* @export +* @enum {string} +*/ +export enum InlineObjectNumberEnumEnum { + NUMBER_1 = 1, + NUMBER_2 = 2, + NUMBER_3 = 3 +} + export function InlineObjectFromJSON(json: any): InlineObject { return InlineObjectFromJSONTyped(json, false); } @@ -78,23 +96,4 @@ export function InlineObjectToJSON(value?: InlineObject | null): any { }; } -/** -* @export -* @enum {string} -*/ -export enum InlineObjectStringEnumEnum { - One = 'one', - Two = 'two', - Three = 'three' -} -/** -* @export -* @enum {string} -*/ -export enum InlineObjectNumberEnumEnum { - NUMBER_1 = 1, - NUMBER_2 = 2, - NUMBER_3 = 3 -} - diff --git a/samples/client/petstore/typescript-fetch/builds/enum/models/InlineResponse200.ts b/samples/client/petstore/typescript-fetch/builds/enum/models/InlineResponse200.ts index 41aad0beccb5..5b410f1ca998 100644 --- a/samples/client/petstore/typescript-fetch/builds/enum/models/InlineResponse200.ts +++ b/samples/client/petstore/typescript-fetch/builds/enum/models/InlineResponse200.ts @@ -45,6 +45,24 @@ export interface InlineResponse200 { nullableNumberEnum?: number | null; } +/** +* @export +* @enum {string} +*/ +export enum InlineResponse200StringEnumEnum { + One = 'one', + Two = 'two', + Three = 'three' +}/** +* @export +* @enum {string} +*/ +export enum InlineResponse200NumberEnumEnum { + NUMBER_1 = 1, + NUMBER_2 = 2, + NUMBER_3 = 3 +} + export function InlineResponse200FromJSON(json: any): InlineResponse200 { return InlineResponse200FromJSONTyped(json, false); } @@ -78,23 +96,4 @@ export function InlineResponse200ToJSON(value?: InlineResponse200 | null): any { }; } -/** -* @export -* @enum {string} -*/ -export enum InlineResponse200StringEnumEnum { - One = 'one', - Two = 'two', - Three = 'three' -} -/** -* @export -* @enum {string} -*/ -export enum InlineResponse200NumberEnumEnum { - NUMBER_1 = 1, - NUMBER_2 = 2, - NUMBER_3 = 3 -} -