Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path level server object with variables is not handled correctly #160

Closed
ganeshnikam18 opened this issue Jan 31, 2020 · 1 comment · Fixed by postmanlabs/postman-app-support#8464
Labels
bug Something isn't working

Comments

@ganeshnikam18
Copy link

{
   "openapi": "3.0.0",
   "info": {
     "version": "1.0.0",
     "title": "Swagger Petstore",
     "license": {
       "name": "MIT"
     }
   },
   "servers": [
     {
       "url": "http://petstore.swagger.io/v1"
     }
   ],
   "paths": {
     "/pets": {
      "servers": [
         {
           "url": "http://petstore.swagger.io:{port}/{basePath}",
          "variables": {
             "port": {
               "enum": [
                 "8443",
                 "443"
               ],
               "default": "8443"
             },
             "basePath": {
               "default": "v2"
             }
          }
         }
      ],
       "get": {
         "summary": "List all pets",
         "operationId": "listPets",
         "tags": [
           "pets"
         ],
         "parameters": [
           {
             "name": "limit",
             "in": "query",
             "description": "How many items to return at one time (max 100)",
             "required": false,
             "schema": {
               "type": "integer",
               "format": "int32"
             }
           }
         ],
         "responses": {
           "200": {
             "description": "A paged array of pets",
             "headers": {
               "x-next": {
                 "description": "A link to the next page of responses",
                 "schema": {
                   "type": "string"
                 }
               }
             },
             "content": {
               "application/json": {
                 "schema": {
                   "$ref": "#/components/schemas/Pets"
                 }
               }
             }
           },
           "default": {
             "description": "unexpected error",
             "content": {
               "application/json": {
                 "schema": {
                   "$ref": "#/components/schemas/Error"
                 }
               }
             }
           }
         }
       },
       "post": {
         "summary": "Create a pet",
         "operationId": "createPets",
         "tags": [
           "pets"
         ],
         "responses": {
           "201": {
             "description": "Null response"
           },
           "default": {
             "description": "unexpected error",
             "content": {
               "application/json": {
                 "schema": {
                   "$ref": "#/components/schemas/Error"
                 }
               }
             }
           }
         }
       }
     },
     "/pets/{petId}": {
       "get": {
         "summary": "Info for a specific pet",
         "operationId": "showPetById",
         "tags": [
           "pets"
         ],
         "parameters": [
           {
             "name": "petId",
             "in": "path",
             "required": true,
             "description": "The id of the pet to retrieve",
             "schema": {
               "type": "string"
             }
           }
         ],
         "responses": {
           "200": {
             "description": "Expected response to a valid request",
             "content": {
               "application/json": {
                 "schema": {
                   "$ref": "#/components/schemas/Pet"
                 }
               }
             }
           },
           "default": {
             "description": "unexpected error",
             "content": {
               "application/json": {
                 "schema": {
                   "$ref": "#/components/schemas/Error"
                 }
               }
             }
           }
         }
       }
     }
   },
   "components": {
     "schemas": {
       "Pet": {
         "type": "object",
         "required": [
           "id",
           "name"
         ],
         "properties": {
           "id": {
             "type": "integer",
             "format": "int64"
           },
           "name": {
             "type": "string"
           },
           "tag": {
             "type": "string"
           }
         }
       },
       "Pets": {
         "type": "array",
         "items": {
           "$ref": "#/components/schemas/Pet"
         }
       },
       "Error": {
         "type": "object",
         "required": [
           "code",
           "message"
         ],
         "properties": {
           "code": {
             "type": "integer",
             "format": "int32"
           },
           "message": {
             "type": "string"
           }
         }
       }
     }
   }
 }

Here there is server object at path level with server variables. When we import this file in postman tool then the request url for '/pets' path is not generated correctly. The request looks like below:
image

Three issues in above request

  1. The '/pets' path part is missing
  2. In the path variables only 'basePath' is added. I think 'port' variable should also be added.
  3. collection variable replacement is not happening when we run the collection. The request URL for the 1st request (after running the collection) is as below:
    http://petstore.swagger.io::port/{{basePath}}?limit=

The collection does has all the variables:
image

@umeshp7
Copy link
Member

umeshp7 commented Jun 12, 2020

Here is the new behavior:
The {{petsUrl}} was created but wasn't respected. Now it will be used instead of the http://petstore.swagger.io::port/{{basePath}}?limit=

Screenshot 2020-06-12 at 8 33 40 PM

Screenshot 2020-06-12 at 8 28 47 PM

@ganeshnikam18
Hope this solves your usecase. Feel free to open this issue again if you have more inputs/concerns :)

@umeshp7 umeshp7 closed this as completed Jun 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants