Revert "Do not use cached properties for additionalProperties (#7955)" (#7971)

This reverts commit 057647cf1ee0793f2987e89f8a588aa3db3ceb5d.
This commit is contained in:
Justin Black 2020-11-17 21:08:55 -08:00 committed by GitHub
parent 057647cf1e
commit c08f14500e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 174 additions and 172 deletions

View File

@ -2573,18 +2573,27 @@ public class DefaultCodegen implements CodegenConfig {
}
// process 'additionalProperties'
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) {
if (schema.getAdditionalProperties() == null) {
if (disallowAdditionalPropertiesIfNotPresent) {
m.isAdditionalPropertiesTrue = false;
} else {
m.isAdditionalPropertiesTrue = true;
} else if (schema.getAdditionalProperties() instanceof Boolean && Boolean.TRUE.equals(schema.getAdditionalProperties())) {
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;
}
} else {
m.isAdditionalPropertiesTrue = false;
CodegenProperty cp = fromProperty("", (Schema) schema.getAdditionalProperties());
m.setAdditionalProperties(cp);
}
// post process model properties
if (m.vars != null) {
@ -3028,7 +3037,6 @@ public class DefaultCodegen implements CodegenConfig {
* 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
@ -3040,17 +3048,12 @@ public class DefaultCodegen implements CodegenConfig {
return null;
}
LOGGER.debug("debugging fromProperty for " + name + " : " + p);
boolean nullName = (name == null);
NamedSchema ns = new NamedSchema(name, p);
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);
@ -3373,9 +3376,7 @@ public class DefaultCodegen implements CodegenConfig {
addVarsRequiredVarsAdditionaProps(p, property);
LOGGER.debug("debugging from property return: " + property);
if (!nullName) {
schemaCodegenPropertyCache.put(ns, property);
}
return property;
}
@ -6161,25 +6162,6 @@ public class DefaultCodegen implements CodegenConfig {
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;
@ -6196,7 +6178,20 @@ public class DefaultCodegen implements CodegenConfig {
.filter(p -> Boolean.TRUE.equals(p.required)).collect(Collectors.toList());
property.setRequiredVars(requireCpVars);
}
setAddProps(schema, property);
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);
}
return;
}

View File

@ -33,22 +33,6 @@ export interface EnumArrays {
arrayEnum?: Array<EnumArraysArrayEnumEnum>;
}
/**
* @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);
}
@ -78,4 +62,21 @@ 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'
}

View File

@ -88,38 +88,6 @@ 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);
}
@ -161,4 +129,39 @@ 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
}

View File

@ -33,23 +33,6 @@ 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);
}
@ -79,4 +62,22 @@ 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)'
}

View File

@ -45,15 +45,6 @@ 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);
}
@ -87,4 +78,13 @@ export function MapTestToJSON(value?: MapTest | null): any {
};
}
/**
* @export
* @enum {string}
*/
export enum MapTestMapOfEnumStringEnum {
Upper = 'UPPER',
Lower = 'lower'
}

View File

@ -57,16 +57,6 @@ 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);
}
@ -104,4 +94,14 @@ export function OrderToJSON(value?: Order | null): any {
};
}
/**
* @export
* @enum {string}
*/
export enum OrderStatusEnum {
Placed = 'placed',
Approved = 'approved',
Delivered = 'delivered'
}

View File

@ -68,16 +68,6 @@ 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);
}
@ -115,4 +105,14 @@ export function PetToJSON(value?: Pet | null): any {
};
}
/**
* @export
* @enum {string}
*/
export enum PetStatusEnum {
Available = 'available',
Pending = 'pending',
Sold = 'sold'
}

View File

@ -45,24 +45,6 @@ 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);
}
@ -96,4 +78,23 @@ 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
}

View File

@ -45,24 +45,6 @@ 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);
}
@ -96,4 +78,23 @@ 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
}