better NPE handling for undefined request body (#1896)

This commit is contained in:
William Cheng
2019-01-13 12:25:35 +08:00
committed by GitHub
parent 4235390175
commit 470fc2065d

View File

@@ -4580,6 +4580,10 @@ public class DefaultCodegen implements CodegenConfig {
String name = null;
LOGGER.debug("Request body = " + body);
Schema schema = ModelUtils.getSchemaFromRequestBody(body);
if (schema == null) {
throw new RuntimeException("Request body cannot be null. Possible cause: missing schema in body parameter (OAS v2): " + body);
}
if (StringUtils.isNotBlank(schema.get$ref())) {
name = ModelUtils.getSimpleRef(schema.get$ref());
schema = schemas.get(name);