Skip to content

Commit

Permalink
Merge pull request #628 from swagger-api/swos-185
Browse files Browse the repository at this point in the history
fixed type for allOf schema as properties
  • Loading branch information
HugoMario authored Mar 13, 2020
2 parents 79e13b9 + d9060a0 commit 5a12700
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,9 @@ public String toModelName(final String name) {
* @return Codegen Model object
*/
public CodegenModel fromModel(String name, Schema schema) {
if (openAPI != null && openAPI.getComponents() != null && openAPI.getComponents().getSchemas() != null) {
return fromModel(name, schema, openAPI.getComponents().getSchemas());
}
return fromModel(name, schema, null);
}

Expand Down
21 changes: 16 additions & 5 deletions src/main/java/io/swagger/codegen/v3/generators/SchemaHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

public class SchemaHandler implements ISchemaHandler {

public static final String ALL_OF_PREFFIX = "AllOf";
public static final String ONE_OF_PREFFIX = "OneOf";
public static final String ANY_OF_PREFFIX = "AnyOf";
public static final String ARRAY_ITEMS_SUFFIX = "Items";
Expand Down Expand Up @@ -99,7 +100,13 @@ protected CodegenModel processComposedSchema(String name, ComposedSchema compose
}

protected CodegenModel processComposedSchema(String codegenModelName, CodegenProperty codegenProperty, ComposedSchema composedSchema, Map<String, CodegenModel> allModels) {
List<Schema> schemas = composedSchema.getOneOf();
List<Schema> schemas = composedSchema.getAllOf();
if (schemas != null && !schemas.isEmpty()) {
final CodegenModel composedModel = codegenConfig.fromModel(ALL_OF_PREFFIX + codegenModelName, composedSchema);
this.updatePropertyDataType(codegenProperty, composedModel);
return composedModel;
}
schemas = composedSchema.getOneOf();
CodegenModel composedModel = this.createComposedModel(ONE_OF_PREFFIX + codegenModelName, schemas);
if (composedModel == null) {
schemas = composedSchema.getAnyOf();
Expand All @@ -109,10 +116,7 @@ protected CodegenModel processComposedSchema(String codegenModelName, CodegenPro
}
}
this.addInterfaces(schemas, composedModel, allModels);
codegenProperty.datatype = composedModel.getClassname();
codegenProperty.datatypeWithEnum = composedModel.getClassname();
codegenProperty.baseType = composedModel.getClassname();
codegenProperty.complexType = composedModel.getClassname();
this.updatePropertyDataType(codegenProperty, composedModel);
return composedModel;
}

Expand Down Expand Up @@ -221,4 +225,11 @@ protected void updateArrayModel(CodegenModel codegenModel, String schemaName, Ar

arraySchema.setItems(items);
}

private void updatePropertyDataType(CodegenProperty codegenProperty, CodegenModel composedModel) {
codegenProperty.datatype = composedModel.getClassname();
codegenProperty.datatypeWithEnum = composedModel.getClassname();
codegenProperty.baseType = composedModel.getClassname();
codegenProperty.complexType = composedModel.getClassname();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ public void processOpts() {

@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
this.openAPI = openAPI;
URL url = URLPathUtil.getServerURL(openAPI);
String host = URLPathUtil.LOCAL_HOST;
String port = "8080";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ public String getSchemaType(Schema p) {

@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
super.preprocessOpenAPI(openAPI);
final Paths paths = openAPI.getPaths();
addRouterControllerExtensions(paths);
final Map<String, SecurityScheme> securitySchemes = openAPI.getComponents() != null ? openAPI.getComponents().getSecuritySchemes() : null;
Expand Down

0 comments on commit 5a12700

Please sign in to comment.