better NPE handling, log warn for const in 3.1 (#16786)

This commit is contained in:
William Cheng
2023-10-11 15:58:29 +08:00
committed by GitHub
parent 015f000f70
commit fe55938363
2 changed files with 7 additions and 2 deletions

View File

@@ -7665,7 +7665,8 @@ public class DefaultCodegen implements CodegenConfig {
}
}
if (found == false) {
throw new RuntimeException("Property " + requiredPropertyName + " is missing from getVars");
LOGGER.warn("Property {} is not processed correctly (missing from getVars). Maybe it's a const (not yet supported) in openapi v3.1 spec.", requiredPropertyName);
continue;
}
} else if (schema.getAdditionalProperties() instanceof Boolean && Boolean.FALSE.equals(schema.getAdditionalProperties())) {
// TODO add processing for requiredPropertyName

View File

@@ -198,7 +198,7 @@ public class ModelUtils {
List<String> schemasUsedInOtherCases = new ArrayList<String>();
visitOpenAPI(openAPI, (s, t) -> {
if (s.get$ref() != null) {
if (s != null && s.get$ref() != null) {
String ref = getSimpleRef(s.get$ref());
if ("application/x-www-form-urlencoded".equalsIgnoreCase(t) ||
"multipart/form-data".equalsIgnoreCase(t)) {
@@ -320,6 +320,10 @@ public class ModelUtils {
* @param visitor the visitor function which is invoked for every visited schema.
*/
private static void visitSchema(OpenAPI openAPI, Schema schema, String mimeType, List<String> visitedSchemas, OpenAPISchemaVisitor visitor) {
if (schema == null) {
return;
}
visitor.visit(schema, mimeType);
if (schema.get$ref() != null) {
String ref = getSimpleRef(schema.get$ref());