postmanlabs / openapi-to-postman

Plugin for converting OpenAPI 3.0 specs to the Postman Collection (v2) format
Apache License 2.0
931 stars 200 forks source link

"host" is not generated if relative path is specified on the path or operation level in OAS file #691

Open armen-ch opened 1 year ago

armen-ch commented 1 year ago

According to https://swagger.io/docs/specification/api-host-and-base-path/ "Relative URLs" if relative path is specified on the path level or operation level and if the definition hosted at http://localhost:3001/openapi.yaml and specifies url: /v2, the url is resolved to http://localhost:3001/v2. So based on this my expectation is if I specify relative path on non-global level like below:

`openapi: 3.0.1
info:
  title: 'Test api'
  version: 1.0.0
servers:
  - url: http://localhost:3001
. . .
paths:
  '/products':
    get:
      servers:
        - url: /v2
. . .

then it should be resolved to http://localhost:3001/v2 and openapi-to-postman will generate something like:

         "request": {
            "name": "my request",
            "url": {
              "path": [
                "v2",
                "products"
              ],
              "host": [
                "{{baseUrl}}"
              ],
       . . .
       }

but currently the collection is generated without the host parameter:

         "request": {
            "name": "my request",
            "url": {
              "path": [
                "v2",
                "products"
              ],
       . . .
       }
VShingala commented 1 year ago

@armen-ch So what's mentioned in the swagger docs is applicable to only where you use can use/link external resource via link directly. It doesn't not apply to servers as value of url in sever is absolute (i.e. string).

Also, URLs are relative to where file is hosted. So for example if it's hosted at localhost:1337/definition.yaml' than all resources you mention via relative URL should be present alocalhost:1337/{resource}`.

To clarify more, see section "Overriding Servers". It states that The global servers array can be overridden on the path level or operation level.. It does not mention anything for relative URLs.

Examples mentioned in this doc have relative URLs for termsOfService and externalDocs where you can link URL itself where actual resource is present. There's no mention of server URLs also accepting relative URL here.