Skip to content

Commit

Permalink
Sets model.additionalProperties for composed schemas (#9033)
Browse files Browse the repository at this point in the history
* Turns on setting model.additionalProperties for composed schemas when supportsAdditionalPropertiesWithComposedSchema is true, tests updated for v2 and v3 specs

* Comment change

* Samples updated

* Turns on supportsAdditionalPropertiesWithComposedSchema for CsharpNetCoreClient, samples regenerated

* Changes commented out, samples regnerated

* Refactors the update in setAddProps to not impact the charp client
  • Loading branch information
spacether authored Mar 22, 2021
1 parent e0021e6 commit 113d38e
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2615,35 +2615,47 @@ public int compare(CodegenProperty one, CodegenProperty another) {
}

private void setAddProps(Schema schema, IJsonSchemaValidationProperties property){
if (schema.equals(new Schema())) {
// if we are trying to set additionalProperties on an empty schema stop recursing
return;
}
boolean additionalPropertiesIsAnyType = false;
CodegenModel m = null;
if (property instanceof CodegenModel) {
m = (CodegenModel) property;
}
CodegenProperty addPropProp = null;
boolean isAdditionalPropertiesTrue = false;
if (schema.getAdditionalProperties() == null) {
if (!disallowAdditionalPropertiesIfNotPresent) {
isAdditionalPropertiesTrue = true;
CodegenProperty cp = fromProperty("", new Schema());
property.setAdditionalProperties(cp);
property.setAdditionalPropertiesIsAnyType(true);
addPropProp = fromProperty("", new Schema());
additionalPropertiesIsAnyType = true;
}
} else if (schema.getAdditionalProperties() instanceof Boolean) {
if (Boolean.TRUE.equals(schema.getAdditionalProperties())) {
isAdditionalPropertiesTrue = true;
CodegenProperty cp = fromProperty("", new Schema());
property.setAdditionalProperties(cp);
property.setAdditionalPropertiesIsAnyType(true);
addPropProp = fromProperty("", new Schema());
additionalPropertiesIsAnyType = true;
}
} else {
CodegenProperty cp = fromProperty("", (Schema) schema.getAdditionalProperties());
property.setAdditionalProperties(cp);
addPropProp = fromProperty("", (Schema) schema.getAdditionalProperties());
if (isAnyTypeSchema((Schema) schema.getAdditionalProperties())) {
property.setAdditionalPropertiesIsAnyType(true);
additionalPropertiesIsAnyType = true;
}
}
if (additionalPropertiesIsAnyType) {
property.setAdditionalPropertiesIsAnyType(true);
}
if (m != null && isAdditionalPropertiesTrue) {
m.isAdditionalPropertiesTrue = true;
}
if (ModelUtils.isComposedSchema(schema) && !supportsAdditionalPropertiesWithComposedSchema) {
return;
}
if (addPropProp != null) {
property.setAdditionalProperties(addPropProp);
}
}


Expand Down Expand Up @@ -6157,6 +6169,7 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
}

private void addVarsRequiredVarsAdditionalProps(Schema schema, IJsonSchemaValidationProperties property){
setAddProps(schema, property);
if (!"object".equals(schema.getType())) {
return;
}
Expand All @@ -6178,7 +6191,6 @@ private void addVarsRequiredVarsAdditionalProps(Schema schema, IJsonSchemaValida
property.setHasRequired(true);
}
}
setAddProps(schema, property);
}

private void addJsonSchemaForBodyRequestInCaseItsNotPresent(CodegenParameter codegenParameter, RequestBody body) {
Expand Down
Loading

0 comments on commit 113d38e

Please sign in to comment.