-
Notifications
You must be signed in to change notification settings - Fork 88
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
Validate path params defined on the path item #86
base: master
Are you sure you want to change the base?
Conversation
Since parameters can be defined on both the path item or the operation, we need to validate path params against both objects, like we do with the query params.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly, we need to check at that place as well.
But when Path Item and Operation have same name path parameters, we should overwrite by the latter.
If a parameter is already defined at the Path Item, the new definition will override it but can never remove it.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#operationObject
So if the path params is valid in Operation and invalid in Path Item, probably we'll get error 🤔
For example, GET /api/test/test_3
is valid request in this definition, but I think we'll get error.
openapi: 3.0.3
info:
title: example
version: '1.0'
paths:
/api/test/{op}:
parameters:
- name: op
in: path
required: true
schema:
type: string
enum:
- test1
- test2
get:
parameters:
- name: op
in: path
required: true
schema:
type: string
enum:
- test3
responses:
default:
description: sample
content:
'application/json':
schema:
type: object
So we need merge these parameters and validate.
But this is a potential bug so I can take over and fix it 🙋
@ota42y ahh good catch! I'm not likely to be able to look at this for a week or so. If I get to it before you I'm happy to have a go, otherwise all yours. Thanks! 😁 |
There is no reason to rush to release a new version, so give it a try! 😄 |
Since parameters can be defined at either the path item or operation level, operation params are effectively merged into the existing path item params for the given location. Per OpenAPI Specification 3.0.3: > If a parameter is already defined at the Path Item, the new definition will override it but can never remove it. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a name and location.
@ota42y I haven't added any specs for this yet, I wanted to see what you thought of the implementation. I've opted to merge the individual hashes explicitly in the Alternatively, we could add a public # module OpenAPIParser::ParameterValidatable
def merged_params
return divided_parameter_hash unless parent&.respond_to?(:merged_params)
@merged_params ||= Hash.new do |merged_params, location|
parent_params = parent.merged_params[location] || {}
merged_params[location] = parent_params.merge(divided_parameter_hash[location])
end
end
def header_parameter_hash
merged_params['header'] || {}
end
# etc… I think this is a more abstract and less obvious approach though. What do you think? |
Sorry for late reply... 🙇
Your approach( merging in the
|
@ota42y thanks for the feedback. I'll add some specs and ping you for a final review. |
Since parameters can be defined on both the path item or the operation, we need to validate path params against both objects, like we do with the query params.