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

Doubt with Path Parameter Validation #95

Closed
triptesh1212 opened this issue May 2, 2024 · 2 comments
Closed

Doubt with Path Parameter Validation #95

triptesh1212 opened this issue May 2, 2024 · 2 comments

Comments

@triptesh1212
Copy link

Hi, I have the following api speficiation.

{
  "openapi": "3.0.0",
  "info": {
    "title": "API Spec With Mandatory Header and Query Parameters",
    "version": "1.0.0"
  },
  "paths": {
    "/api-endpoint/{id}": {
      "get": {
        "summary": "Restricted API Endpoint",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "apiKey",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "userId",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyHeader": {
        "type": "apiKey",
        "name": "apiKey",
        "in": "header"
      }
    }
  },
  "security": [
    {
      "ApiKeyHeader": []
    }
  ]
}

(1) /api-endpoint gives the following error which is expected

GET Path '/api-endpoint' not found

(2) /api-endpoint/ does not give any error. Can anyone confirm if the empty string can be taken as path parameter ? (I have kept path parameter required as true. So, my expectation is if its empty then it should fail)

@ralfhandl
Copy link
Contributor

Path segments can be empty, although some OpenAPI tools are pickier than others.

You could add a pattern requiring at least one character, or be even more restrictive.

@lornajane
Copy link
Collaborator

This seems to have been well answered by @ralfhandl so I'll close the issue - let us know if you need anything else though!

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

3 participants