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 d8100add96..80cee1313e 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java +++ b/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java @@ -2414,8 +2414,11 @@ public CodegenParameter fromParameter(Parameter parameter, Set imports) codegenParameter.vendorExtensions.putAll(parameter.getExtensions()); } - if (parameter.getSchema() != null) { - Schema parameterSchema = parameter.getSchema(); + Schema parameterSchema = parameter.getSchema(); + if (parameterSchema == null) { + parameterSchema = getSchemaFromParameter(parameter); + } + if (parameterSchema != null) { String collectionFormat = null; if (parameterSchema instanceof ArraySchema) { // for array parameter final ArraySchema arraySchema = (ArraySchema) parameterSchema; @@ -3983,6 +3986,21 @@ protected Schema getSchemaFromResponse(ApiResponse response) { return schema; } + protected Schema getSchemaFromParameter(Parameter parameter) { + if (parameter.getContent() == null || parameter.getContent().isEmpty()) { + return null; + } + Schema schema = null; + for (String contentType : parameter.getContent().keySet()) { + schema = parameter.getContent().get(contentType).getSchema(); + if (schema != null) { + schema.addExtension("x-content-type", contentType); + } + break; + } + return schema; + } + protected Parameter getParameterFromRef(String ref, OpenAPI openAPI) { String parameterName = ref.substring(ref.lastIndexOf('/') + 1); Map parameterMap = openAPI.getComponents().getParameters();