-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Path item $refs override inline operations instead of merging #3664
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
Comments
I think this can be closed. According to https://swagger.io/docs/specification/using-ref/#sibling the observed behavior is as described. |
No, this is an actual issue. Path items $refs are different from other $refs in that they are supposed to be merged with siblings. |
Okay… Didn't know that. Tbh. I came here because I thought a merge or overwrite would be helpful in other places too. See: https://gist.github.com/Skeeve/4d0b41626bdaa82ea1a12d2e4bbd7b55 I have in my schema different sets of required properties. With the posibillity to merge, this could be handled. As far as I know I have to duplicate what's defined in the schema in order to be able to achieve the case of different required properties. |
@Skeeve the next version of the OpenAPI Specification, 3.1, will support |
Thanks again @hkosova, but I seem to not understand how to do that. Swagger Editor keeps complaining about structural errors. Maybe you can give me a hint? This is what I currently think I would have to have because of not understanding how to properly achieve it: openapi: 3.0.2
paths:
/manage/client:
post:
summary: Create a new Client
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/create_Client'
put:
summary: Modify a Client
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/modify_Client'
components:
schemas:
create_Client:
title: Clientdata
type: object
required:
- client_id
- client_name
- complaint_address
properties:
client_id:
type: string
client_name:
type: string
complaint_address:
type: string
format: email
fbl_address:
type: string
format: email
status:
type: string
pattern: ^(standard|partner|prospect|suspended|delisted|deleted)$
modify_Client:
title: Clientdata
type: object
properties:
client_id:
type: string
client_name:
type: string
complaint_address:
type: string
format: email
fbl_address:
type: string
format: email
status:
type: string
pattern: ^(standard|partner|prospect|suspended|delisted|deleted)$ You see: The |
Hmmm… Could it be, this is correct? /manage/client:
post:
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Client'
put:
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
anyOf:
$ref: '#/components/schemas/Client/properties' |
Demonstration API definition
2.0 spec:
3.0 spec:
Expected Behavior
/foo2
displays both GET (added by$ref
) and POST (defined inline).Current Behavior
/foo2
displays GET only.Context
According to OAI/OpenAPI-Specification#1038 (comment), when a path item contains a
$ref
, the referenced operation is added (merged) to other operations in this path. Unlike regular JSON references, path item$ref
s are not supposed to override their sibling elements.The text was updated successfully, but these errors were encountered: