You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geronimo.apache.org by GitBox <gi...@apache.org> on 2019/08/29 07:47:53 UTC

[GitHub] [geronimo-openapi] edenhaus opened a new pull request #17: Always use reusable object component

edenhaus opened a new pull request #17: Always use reusable object component
URL: https://github.com/apache/geronimo-openapi/pull/17
 
 
   Hi everyone,
   
   currently geronimo uses a schema ref in the components section only starting from the second usage. The first time the object schema is added to the components but also embedded at the calling point.
   This behavior leads to two different classes, if someone uses the openapi.json to generate classes.
   
   For better understanding, i've provided a openapi.json generated before and after the patch.
   Irrelevant parts are removed to keep it small.
   
   Current version:
   ```{
     "components":{
       "schemas":{
         "hello_Greeting":{
           "description":"Bla",
           "properties":{
             "id":{
               "description":"an id",
               "type":"integer"
             },
             "content":{
               "description":"Content",
               "type":"string"
             }
           },
           "required":[
             "id",
             "content"
           ],
           "title":"Greeting",
           "type":"object"
         }
       }
     },
     "paths":{
       "/greeting":{
         "get":{
           ...
           "responses":{
             "200":{
               "content":{
                 "application/json":{
                   "schema":{
                     "description":"Bla",
                     "properties":{
                       "id":{
                         "description":"an id",
                         "type":"integer"
                       },
                       "content":{
                         "description":"Content",
                         "type":"string"
                       }
                     },
                     "required":[
                       "id",
                       "content"
                     ],
                     "title":"Greeting",
                     "type":"object"
                   }
                 }
               }
             }
           }
         }
       },
       "/test":{
         "get":{
           ...
           "responses":{
             "200":{
               "content":{
                 "application/json":{
                   "schema":{
                     "$ref":"#/components/schemas/hello_Greeting",
                     "type":"object"
                   }
                 }
               }
             }
           }
         }
       }
     }
   }
   ```
   
   With my fix:
   ```
   {
     "components":{
       "schemas":{
         "Greeting":{
           "description":"Bla",
           "properties":{
             "id":{
               "description":"an id",
               "type":"integer"
             },
             "content":{
               "description":"Content",
               "type":"string"
             }
           },
           "required":[
             "id",
             "content"
           ],
           "title":"Greeting",
           "type":"object"
         }
       }
     },
     "paths":{
       "/greeting":{
         "get":{
           ...
           "responses":{
             "200":{
               "content":{
                 "application/json":{
                   "schema":{
                     "$ref":"#/components/schemas/Greeting",
                     "type":"object"
                   }
                 }
               }
             }
           }
         }
       },
       "/test":{
         "get":{
           ...
           "responses":{
             "200":{
               "content":{
                 "application/json":{
                   "schema":{
                     "$ref":"#/components/schemas/Greeting",
                     "type":"object"
                   }
                 }
               }
             }
           }
         }
       }
     }
   }
   ```
   
   The difference is at the path "/greeting". The current version will embed the schema and use the ref from the second time on. However the fix will refer to the schema in the components already on the first time.
   
   In addition I have added, that if no providedRef is set and the schema.name attribute is set, it will be used as providedRef.
   
   Feel free to contact me, if you have questions or change something in my fix.
   
   Cheers,
   Robert
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services