Skip to content

Commit 1a5a484

Browse files
committed
catch NPE cases in preprocessOpenAPI updated samples
1 parent 49f13eb commit 1a5a484

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ public void postProcessParameter(CodegenParameter parameter) {
710710
//override with any special handling of the entire OpenAPI spec document
711711
@SuppressWarnings("unused")
712712
public void preprocessOpenAPI(OpenAPI openAPI) {
713-
if (useOneOfInterfaces) {
713+
if (useOneOfInterfaces && openAPI.getComponents() != null) {
714714
// we process the openapi schema here to find oneOf schemas and create interface models for them
715715
Map<String, Schema> schemas = new HashMap<String, Schema>(openAPI.getComponents().getSchemas());
716716
if (schemas == null) {
@@ -733,11 +733,13 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
733733
schemas.put(opId, requestSchema);
734734
}
735735
// process all response bodies
736-
for (Map.Entry<String, ApiResponse> ar : op.getValue().getResponses().entrySet()) {
737-
ApiResponse a = ModelUtils.getReferencedApiResponse(openAPI, ar.getValue());
738-
Schema responseSchema = ModelUtils.getSchemaFromResponse(a);
739-
if (responseSchema != null) {
740-
schemas.put(opId + ar.getKey(), responseSchema);
736+
if (op.getValue().getResponses() != null){
737+
for (Map.Entry<String, ApiResponse> ar : op.getValue().getResponses().entrySet()) {
738+
ApiResponse a = ModelUtils.getReferencedApiResponse(openAPI, ar.getValue());
739+
Schema responseSchema = ModelUtils.getSchemaFromResponse(a);
740+
if (responseSchema != null) {
741+
schemas.put(opId + ar.getKey(), responseSchema);
742+
}
741743
}
742744
}
743745
}

0 commit comments

Comments
 (0)