Repository: swagger-api/swagger-parser
Pull request #753 (2018-07-06 13:41:28)

Do not read Info block if it does not exist
Fixes issue described here: OpenAPITools/openapi-generator#177


Patch:
diff --git a/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java b/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java
index b4250e44..1b6d490b 100644
--- a/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java
+++ b/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java
@@ -141,7 +141,9 @@ public class SwaggerConverter implements SwaggerParserExtension {
             openAPI.setExternalDocs(convert(swagger.getExternalDocs()));
         }
 
-        openAPI.setInfo(convert(swagger.getInfo()));
+        if (swagger.getInfo() != null) {
+            openAPI.setInfo(convert(swagger.getInfo()));
+        }
 
         openAPI.setServers(convert(swagger.getSchemes(), swagger.getHost(), swagger.getBasePath()));
 


Test patch:
diff --git a/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java b/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java
index 4d565290..4e2c9534 100644
--- a/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java
+++ b/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java
@@ -77,6 +77,7 @@ public class V2ConverterTest {
     private static final String ISSUE_673_YAML = "issue-673.yaml";
     private static final String ISSUE_676_JSON = "issue-676.json";
     private static final String ISSUE_708_YAML = "issue-708.yaml";
+    private static final String ISSUE_755_YAML = "issue-755.yaml";
 
     private static final String API_BATCH_PATH = "/api/batch/";
     private static final String PETS_PATH = "/pets";
@@ -650,6 +651,12 @@ public class V2ConverterTest {
         assertNotNull(result.getMessages());
     }
 
+    @Test(description = "OpenAPI v2 converter - Conversion of a spec without a info section")
+    public void testIssue755() throws Exception {
+        final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_755_YAML);
+        assertNotNull(oas);
+    }
+
     private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException, URISyntaxException {
         SwaggerConverter converter = new SwaggerConverter();
         String swaggerAsString = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource(file).toURI())));
diff --git a/modules/swagger-parser-v2-converter/src/test/resources/issue-755.yaml b/modules/swagger-parser-v2-converter/src/test/resources/issue-755.yaml
new file mode 100644
index 00000000..083ba6ee
--- /dev/null
+++ b/modules/swagger-parser-v2-converter/src/test/resources/issue-755.yaml
@@ -0,0 +1,14 @@
+swagger: '2.0'
+host: petstore.swagger.io
+basePath: /v2
+schemes:
+  - http
+paths:
+  /ping:
+    post:
+      summary: test
+      description: 'test it'
+      operationId: pingOp
+      responses:
+        '200':
+          description: OK
\ No newline at end of file