diff --git a/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java b/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java index 697c30c6c8..b2ff6c329e 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java +++ b/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java @@ -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); } diff --git a/src/main/java/io/swagger/codegen/v3/generators/SchemaHandler.java b/src/main/java/io/swagger/codegen/v3/generators/SchemaHandler.java index 8c91a4384d..e9cf7638be 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/SchemaHandler.java +++ b/src/main/java/io/swagger/codegen/v3/generators/SchemaHandler.java @@ -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"; @@ -99,7 +100,13 @@ protected CodegenModel processComposedSchema(String name, ComposedSchema compose } protected CodegenModel processComposedSchema(String codegenModelName, CodegenProperty codegenProperty, ComposedSchema composedSchema, Map allModels) { - List schemas = composedSchema.getOneOf(); + List 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(); @@ -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; } @@ -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(); + } } diff --git a/src/main/java/io/swagger/codegen/v3/generators/nodejs/NodeJSServerCodegen.java b/src/main/java/io/swagger/codegen/v3/generators/nodejs/NodeJSServerCodegen.java index bac8729c75..82c7b3b6d6 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/nodejs/NodeJSServerCodegen.java +++ b/src/main/java/io/swagger/codegen/v3/generators/nodejs/NodeJSServerCodegen.java @@ -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"; diff --git a/src/main/java/io/swagger/codegen/v3/generators/python/PythonFlaskConnexionCodegen.java b/src/main/java/io/swagger/codegen/v3/generators/python/PythonFlaskConnexionCodegen.java index 3340fa74ce..2c91368e39 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/python/PythonFlaskConnexionCodegen.java +++ b/src/main/java/io/swagger/codegen/v3/generators/python/PythonFlaskConnexionCodegen.java @@ -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 securitySchemes = openAPI.getComponents() != null ? openAPI.getComponents().getSecuritySchemes() : null;