Repository: swagger-api/swagger-parser
Pull request #1837 (2022-10-17 20:45:16)

refs #1266 - handle overridden extensions


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 5c0c4cf6..0b592af4 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
@@ -56,7 +56,7 @@ public class ResolverFully {
     private Map<String, Link> links;
     private Map<String, Schema> resolvedProperties = new IdentityHashMap<>();
     private Map<String, Callback> callbacks;
-    
+
     public void resolveFully(OpenAPI openAPI) {
         Components components = openAPI.getComponents();
         if (components != null && components.getRequestBodies() != null) {
@@ -85,7 +85,7 @@ public class ResolverFully {
             if (headers == null) {
                 headers = new HashMap<>();
             }
-        }  
+        }
 
         if (components != null && components.getParameters() != null) {
             parameters = components.getParameters();
@@ -243,7 +243,7 @@ public class ResolverFully {
         }
         return header;
     }
-  
+
     public Link resolveLink(Link link){
         RefFormat refFormat = computeRefFormat(link.get$ref());
         String $ref = link.get$ref();
@@ -272,7 +272,7 @@ public class ResolverFully {
         }
         return requestBody;
     }
-    
+
     public Callback resolveCallback(Callback callback){
         RefFormat refFormat = computeRefFormat(callback.get$ref());
         String $ref = callback.get$ref();
@@ -502,6 +502,12 @@ public class ResolverFully {
                     targetSchema.addExtension(key, extensions.get(key));
                 }
             }
+            if (sourceSchema.getExtensions() != null) {
+                Map<String, Object> extensions = sourceSchema.getExtensions();
+                for (String key : extensions.keySet()) {
+                    targetSchema.addExtension(key, sourceSchema.getExtensions().get(key));
+                }
+            }
         }
 
         if (requiredProperties.size() > 0) {


Test patch:
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266-resolved.yaml b/modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266-resolved.yaml
index df308793..e65304e3 100644
--- a/modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266-resolved.yaml
+++ b/modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266-resolved.yaml
@@ -21,6 +21,42 @@ paths:
                   data2:
                     type: string
                 x-extension-ref: 1
+  /test/extensions/not/inherited/bothinline:
+    get:
+      responses:
+        "200":
+          description: "A test failing on the merge of extensions in a allOf, with\
+            \ same extension defined in referencing and referenced"
+          content:
+            application/json:
+              schema:
+                required:
+                - data
+                properties:
+                  data:
+                    type: string
+                  data2:
+                    type: string
+                x-extension-ref: 3
+  /test/extensions/not/inherited/both:
+    get:
+      responses:
+        "200":
+          description: "A test failing on the merge of extensions in a allOf, with\
+            \ same extension defined in referencing and referenced"
+          content:
+            application/json:
+              schema:
+                required:
+                - data
+                - gps
+                type: object
+                properties:
+                  data:
+                    type: string
+                  gps:
+                    type: string
+                x-extension-ref: 2
 components:
   schemas:
     ResponseModel:
@@ -31,3 +67,14 @@ components:
         data:
           type: string
       x-extension-ref: 1
+    ExtendedResponseModel:
+      required:
+      - data
+      - gps
+      type: object
+      properties:
+        data:
+          type: string
+        gps:
+          type: string
+      x-extension-ref: 2
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266.yaml b/modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266.yaml
index 4d38aa12..6b493414 100644
--- a/modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266.yaml
+++ b/modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266.yaml
@@ -13,6 +13,17 @@ components:
       properties:
         data:
           type: "string"
+    ExtendedResponseModel:
+      type: object
+      x-extension-ref: 2
+      allOf:
+        - $ref: '#/components/schemas/ResponseModel'
+        - type: object
+          required:
+            - gps
+          properties:
+            gps:
+              type: string          
 
 paths:
   /test/extensions/not/inherited:
@@ -28,4 +39,28 @@ paths:
                   - type: "object"
                     properties:
                       data2:
-                        type: "string"
\ No newline at end of file
+                        type: "string"
+  /test/extensions/not/inherited/bothinline:
+    get:
+      responses:
+        200:
+          description: "A test failing on the merge of extensions in a allOf, with same extension defined in referencing and referenced"
+          content:
+            application/json:
+              schema:
+                allOf:
+                  - $ref: "#/components/schemas/ResponseModel"
+                  - type: "object"
+                    x-extension-ref: 3
+                    properties:
+                      data2:
+                        type: "string"                       
+  /test/extensions/not/inherited/both:
+    get:
+      responses:
+        200:
+          description: "A test failing on the merge of extensions in a allOf, with same extension defined in referencing and referenced"
+          content:
+            application/json:
+              schema:
+                $ref: "#/components/schemas/ExtendedResponseModel"