Repository: swagger-api/swagger-parser
Pull request #958 (2018-11-30 16:17:52)

Regression issue 943
Regression issue #943


Patch:
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java
index 95438b30..43d74962 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java
@@ -314,7 +314,7 @@ public class ResolverFully {
                     Schema innerProperty = obj.getProperties().get(propertyName);
                     // reference check
                     if(schema != innerProperty) {
-                        if(resolvedProperties.get(propertyName) == null && resolvedProperties.get(propertyName) != innerProperty) {
+                        if(resolvedProperties.get(propertyName) == null || resolvedProperties.get(propertyName) != innerProperty) {
                             LOGGER.debug("avoiding infinite loop");
                             Schema resolved = resolveSchema(innerProperty);
                             updated.put(propertyName, resolved);
@@ -354,7 +354,7 @@ public class ResolverFully {
                         if (resolved.getProperties() != null) {
                             for (String key : properties.keySet()) {
                                 Schema prop = (Schema) resolved.getProperties().get(key);
-                                if(resolvedProperties.get(key) == null && resolvedProperties.get(key) != prop) {
+                                if(resolvedProperties.get(key) == null || resolvedProperties.get(key) != prop) {
                                     LOGGER.debug("avoiding infinite loop");
                                     Schema resolvedProp = resolveSchema(prop);
                                     model.addProperties(key,resolvedProp );
@@ -402,7 +402,7 @@ public class ResolverFully {
                             if (resolved.getProperties() != null) {
                                 for (String key : properties.keySet()) {
                                     Schema prop = (Schema) resolved.getProperties().get(key);
-                                    if(resolvedProperties.get(key) == null && resolvedProperties.get(key) != prop) {
+                                    if(resolvedProperties.get(key) == null || resolvedProperties.get(key) != prop) {
                                         LOGGER.debug("avoiding infinite loop");
                                         Schema resolvedProp = resolveSchema(prop);
                                         model.addProperties(key,resolvedProp );
@@ -451,7 +451,7 @@ public class ResolverFully {
                             if (resolved.getProperties() != null) {
                                 for (String key : properties.keySet()) {
                                     Schema prop = (Schema) resolved.getProperties().get(key);
-                                    if(resolvedProperties.get(key) == null && resolvedProperties.get(key) != prop) {
+                                    if(resolvedProperties.get(key) == null || resolvedProperties.get(key) != prop) {
                                         LOGGER.debug("avoiding infinite loop");
                                         Schema resolvedProp = resolveSchema(prop);
                                         model.addProperties(key,resolvedProp );
@@ -507,7 +507,7 @@ public class ResolverFully {
             Map<String, Schema> properties = model.getProperties();
             for (String propertyName : properties.keySet()) {
                 Schema property = (Schema) model.getProperties().get(propertyName);
-                if(resolvedProperties.get(propertyName) == null && resolvedProperties.get(propertyName) != property) {
+                if(resolvedProperties.get(propertyName) == null || resolvedProperties.get(propertyName) != property) {
                     LOGGER.debug("avoiding infinite loop");
                     Schema resolved = resolveSchema(property);
                     updated.put(propertyName, resolved);


Test patch:
diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java
index e5558ed5..e9473152 100644
--- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java
+++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java
@@ -1166,6 +1166,16 @@ public class OpenAPIResolverTest {
         }
     }
 
+    @Test
+    public void propertyNameMixup() {
+        ParseOptions parseOptions = new ParseOptions();
+        parseOptions.setResolveFully(true);
+        OpenAPI openAPI = new OpenAPIV3Parser().read("simple.yaml", null, parseOptions);
+        assertEquals(((StringSchema)openAPI.getComponents().getSchemas().get("Manufacturer").getProperties().get("name")).getExample(), "ACME Corporation");
+        Schema schema = openAPI.getPaths().get("/inventory").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
+        assertEquals(((ObjectSchema) ((ArraySchema) schema).getItems().getProperties().get("manufacturer")).getProperties().get("name").getExample(), "ACME Corporation");
+    }
+
     public String replacePort(String url){
         String pathFile = url.replace("${dynamicPort}", String.valueOf(this.serverPort));
         return pathFile;
diff --git a/modules/swagger-parser-v3/src/test/resources/simple.yaml b/modules/swagger-parser-v3/src/test/resources/simple.yaml
new file mode 100644
index 00000000..d3940253
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/simple.yaml
@@ -0,0 +1,115 @@
+openapi: 3.0.0
+info:
+  description: This is a simple API
+  version: "1.0.0"
+  title: Simple Inventory API
+  contact:
+    email: you@your-company.com
+  license:
+    name: Apache 2.0
+    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
+tags:
+- name: admins
+  description: Secured Admin-only calls
+- name: developers
+  description: Operations available to regular developers
+paths:
+  /inventory:
+    get:
+      tags:
+      - developers
+      summary: searches inventory
+      operationId: searchInventory
+      description: |
+        By passing in the appropriate options, you can search for
+        available inventory in the system
+      parameters:
+      - in: query
+        name: searchString
+        description: pass an optional search string for looking up inventory
+        required: false
+        schema:
+          type: string
+      - in: query
+        name: skip
+        description: number of records to skip for pagination
+        schema:
+          type: integer
+          format: int32
+          minimum: 0
+      - in: query
+        name: limit
+        description: maximum number of records to return
+        schema:
+          type: integer
+          format: int32
+          minimum: 0
+          maximum: 50
+      responses:
+        '200':
+          description: search results matching criteria
+          content:
+            application/json:
+              schema:
+                type: array
+                items:
+                  $ref: '#/components/schemas/InventoryItem'
+        '400':
+          description: bad input parameter
+    post:
+      tags:
+      - admins
+      summary: adds an inventory item
+      operationId: addInventory
+      description: Adds an item to the system
+      responses:
+        '201':
+          description: item created
+        '400':
+          description: 'invalid input, object invalid'
+        '409':
+          description: an existing item already exists
+      requestBody:
+        content:
+          application/json:
+            schema:
+              $ref: '#/components/schemas/InventoryItem'
+        description: Inventory item to add
+components:
+  schemas:
+    InventoryItem:
+      type: object
+      required:
+      - id
+      - name
+      - manufacturer
+      - releaseDate
+      properties:
+        id:
+          type: string
+          format: uuid
+          example: d290f1ee-6c54-4b01-90e6-d701748f0851
+        name:
+          type: string
+          example: Widget Adapter
+        releaseDate:
+          type: string
+          format: date-time
+          example: '2016-08-29T09:12:33.001Z'
+        manufacturer:
+          $ref: '#/components/schemas/Manufacturer'
+    Manufacturer:
+      required:
+      - name
+      properties:
+        name:
+          type: string
+          example: ACME Corporation
+        homePage:
+          type: string
+          format: url
+          example: 'https://www.acme-corp.com'
+        phone:
+          type: string
+          example: 408-867-5309
+      type: object
\ No newline at end of file