-
Notifications
You must be signed in to change notification settings - Fork 20
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
Issue with Path Parameter Validation #73
Comments
Hello. I wrote a test to check this. func TestNewValidator_CheckMissingSlash(t *testing.T) {
spec := `openapi: 3.0.0
info:
title: API Spec With Mandatory Header and Query Parameters
version: 1.0.0
paths:
"/api-endpoint/{id}":
get:
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: []`
doc, err := libopenapi.NewDocument([]byte(spec))
if err != nil {
t.Fatal(err)
}
m, _ := doc.BuildV3Model()
request, _ := http.NewRequest(http.MethodGet, "https://things.com/host/api-endpoint", nil)
_, errs, _ := FindPath(request, &m.Model)
assert.Len(t, errs, 1)
assert.Equal(t, "GET Path '/host/api-endpoint' not found", errs[0].Message)
request, _ = http.NewRequest(http.MethodGet, "https://things.com/host/api-endpoint/", nil)
_, errs, _ = FindPath(request, &m.Model)
assert.Len(t, errs, 1)
assert.Equal(t, "GET Path '/host/api-endpoint/' not found", errs[0].Message)
} Test passes just fine. I am unable to recreate this. |
Hi, I was directly using GetParameterValidator() method. It usually returned error if path does not match. Here is the code.
(1) For path /api-endpoint is validation successful- false (2) For path /api-endpoint/ is validation successful- true temp.json : {
"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": []
}
]
} |
@daveshanley , could you modify the paths in the spec and try this
|
Hi @daveshanley - i think you can remove the "cannot reproduce" label as the test case which you have written does not match the use-case which is described in this issue . If you remove /host from this test case below
the test case fails and that is the actual issue |
This is a duplicate of #78 https://github.com/pb33f/libopenapi-validator/blob/main/parameters/path_parameters.go#L88 |
added in |
Hi community, I have been using libopenapi-validator library. I have the following api-spec.
(1)
/<host>/api-endpoint
gives the following error which is expectedGET Path '/api-endpoint' not found
(2)
/<host>/api-endpoint/
does not give any error. Can anyone confirm if the library is taking empty string as path parameter ? (I have kept path parameter required as true. So, my expectation is if its empty then it should fail)The text was updated successfully, but these errors were encountered: