Skip to content

Commit 88c0804

Browse files
authored
Merge pull request #328 from swagger-api/issue-17159
allow request body with non schema
2 parents e00403e + e6f4b68 commit 88c0804

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,18 +2000,33 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
20002000
List<Schema> foundSchemas = new ArrayList<>();
20012001

20022002
for (String contentType : body.getContent().keySet()) {
2003+
boolean isForm = "application/x-www-form-urlencoded".equalsIgnoreCase(contentType) || "multipart/form-data".equalsIgnoreCase(contentType);
20032004

20042005
String schemaName = null;
20052006
Schema schema = body.getContent().get(contentType).getSchema();
2006-
if (StringUtils.isNotBlank(schema.get$ref())) {
2007+
if (schema != null && StringUtils.isNotBlank(schema.get$ref())) {
20072008
schemaName = OpenAPIUtil.getSimpleRef(schema.get$ref());
20082009
schema = schemas.get(schemaName);
20092010
}
2010-
2011-
if ("application/x-www-form-urlencoded".equalsIgnoreCase(contentType) || "multipart/form-data".equalsIgnoreCase(contentType)) {
2012-
final CodegenContent codegenContent = new CodegenContent(contentType);
2013-
codegenContent.getContentExtensions().put(CodegenConstants.IS_FORM_EXT_NAME, Boolean.TRUE);
2014-
2011+
final CodegenContent codegenContent = new CodegenContent(contentType);
2012+
codegenContent.getContentExtensions().put(CodegenConstants.IS_FORM_EXT_NAME, isForm);
2013+
2014+
if (schema == null) {
2015+
CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
2016+
codegenParameter.description = body.getDescription();
2017+
codegenParameter.unescapedDescription = body.getDescription();
2018+
codegenParameter.baseName = REQUEST_BODY_NAME;
2019+
codegenParameter.paramName = REQUEST_BODY_NAME;
2020+
codegenParameter.dataType = "Object";
2021+
codegenParameter.baseType = "Object";
2022+
2023+
codegenParameter.required = body.getRequired() != null ? body.getRequired() : Boolean.FALSE;
2024+
if (!isForm) {
2025+
codegenParameter.getVendorExtensions().put(CodegenConstants.IS_BODY_PARAM_EXT_NAME, Boolean.TRUE);
2026+
}
2027+
continue;
2028+
}
2029+
if (isForm) {
20152030
final Map<String, Schema> propertyMap = schema.getProperties();
20162031
boolean isMultipart = contentType.equalsIgnoreCase("multipart/form-data");
20172032
if (propertyMap != null && !propertyMap.isEmpty()) {
@@ -2049,7 +2064,6 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
20492064
}
20502065
}
20512066
foundSchemas.add(schema);
2052-
final CodegenContent codegenContent = new CodegenContent(contentType);
20532067
codegenContent.getParameters().add(bodyParam.copy());
20542068
codegenContents.add(codegenContent);
20552069
}

0 commit comments

Comments
 (0)