Skip to content

Commit c08f145

Browse files
authored
Revert "Do not use cached properties for additionalProperties (#7955)" (#7971)
This reverts commit 057647c.
1 parent 057647c commit c08f145

File tree

9 files changed

+174
-172
lines changed

9 files changed

+174
-172
lines changed

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

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,17 +2573,26 @@ public int compare(CodegenProperty one, CodegenProperty another) {
25732573
}
25742574

25752575
// process 'additionalProperties'
2576-
setAddProps(schema, m);
2577-
// additionalProperties == True means that empty object will be used
2578-
// per the openapi spec, if additionalProperties is omitted it is defaulted to empty object
2579-
// so if we do that, set isAdditionalPropertiesTrue to True
2580-
// if an explicit schema is passed in to additionalProperties, set isAdditionalPropertiesTrue to False
2581-
if (schema.getAdditionalProperties() == null && !disallowAdditionalPropertiesIfNotPresent) {
2582-
m.isAdditionalPropertiesTrue = true;
2583-
} else if (schema.getAdditionalProperties() instanceof Boolean && Boolean.TRUE.equals(schema.getAdditionalProperties())) {
2584-
m.isAdditionalPropertiesTrue = true;
2576+
if (schema.getAdditionalProperties() == null) {
2577+
if (disallowAdditionalPropertiesIfNotPresent) {
2578+
m.isAdditionalPropertiesTrue = false;
2579+
} else {
2580+
m.isAdditionalPropertiesTrue = true;
2581+
CodegenProperty cp = fromProperty("", new Schema());
2582+
m.setAdditionalProperties(cp);
2583+
}
2584+
} else if (schema.getAdditionalProperties() instanceof Boolean) {
2585+
if (Boolean.TRUE.equals(schema.getAdditionalProperties())) {
2586+
m.isAdditionalPropertiesTrue = true;
2587+
CodegenProperty cp = fromProperty("", new Schema());
2588+
m.setAdditionalProperties(cp);
2589+
} else {
2590+
m.isAdditionalPropertiesTrue = false;
2591+
}
25852592
} else {
25862593
m.isAdditionalPropertiesTrue = false;
2594+
CodegenProperty cp = fromProperty("", (Schema) schema.getAdditionalProperties());
2595+
m.setAdditionalProperties(cp);
25872596
}
25882597

25892598
// post process model properties
@@ -3028,7 +3037,6 @@ public String getterAndSetterCapitalize(String name) {
30283037
* the (String name, Schema p) arguments.
30293038
* Any subsequent processing of the CodegenModel return value must be idempotent
30303039
* for a given (String name, Schema schema).
3031-
* Pass in null for the name to not use the schemaCodegenPropertyCache
30323040
*
30333041
* @param name name of the property
30343042
* @param p OAS property schema
@@ -3040,16 +3048,11 @@ public CodegenProperty fromProperty(String name, Schema p) {
30403048
return null;
30413049
}
30423050
LOGGER.debug("debugging fromProperty for " + name + " : " + p);
3043-
boolean nullName = (name == null);
30443051
NamedSchema ns = new NamedSchema(name, p);
3045-
if (!nullName) {
3046-
CodegenProperty cpc = schemaCodegenPropertyCache.get(ns);
3047-
if (cpc != null) {
3048-
LOGGER.debug("Cached fromProperty for " + name + " : " + p.getName());
3049-
return cpc;
3050-
}
3051-
} else {
3052-
name = "";
3052+
CodegenProperty cpc = schemaCodegenPropertyCache.get(ns);
3053+
if (cpc != null) {
3054+
LOGGER.debug("Cached fromProperty for " + name + " : " + p.getName());
3055+
return cpc;
30533056
}
30543057
// unalias schema
30553058
p = unaliasSchema(p, importMapping);
@@ -3373,9 +3376,7 @@ public CodegenProperty fromProperty(String name, Schema p) {
33733376

33743377
addVarsRequiredVarsAdditionaProps(p, property);
33753378
LOGGER.debug("debugging from property return: " + property);
3376-
if (!nullName) {
3377-
schemaCodegenPropertyCache.put(ns, property);
3378-
}
3379+
schemaCodegenPropertyCache.put(ns, property);
33793380
return property;
33803381
}
33813382

@@ -6161,25 +6162,6 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
61616162
return codegenParameter;
61626163
}
61636164

6164-
private void setAddProps(Schema schema, IJsonSchemaValidationProperties property){
6165-
Schema usedSchema = new Schema();
6166-
if (schema.getAdditionalProperties() == null) {
6167-
if (!disallowAdditionalPropertiesIfNotPresent) {
6168-
CodegenProperty cp = fromProperty(null, usedSchema);
6169-
property.setAdditionalProperties(cp);
6170-
}
6171-
} else if (schema.getAdditionalProperties() instanceof Boolean) {
6172-
if (Boolean.TRUE.equals(schema.getAdditionalProperties())) {
6173-
CodegenProperty cp = fromProperty(null, usedSchema);
6174-
property.setAdditionalProperties(cp);
6175-
}
6176-
} else {
6177-
usedSchema = (Schema) schema.getAdditionalProperties();
6178-
CodegenProperty cp = fromProperty(null, usedSchema);
6179-
property.setAdditionalProperties(cp);
6180-
}
6181-
}
6182-
61836165
private void addVarsRequiredVarsAdditionaProps(Schema schema, IJsonSchemaValidationProperties property){
61846166
if (!"object".equals(schema.getType())) {
61856167
return;
@@ -6196,7 +6178,20 @@ private void addVarsRequiredVarsAdditionaProps(Schema schema, IJsonSchemaValidat
61966178
.filter(p -> Boolean.TRUE.equals(p.required)).collect(Collectors.toList());
61976179
property.setRequiredVars(requireCpVars);
61986180
}
6199-
setAddProps(schema, property);
6181+
if (schema.getAdditionalProperties() == null) {
6182+
if (!disallowAdditionalPropertiesIfNotPresent) {
6183+
CodegenProperty cp = fromProperty("", new Schema());
6184+
property.setAdditionalProperties(cp);
6185+
}
6186+
} else if (schema.getAdditionalProperties() instanceof Boolean) {
6187+
if (Boolean.TRUE.equals(schema.getAdditionalProperties())) {
6188+
CodegenProperty cp = fromProperty("", new Schema());
6189+
property.setAdditionalProperties(cp);
6190+
}
6191+
} else {
6192+
CodegenProperty cp = fromProperty("", (Schema) schema.getAdditionalProperties());
6193+
property.setAdditionalProperties(cp);
6194+
}
62006195
return;
62016196
}
62026197

samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumArrays.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,6 @@ export interface EnumArrays {
3333
arrayEnum?: Array<EnumArraysArrayEnumEnum>;
3434
}
3535

36-
/**
37-
* @export
38-
* @enum {string}
39-
*/
40-
export enum EnumArraysJustSymbolEnum {
41-
GreaterThanOrEqualTo = '>=',
42-
Dollar = '$'
43-
}/**
44-
* @export
45-
* @enum {string}
46-
*/
47-
export enum EnumArraysArrayEnumEnum {
48-
Fish = 'fish',
49-
Crab = 'crab'
50-
}
51-
5236
export function EnumArraysFromJSON(json: any): EnumArrays {
5337
return EnumArraysFromJSONTyped(json, false);
5438
}
@@ -78,4 +62,21 @@ export function EnumArraysToJSON(value?: EnumArrays | null): any {
7862
};
7963
}
8064

65+
/**
66+
* @export
67+
* @enum {string}
68+
*/
69+
export enum EnumArraysJustSymbolEnum {
70+
GreaterThanOrEqualTo = '>=',
71+
Dollar = '$'
72+
}
73+
/**
74+
* @export
75+
* @enum {string}
76+
*/
77+
export enum EnumArraysArrayEnumEnum {
78+
Fish = 'fish',
79+
Crab = 'crab'
80+
}
81+
8182

samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumTest.ts

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -88,38 +88,6 @@ export interface EnumTest {
8888
outerEnumIntegerDefaultValue?: OuterEnumIntegerDefaultValue;
8989
}
9090

91-
/**
92-
* @export
93-
* @enum {string}
94-
*/
95-
export enum EnumTestEnumStringEnum {
96-
Upper = 'UPPER',
97-
Lower = 'lower',
98-
Empty = ''
99-
}/**
100-
* @export
101-
* @enum {string}
102-
*/
103-
export enum EnumTestEnumStringRequiredEnum {
104-
Upper = 'UPPER',
105-
Lower = 'lower',
106-
Empty = ''
107-
}/**
108-
* @export
109-
* @enum {string}
110-
*/
111-
export enum EnumTestEnumIntegerEnum {
112-
NUMBER_1 = 1,
113-
NUMBER_MINUS_1 = -1
114-
}/**
115-
* @export
116-
* @enum {string}
117-
*/
118-
export enum EnumTestEnumNumberEnum {
119-
NUMBER_1_DOT_1 = 1.1,
120-
NUMBER_MINUS_1_DOT_2 = -1.2
121-
}
122-
12391
export function EnumTestFromJSON(json: any): EnumTest {
12492
return EnumTestFromJSONTyped(json, false);
12593
}
@@ -161,4 +129,39 @@ export function EnumTestToJSON(value?: EnumTest | null): any {
161129
};
162130
}
163131

132+
/**
133+
* @export
134+
* @enum {string}
135+
*/
136+
export enum EnumTestEnumStringEnum {
137+
Upper = 'UPPER',
138+
Lower = 'lower',
139+
Empty = ''
140+
}
141+
/**
142+
* @export
143+
* @enum {string}
144+
*/
145+
export enum EnumTestEnumStringRequiredEnum {
146+
Upper = 'UPPER',
147+
Lower = 'lower',
148+
Empty = ''
149+
}
150+
/**
151+
* @export
152+
* @enum {string}
153+
*/
154+
export enum EnumTestEnumIntegerEnum {
155+
NUMBER_1 = 1,
156+
NUMBER_MINUS_1 = -1
157+
}
158+
/**
159+
* @export
160+
* @enum {string}
161+
*/
162+
export enum EnumTestEnumNumberEnum {
163+
NUMBER_1_DOT_1 = 1.1,
164+
NUMBER_MINUS_1_DOT_2 = -1.2
165+
}
166+
164167

samples/client/petstore/typescript-fetch/builds/default-v3.0/models/InlineObject2.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,6 @@ export interface InlineObject2 {
3333
enumFormString?: InlineObject2EnumFormStringEnum;
3434
}
3535

36-
/**
37-
* @export
38-
* @enum {string}
39-
*/
40-
export enum InlineObject2EnumFormStringArrayEnum {
41-
GreaterThan = '>',
42-
Dollar = '$'
43-
}/**
44-
* @export
45-
* @enum {string}
46-
*/
47-
export enum InlineObject2EnumFormStringEnum {
48-
Abc = '_abc',
49-
Efg = '-efg',
50-
Xyz = '(xyz)'
51-
}
52-
5336
export function InlineObject2FromJSON(json: any): InlineObject2 {
5437
return InlineObject2FromJSONTyped(json, false);
5538
}
@@ -79,4 +62,22 @@ export function InlineObject2ToJSON(value?: InlineObject2 | null): any {
7962
};
8063
}
8164

65+
/**
66+
* @export
67+
* @enum {string}
68+
*/
69+
export enum InlineObject2EnumFormStringArrayEnum {
70+
GreaterThan = '>',
71+
Dollar = '$'
72+
}
73+
/**
74+
* @export
75+
* @enum {string}
76+
*/
77+
export enum InlineObject2EnumFormStringEnum {
78+
Abc = '_abc',
79+
Efg = '-efg',
80+
Xyz = '(xyz)'
81+
}
82+
8283

samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MapTest.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ export interface MapTest {
4545
indirectMap?: { [key: string]: boolean; };
4646
}
4747

48-
/**
49-
* @export
50-
* @enum {string}
51-
*/
52-
export enum MapTestMapOfEnumStringEnum {
53-
Upper = 'UPPER',
54-
Lower = 'lower'
55-
}
56-
5748
export function MapTestFromJSON(json: any): MapTest {
5849
return MapTestFromJSONTyped(json, false);
5950
}
@@ -87,4 +78,13 @@ export function MapTestToJSON(value?: MapTest | null): any {
8778
};
8879
}
8980

