Skip to content

Conversation

@VIIgit
Copy link

@VIIgit VIIgit commented Nov 11, 2018

No description provided.

@gracekarina
Copy link
Contributor

I'm sorry @VIIgit but I still don`t understand the issue. Can you please explain. thanks.

@VIIgit
Copy link
Author

VIIgit commented Nov 11, 2018

Without the fix, not all references were resolved:

Parser's Message returns:

[ "Invalid ref format: ./sub-folder/common-responses.yaml#/responses/Ok201#/definitions/User" ]

By resolving a reference which is referring again a relative linked file then the format "INTERNAL" is used to resolve the reference instead of correct refModel's format "RELATIVE".

Without the fix, the provided swagger-root.yaml example doesn't resolve response 201

{
  "swagger" : "2.0",
  ...
  "paths" : {
    "/users" : {
      "get" : {
        "summary" : "Returns a list of users.",
        "description" : "Optional extended description in Markdown.",
        "produces" : [ "application/json" ],
        "parameters" : [ ],
        "responses" : {
          "200" : {
            "description" : "OK",
            "schema" : {
              "$ref" : "#/definitions/User"
            }
          },
          "201" : {
            "$ref" : "./sub-folder/common-responses.yaml#/responses/Ok201"
          }
        }
      }
    }
  },
...

after the fix the all references are resolved correctly

{
  "swagger" : "2.0",
...
  "paths" : {
    "/users" : {
      "get" : {
        "summary" : "Returns a list of users.",
        "description" : "Optional extended description in Markdown.",
        "produces" : [ "application/json" ],
        "parameters" : [ ],
        "responses" : {
          "200" : {
            "description" : "OK",
            "schema" : {
              "$ref" : "#/definitions/User"
            }
          },
          "201" : {
            "description" : "OK",
            "schema" : {
              "$ref" : "#/definitions/User"
            }
          }
        }
      }
    }
  },
...

@gracekarina gracekarina merged commit 518da9d into swagger-api:v1 Nov 14, 2018
@john3300
Copy link

Will/can this be added to master too?

@gracekarina
Copy link
Contributor

Please send a PR, will make it faster 👍

@VIIgit
Copy link
Author

VIIgit commented Nov 15, 2018

Will/can this be added to master too?

The exact same data constellation but as OpenApi 3 files and with openApiParser works as expected. So I believe there is no need to add it to the master.

@john3300
Copy link

john3300 commented Nov 16, 2018

Fair enough, thanks @VIIgit.

I did check out this branch and tried to run the tests that you added with Maven but none of the tests in that class seem to be executed. Am I missing something?

Your tests cover when the common file has a reference back to the root file. But the scenario I am facing and want to test is when the common file has a reference inside itself. Like this:

root.yaml

paths:
  /employees/{id}:
    get:
      responses:
        404:
          $ref: './common.yaml#/responses/notFound'

common.yaml

responses:
  notFound:
    description: Not found
    schema:
      $ref: '#/definitions/error'
definitions:
  error:
    type: object
    properties:
      msg:
        type: string

I don't think this scenario was covered in your tests but I'm hoping that your fix will take care of this too.

@VIIgit
Copy link
Author

VIIgit commented Nov 17, 2018

I've tested it only locally and didn't make a pull request.

And I also tested your use case positively.👌

@john3300
Copy link

john3300 commented Nov 17, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants