Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ public String getSchemaType(Schema schema) {
// TODO better logic to handle compose schema
if (schema instanceof ComposedSchema) { // composed schema
ComposedSchema cs = (ComposedSchema) schema;
if(cs.getAllOf() != null) {
if (cs.getAllOf() != null) {
for (Schema s : cs.getAllOf()) {
if (s != null) {
// using the first schema defined in allOf
Expand Down Expand Up @@ -1383,6 +1383,9 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al
typeAliases = getAllAliases(allDefinitions);
}

// unalias schema
schema = ModelUtils.unaliasSchema(allDefinitions, schema);

CodegenModel m = CodegenModelFactory.newInstance(CodegenModelType.MODEL);

if (reservedWords.contains(name)) {
Expand Down Expand Up @@ -1508,9 +1511,8 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al
addProperties(allProperties, allRequired, child, allDefinitions);
}
}
addVars(m, properties, required, allProperties, allRequired);
// TODO
//} else if (schema instanceof RefModel) {
addVars(m, unaliasPropertySchema(allDefinitions, properties), required, allProperties, allRequired);

} else {
m.dataType = getSchemaType(schema);
if (schema.getEnum() != null && !schema.getEnum().isEmpty()) {
Expand All @@ -1522,7 +1524,7 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al
if (ModelUtils.isMapSchema(schema)) {
addAdditionPropertiesToCodeGenModel(m, schema);
}
addVars(m, schema.getProperties(), schema.getRequired());
addVars(m, unaliasPropertySchema(allDefinitions, schema.getProperties()), schema.getRequired());
}

if (m.vars != null) {
Expand Down Expand Up @@ -1591,7 +1593,6 @@ public CodegenProperty fromProperty(String name, Schema p) {
return null;
}
LOGGER.debug("debugging fromProperty for " + name + " : " + p);

CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
property.name = toVarName(name);
property.baseName = name;
Expand Down Expand Up @@ -1832,7 +1833,6 @@ public CodegenProperty fromProperty(String name, Schema p) {
// property.baseType = getSimpleRef(p.get$ref());
//}
// --END of revision

setNonArrayMapProperty(property, type);
}

Expand Down Expand Up @@ -3047,6 +3047,24 @@ protected void addImport(CodegenModel m, String type) {
}
}

/**
* Loop through propertiies and unalias the reference if $ref (reference) is defined
*
* @param allSchemas all schemas defined in the spec
* @param properties model properties (schemas)
* @return model properties with direct reference to schemas
*/
private Map<String, Schema> unaliasPropertySchema(Map<String, Schema> allSchemas, Map<String, Schema> properties) {
if (properties != null) {
for (String key : properties.keySet()) {
properties.put(key, ModelUtils.unaliasSchema(allSchemas, properties.get(key)));

}
}

return properties;
}

private void addVars(CodegenModel model, Map<String, Schema> properties, List<String> required) {
addVars(model, properties, required, null, null);
}
Expand Down Expand Up @@ -3160,9 +3178,11 @@ private static Map<String, String> getAllAliases(Map<String, Schema> schemas) {
String oasName = entry.getKey();
Schema schema = entry.getValue();
String schemaType = getPrimitiveType(schema);
if (schemaType != null && !schemaType.equals("object") && !schemaType.equals("array") && schema.getEnum() == null) {
if (schemaType != null && !schemaType.equals("object") && !schemaType.equals("array")
&& schema.getEnum() == null && !ModelUtils.isMapSchema(schema)) {
aliases.put(oasName, schemaType);
}

}

return aliases;
Expand Down Expand Up @@ -3896,14 +3916,14 @@ private void addProducesInfo(OpenAPI openAPI, ApiResponse inputResponse, Codegen
}

Set<String> existingMediaTypes = new HashSet<>();
for (Map<String, String> mediaType: codegenOperation.produces) {
for (Map<String, String> mediaType : codegenOperation.produces) {
existingMediaTypes.add(mediaType.get("mediaType"));
}

int count = 0;
for (String key : produces) {
// escape quotation to avoid code injection, "*/*" is a special case, do nothing
String encodedKey = "*/*".equals(key)? key : escapeText(escapeQuotationMark(key));
String encodedKey = "*/*".equals(key) ? key : escapeText(escapeQuotationMark(key));
//Only unique media types should be added to "produces"
if (!existingMediaTypes.contains(encodedKey)) {
Map<String, String> mediaType = new HashMap<String, String>();
Expand All @@ -3925,7 +3945,7 @@ private void addProducesInfo(OpenAPI openAPI, ApiResponse inputResponse, Codegen
/**
* returns the list of MIME types the APIs can produce
*
* @param openAPI current specification instance
* @param openAPI current specification instance
* @param operation Operation
* @return a set of MIME types
*/
Expand Down Expand Up @@ -4024,10 +4044,9 @@ public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body,
codegenParameter.isListContainer = true;
codegenParameter.description = s.getDescription();
codegenParameter.dataType = getTypeDeclaration(s);
if (codegenParameter.baseType != null && codegenParameter.enumName != null){
if (codegenParameter.baseType != null && codegenParameter.enumName != null) {
codegenParameter.datatypeWithEnum = codegenParameter.dataType.replace(codegenParameter.baseType, codegenParameter.enumName);
}
else {
} else {
LOGGER.warn("Could not compute datatypeWithEnum from " + codegenParameter.baseType + ", " + codegenParameter.enumName);
}
//TODO fix collectformat for form parameters
Expand Down Expand Up @@ -4338,7 +4357,7 @@ public void generateJSONSpecFile(Map<String, Object> objs) {
public void generateYAMLSpecFile(Map<String, Object> objs) {
OpenAPI openAPI = (OpenAPI) objs.get("openAPI");
String yaml = SerializerUtils.toYamlString(openAPI);
if(yaml != null) {
if (yaml != null) {
objs.put("openapi-yaml", yaml);
}
}
Expand Down
Loading