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

Not able to identify the missed path variables #911

Closed
parameshjava opened this issue Nov 5, 2018 · 6 comments
Closed

Not able to identify the missed path variables #911

parameshjava opened this issue Nov 5, 2018 · 6 comments

Comments

@parameshjava
Copy link

parameshjava commented Nov 5, 2018

Hi,

It's showing a valid JSON though the path variables are missed to declare. We can find the error, if we keep the same JSON in editor.swagger.io.

Please find the below sample JSON:

{
  "swagger": "2.0",
  "info": {
    "description": "Pets Reference Data",
    "version": "1.0",
    "title": "Pets Reference Data"
  },
  "host": "localhost:8080",
  "basePath": "/api/pets/referencedata/v1.0",
  "tags": [
    {
      "name": "Pets Reference Data Operations",
      "description": "Pets Reference Data Controller"
    }
  ],
  "paths": {
    "/{tenantId}/categories/{categoryCode}": {
      "get": {
        "tags": [
          "Dynamic Codces Operations"
        ],
        "summary": "Reference Data Service",
        "description": "Retrieves the ReferenceData for a given tenant id, category and sub category with language code as english",
        "operationId": "Reference Data Service_2",
        "produces": [
          "*/*"
        ],
        "parameters": [
          {
            "name": "categoryCode",
            "in": "path",
            "description": "categoryCode",
            "required": true,
            "type": "string"
          },
          {
            "name": "subCategoryCode",
            "in": "query",
            "description": "subCategoryCode",
            "required": false,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "$ref": "#/definitions/petsDataResponse"
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not Found"
          }
        }
      }
    }
  },
  "definitions": {
    "Domain": {
      "type": "object",
      "properties": {
        "b2X": {
          "type": "string"
        },
        "documentation": {
          "type": "string"
        },
        "key": {
          "type": "string"
        },
        "memberValue": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "verbalization": {
          "type": "string"
        }
      },
      "title": "Domain"
    },
    "Error": {
      "type": "object",
      "properties": {
        "errorCode": {
          "type": "string"
        },
        "errorDescription": {
          "type": "string"
        }
      },
      "title": "Error"
    },
    "petsDataResponse": {
      "type": "object",
      "properties": {
        "messageElements": {
          "$ref": "#/definitions/messageElements"
        },
        "tenant": {
          "$ref": "#/definitions/tenant"
        },
        "codeReferences": {
          "type": "array",
          "description": "List of Pet Code References based on input.",
          "items": {
            "$ref": "#/definitions/PetsReferenecData"
          }
        }
      },
      "title": "petsDataResponse",
      "description": "A data transfer object to send a response."
    },
    "messageElements": {
      "type": "object",
      "properties": {
        "businessCorrelationId": {
          "type": "string"
        },
        "errorList": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Error"
          }
        },
        "messageStatus": {
          "type": "string"
        }
      },
      "title": "messageElements",
      "description": "A data transfer object, that holds transaction result codes and descriptions."
    },
    "tenant": {
      "type": "object",
      "properties": {
        "tenantId": {
          "type": "number"
        },
        "tenantName": {
          "type": "string"
        },
        "timezone": {
          "type": "string"
        }
      },
      "title": "tenant",
      "description": "Holds Tenant's information."
    },
    "PetsReferenecData": {
      "type": "object",
      "properties": {
        "category": {
          "type": "string"
        },
        "languageCode": {
          "type": "string"
        },
        "subCategory": {
          "type": "string"
        },
        "value": {
          "type": "string"
        }
      },
      "title": "PetsReferenecData"
    }
  }
}

To become a valid swagger json, we need to have the below in parameters list.

{
	"name": "tenantId",
	"in": "path",
	"description": "tenantId",
	"required": true,
	"type": "string"
  }

Swagger editor will report the below issue.

image

But, this library not able to identify this issue.

@ymohdriz
Copy link
Contributor

ymohdriz commented Nov 8, 2018

Hi @parameshjava,

Spec says as below:
If in is "path", the name field MUST correspond to the associated path segment from the path field in the Paths Object.

Spec doesn't specify about the reverse.
Let's wait for others view and decide on this issue.

Thanks,
Mohammed

@parameshjava
Copy link
Author

parameshjava commented Nov 12, 2018

@ymohdriz

In such case, if we forgot to declare path parameter in resource path, still swagger-parser certifies that the json is well formed. But, when we keep this in swagger editor, it complains. I am not sure the difference in schema referred by online editor and swagger parser. It would be a great help, if we can achieve the validation same as online editor.

@ymohdriz
Copy link
Contributor

@parameshjava

Makes sense and I have raised a PR to fix this issue.

Thanks,
Mohammed

@gracekarina
Copy link
Contributor

Hi @parameshjava We hope this PR have solved this issue. please let us know how it goes. thanks @ymohdriz

@mih-kopylov
Copy link
Contributor

mih-kopylov commented Jan 1, 2019

Hi, @gracekarina @parameshjava @ymohdriz
Unfortunately PRs for this issue do not take into account parameters references defined with $ref.

paths:
  /users/{id}"
    get:
      parameters:
        - $ref: "#/components/parameters/userId"
components:
  parameters:
    userId:
      name: id
      in: path
      required: true

io.swagger.v3.parser.OpenAPIV3Parser#readLocation this method first calls result = readWithInfo(url,auth); where your patch happens.
The patch analyses parameters and sees only $ref, so new warning appears.
Then resolver works and all references become resolved, and the OpenAPI entity becomes valid, but the warning is kept.

Probably the analysis should happen after the resolver works.

I think that this issue should be reopened or another one should be created. What's better?

@jjlin
Copy link

jjlin commented Jan 10, 2019

@fujigon followed up with issue #976.

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

No branches or pull requests

5 participants