81+
/**
82+
* @export
83+
* @enum {string}
84+
*/
85+
export enum MapTestMapOfEnumStringEnum {
86+
Upper = 'UPPER',
87+
Lower = 'lower'
88+
}
89+
9090

samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Order.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,6 @@ export interface Order {
5757
complete?: boolean;
5858
}
5959

60-
/**
61-
* @export
62-
* @enum {string}
63-
*/
64-
export enum OrderStatusEnum {
65-
Placed = 'placed',
66-
Approved = 'approved',
67-
Delivered = 'delivered'
68-
}
69-
7060
export function OrderFromJSON(json: any): Order {
7161
return OrderFromJSONTyped(json, false);
7262
}
@@ -104,4 +94,14 @@ export function OrderToJSON(value?: Order | null): any {
10494
};
10595
}
10696

97+
/**
98+
* @export
99+
* @enum {string}
100+
*/
101+
export enum OrderStatusEnum {
102+
Placed = 'placed',
103+
Approved = 'approved',
104+
Delivered = 'delivered'
105+
}
106+
107107

samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,6 @@ export interface Pet {
6868
status?: PetStatusEnum;
6969
}
7070

71-
/**
72-
* @export
73-
* @enum {string}
74-
*/
75-
export enum PetStatusEnum {
76-
Available = 'available',
77-
Pending = 'pending',
78-
Sold = 'sold'
79-
}
80-
8171
export function PetFromJSON(json: any): Pet {
8272
return PetFromJSONTyped(json, false);
8373
}
@@ -115,4 +105,14 @@ export function PetToJSON(value?: Pet | null): any {
115105
};
116106
}
117107

108+
/**
109+
* @export
110+
* @enum {string}
111+
*/
112+
export enum PetStatusEnum {
113+
Available = 'available',
114+
Pending = 'pending',
115+
Sold = 'sold'
116+
}
117+
118118

0 commit comments

Comments
 (0)