From f3f2fed068e4add851728f40e9da1b61bfbc68ba Mon Sep 17 00:00:00 2001 From: djayakumar122 <122564174+djayakumar122@users.noreply.github.com> Date: Thu, 11 Jan 2024 17:01:57 -0800 Subject: [PATCH] Update OpenApiToJsonSchema.java Fixing NPE --- .../jsonschema/OpenApiToJsonSchema.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/NST/src/main/java/com/ebay/openapi/export/jsonschema/OpenApiToJsonSchema.java b/NST/src/main/java/com/ebay/openapi/export/jsonschema/OpenApiToJsonSchema.java index abff52d..4d46c5c 100644 --- a/NST/src/main/java/com/ebay/openapi/export/jsonschema/OpenApiToJsonSchema.java +++ b/NST/src/main/java/com/ebay/openapi/export/jsonschema/OpenApiToJsonSchema.java @@ -179,15 +179,19 @@ public void convert() { if (response == null) { throw new IllegalStateException(String.format("Status code [%s] is not present for request method [%s] and path [%s] in file: %s", statusCode, requestMethod, requestPath, openApiSpecFilePath)); } - - MediaType mediaType = response.getContent().get(MEDIA_TYPE); - if (mediaType == null) { - throw new IllegalStateException( - "Media type [application/json] is not present for status code [200] and request method [" - + requestMethod + "] and path [" + requestPath + "] in file: " + openApiSpecFilePath); + + //added below check to fix NPE + if(response.getContent() != null) { + MediaType mediaType = response.getContent().get(MEDIA_TYPE); + if (mediaType == null) { + throw new IllegalStateException( + "Media type [application/json] is not present for status code [200] and request method [" + + requestMethod + "] and path [" + requestPath + "] in file: " + openApiSpecFilePath); + }else{ + schema = mediaType.getSchema(); + } } - - schema = mediaType.getSchema(); + if (schema == null) { throw new IllegalStateException( "Schema not found for media type [application/json] and status code [200] and request method ["