Skip to content

Commit

Permalink
Adds $ref data to schema classes (#13163)
Browse files Browse the repository at this point in the history
* Adds getRef/setRef

* Adds ref to CodegenModel

* Adds ref to CodegenProperty

* Adds ref to CodegenParameter

* Adds ref to CodegenResponse

* Sets ref on CodegenModel and CodegenProperty

* Samples regenerated
  • Loading branch information
spacether authored Aug 11, 2022
1 parent 7fede83 commit 8cd0d38
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
private boolean isAnyType;
private boolean isUuid;
private Map<String, CodegenProperty> requiredVarsMap;
private String ref;

public String getAdditionalPropertiesType() {
return additionalPropertiesType;
Expand All @@ -174,6 +175,16 @@ public void setAdditionalPropertiesType(String additionalPropertiesType) {
this.additionalPropertiesType = additionalPropertiesType;
}

@Override
public String getRef() {
return ref;
}

@Override
public void setRef(String ref) {
this.ref = ref;
}

public Set<String> getAllMandatory() {
return allMandatory;
}
Expand Down Expand Up @@ -929,6 +940,7 @@ public boolean equals(Object o) {
getUniqueItems() == that.getUniqueItems() &&
getExclusiveMinimum() == that.getExclusiveMinimum() &&
getExclusiveMaximum() == that.getExclusiveMaximum() &&
Objects.equals(ref, that.getRef()) &&
Objects.equals(requiredVarsMap, that.getRequiredVarsMap()) &&
Objects.equals(composedSchemas, that.composedSchemas) &&
Objects.equals(parent, that.parent) &&
Expand Down Expand Up @@ -1002,7 +1014,7 @@ hasChildren, isMap, isDeprecated, hasOnlyReadOnly, getExternalDocumentation(), g
getMinItems(), getMaxLength(), getMinLength(), getExclusiveMinimum(), getExclusiveMaximum(), getMinimum(),
getMaximum(), getPattern(), getMultipleOf(), getItems(), getAdditionalProperties(), getIsModel(),
getAdditionalPropertiesIsAnyType(), hasDiscriminatorWithNonEmptyMapping,
isAnyType, getComposedSchemas(), hasMultipleTypes, isDecimal, isUuid, requiredVarsMap);
isAnyType, getComposedSchemas(), hasMultipleTypes, isDecimal, isUuid, requiredVarsMap, ref);
}

@Override
Expand Down Expand Up @@ -1100,6 +1112,7 @@ public String toString() {
sb.append(", isDecimal=").append(isDecimal);
sb.append(", isUUID=").append(isUuid);
sb.append(", requiredVarsMap=").append(requiredVarsMap);
sb.append(", ref=").append(ref);
sb.append('}');
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
private boolean hasMultipleTypes = false;
private LinkedHashMap<String, CodegenMediaType> content;
private Map<String, CodegenProperty> requiredVarsMap;
private String ref;

public CodegenParameter copy() {
CodegenParameter output = new CodegenParameter();
Expand Down Expand Up @@ -198,6 +199,9 @@ public CodegenParameter copy() {
if (this.requiredVarsMap != null) {
output.setRequiredVarsMap(this.requiredVarsMap);
}
if (this.ref != null) {
output.setRef(this.ref);
}
output.hasValidation = this.hasValidation;
output.isNullable = this.isNullable;
output.isDeprecated = this.isDeprecated;
Expand Down Expand Up @@ -234,7 +238,7 @@ public CodegenParameter copy() {

@Override
public int hashCode() {
return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, isContainer, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName, style, isDeepObject, isAllowEmptyValue, example, jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isFreeFormObject, isAnyType, isArray, isMap, isFile, isEnum, _enum, allowableValues, items, mostInnerItems, additionalProperties, vars, requiredVars, vendorExtensions, hasValidation, getMaxProperties(), getMinProperties(), isNullable, isDeprecated, required, getMaximum(), getExclusiveMaximum(), getMinimum(), getExclusiveMinimum(), getMaxLength(), getMinLength(), getPattern(), getMaxItems(), getMinItems(), getUniqueItems(), contentType, multipleOf, isNull, additionalPropertiesIsAnyType, hasVars, hasRequired, isShort, isUnboundedInteger, hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, schema, content, requiredVarsMap);
return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, isContainer, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName, style, isDeepObject, isAllowEmptyValue, example, jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isFreeFormObject, isAnyType, isArray, isMap, isFile, isEnum, _enum, allowableValues, items, mostInnerItems, additionalProperties, vars, requiredVars, vendorExtensions, hasValidation, getMaxProperties(), getMinProperties(), isNullable, isDeprecated, required, getMaximum(), getExclusiveMaximum(), getMinimum(), getExclusiveMinimum(), getMaxLength(), getMinLength(), getPattern(), getMaxItems(), getMinItems(), getUniqueItems(), contentType, multipleOf, isNull, additionalPropertiesIsAnyType, hasVars, hasRequired, isShort, isUnboundedInteger, hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, schema, content, requiredVarsMap, ref);
}

@Override
Expand Down Expand Up @@ -290,6 +294,7 @@ public boolean equals(Object o) {
getExclusiveMaximum() == that.getExclusiveMaximum() &&
getExclusiveMinimum() == that.getExclusiveMinimum() &&
getUniqueItems() == that.getUniqueItems() &&
Objects.equals(ref, that.getRef()) &&
Objects.equals(requiredVarsMap, that.getRequiredVarsMap()) &&
Objects.equals(content, that.getContent()) &&
Objects.equals(schema, that.getSchema()) &&
Expand Down Expand Up @@ -421,6 +426,7 @@ public String toString() {
sb.append(", schema=").append(schema);
sb.append(", content=").append(content);
sb.append(", requiredVarsMap=").append(requiredVarsMap);
sb.append(", ref=").append(ref);
sb.append('}');
return sb.toString();
}
Expand Down Expand Up @@ -827,5 +833,11 @@ public String getBaseType() {

@Override
public void setRequiredVarsMap(Map<String, CodegenProperty> requiredVarsMap) { this.requiredVarsMap=requiredVarsMap; }

@Override
public String getRef() { return ref; }

@Override
public void setRef(String ref) { this.ref=ref; }
}

Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
private CodegenComposedSchemas composedSchemas = null;
private boolean hasMultipleTypes = false;
private Map<String, CodegenProperty> requiredVarsMap;
private String ref;

public String getBaseName() {
return baseName;
Expand Down Expand Up @@ -660,6 +661,16 @@ public CodegenComposedSchemas getComposedSchemas() {
return composedSchemas;
}

@Override
public void setRef(String ref) {
this.ref = ref;
}

@Override
public String getRef() {
return ref;
}

@Override
public CodegenProperty clone() {
try {
Expand Down Expand Up @@ -694,6 +705,9 @@ public CodegenProperty clone() {
if (this.requiredVarsMap != null) {
cp.setRequiredVarsMap(this.requiredVarsMap);
}
if (this.ref != null) {
cp.setRef(this.ref);
}

return cp;
} catch (CloneNotSupportedException e) {
Expand Down Expand Up @@ -977,6 +991,7 @@ public String toString() {
sb.append(", composedSchemas=").append(composedSchemas);
sb.append(", hasMultipleTypes=").append(hasMultipleTypes);
sb.append(", requiredVarsMap=").append(requiredVarsMap);
sb.append(", ref=").append(ref);
sb.append('}');
return sb.toString();
}
Expand Down Expand Up @@ -1035,6 +1050,7 @@ public boolean equals(Object o) {
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
getHasVars() == that.getHasVars() &&
getHasRequired() == that.getHasRequired() &&
Objects.equals(ref, that.getRef()) &&
Objects.equals(requiredVarsMap, that.getRequiredVarsMap()) &&
Objects.equals(composedSchemas, that.composedSchemas) &&
Objects.equals(openApiType, that.openApiType) &&
Expand Down Expand Up @@ -1099,6 +1115,7 @@ public int hashCode() {
vendorExtensions, hasValidation, isInherited, discriminatorValue, nameInCamelCase,
nameInSnakeCase, enumName, maxItems, minItems, isXmlAttribute, xmlPrefix, xmlName,
xmlNamespace, isXmlWrapped, isNull, additionalPropertiesIsAnyType, hasVars, hasRequired,
hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, requiredVarsMap);
hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, requiredVarsMap,
ref);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
private boolean hasMultipleTypes = false;
private LinkedHashMap<String, CodegenMediaType> content;
private Map<String, CodegenProperty> requiredVarsMap;
private String ref;

@Override
public int hashCode() {
Expand All @@ -102,7 +103,7 @@ public int hashCode() {
getMinLength(), exclusiveMinimum, exclusiveMaximum, getMinimum(), getMaximum(), getPattern(),
is1xx, is2xx, is3xx, is4xx, is5xx, additionalPropertiesIsAnyType, hasVars, hasRequired,
hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, responseHeaders, content,
requiredVarsMap);
requiredVarsMap, ref);
}

@Override
Expand Down Expand Up @@ -151,6 +152,7 @@ public boolean equals(Object o) {
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
getHasVars() == that.getHasVars() &&
getHasRequired() == that.getHasRequired() &&
Objects.equals(ref, that.getRef()) &&
Objects.equals(requiredVarsMap, that.getRequiredVarsMap()) &&
Objects.equals(content, that.getContent()) &&
Objects.equals(responseHeaders, that.getResponseHeaders()) &&
Expand Down Expand Up @@ -542,6 +544,7 @@ public String toString() {
sb.append(", responseHeaders=").append(responseHeaders);
sb.append(", content=").append(content);
sb.append(", requiredVarsMap=").append(requiredVarsMap);
sb.append(", ref=").append(ref);
sb.append('}');
return sb.toString();
}
Expand Down Expand Up @@ -675,4 +678,10 @@ public String getBaseType() {

@Override
public void setRequiredVarsMap(Map<String, CodegenProperty> requiredVarsMap) { this.requiredVarsMap=requiredVarsMap; }

@Override
public String getRef() { return ref; }

@Override
public void setRef(String ref) { this.ref=ref; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2892,6 +2892,9 @@ public CodegenModel fromModel(String name, Schema schema) {
// schema by unaliasSchema and one of the above code paths will be taken
;
}
if (schema.get$ref() != null) {
m.setRef(schema.get$ref());
}

if (schema instanceof ComposedSchema) {
updateModelForComposedSchema(m, schema, allDefinitions);
Expand Down Expand Up @@ -3763,6 +3766,9 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required) {
// referenced model
;
}
if (p.get$ref() != null) {
property.setRef(p.get$ref());
}

boolean isAnyTypeWithNothingElseSet = (ModelUtils.isAnyType(p) &&
(p.getProperties() == null || p.getProperties().isEmpty()) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public interface IJsonSchemaValidationProperties {

void setIsAnyType(boolean isAnyType);

String getRef();

void setRef(String ref);

CodegenComposedSchemas getComposedSchemas();

void setComposedSchemas(CodegenComposedSchemas composedSchemas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,10 @@ public static boolean isNullType(Schema schema) {
* @return boolean
*/
public static boolean isAnyType(Schema schema) {
// $ref is not a type, it is a keyword
// TODO remove the ref check here, or pass in the spec version
// openapi 3.1.0 specs allow ref to be adjacent to any keyword
// openapi 3.0.3 and earlier do not allow adjacent keywords to refs
return (schema.get$ref() == null && schema.getType() == null);
}

Expand Down
Loading

0 comments on commit 8cd0d38

Please sign in to comment.