-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
[Question] Extend/override properties of a parameter #2026
Comments
Any update about this? |
This would be very helpful. I'm also defining parameters which differ only with required attribute (true |
I have the exact same schema I need to use in three places, I just want to change the top-level description. The schema's the same, the description varies just slightly in ways that are subtly important. So instead of re-using it, I have to duplicate it. |
@geoffreywiseman OAS (or whatever version the next release ends up as being) will support |
OK, now I'm curious about why the next version might not be OAS. ;) Is there somewhere I go to read about that? |
Sorry, there should have been a 3.1 in there, which got lost in editing! |
I agree and also need this feature, but with the addition of wanting to override the example values on my parameters to be more relevant to each operation. Or the ability to do some type of allOf on parameters where I can include an existing parameter definition and override one or more properties as you can with schemas. |
Also running into a use for this. I've got parameters that are reused across multiple endpoints, but they're sometimes query parameters and sometimes path parameters, depending on whether they're identifying a single resource or filtering a collection of resources. |
Yes, same need here. Also not the first time I end up on this thread 😄 So much duplication going on in my OpenAPI definitions, at the moment. |
I am also feeling the need for the same. |
I've another use-case for this No reuse: openapi: 3.0.0
components:
schemas:
TextContainer:
type: object
properties:
format:
title: Text Format
description: Type of formatting of this text.
type: string
enum:
- plain
- html
- markdown
default: plain
text:
type: string
required:
- text
paths:
/find:
get:
summary: FindTexts
description: Find specific texts
parameters:
- name: q
in: query
required: true
schema:
type: string
- name: only
in: query
required: false
schema:
description: Optionally filter a specific text type.
type: string
enum:
- plain
- html
- markdown
- any
default: any 3 different features I'd like here, please note that:
The way I would like it to work: openapi: 3.0.0
components:
schemas:
TextFormat:
title: Text Format
description: Type of formatting of this text.
type: string
enum:
- plain
- html
- markdown
TextContainer:
type: object
properties:
format:
$ref: '#/components/schemas/TextFormat'
default: plain
text:
type: string
required:
- text
paths:
/find:
get:
summary: FindTexts
description: Find specific texts
parameters:
- name: q
in: query
required: true
schema:
type: string
- name: only
in: query
required: false
schema:
$ref: '#/components/schemas/TextFormat'
// override
description: Optionally filter a specific text type.
enum:
// some way to tell I want to add to the enum (a similar argument could be done for exclude)
- $add: [any]
default: any |
Allowing to reuse referenced params with option to override "required" flag would be awsome |
Is this going to be available in v3.1 ? |
3.1.0 is already out. You can override the |
Any news about overriding |
Why not allow overriding everything instead of field by field ?
it looks like for now |
We'd also like to override see also: nestjs/swagger#1723 |
As the Swagger Editor suggests, one could wrap the
See https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/#allof |
@axl8713 your example is unfortunately not a valid construct in OpenAPI.
|
I've got misleaded by the Swagger Editor then, where it seems at least to be rendered correctly (although with some structural errors). |
Having the same issues. Would very much want a consistent way to override properties. Others have mentioned examples of properties that basically need this functionality, but I don't see why the spec should pick and choose what properties are overridable. |
This, please. |
Anything below the |
To qualify, I am not saying people should not use aliases to help them create OAS descriptions efficiently. We fully support folks who start with some other format and use tooling to create their OAS description. If that tooling is a yaml parser that can dereference aliases, then all the power to you. |
@darrelmiller which YAML parsers don't support aliases? 😁 Any OAS tool using a YAML parser is (almost certainly) going to support aliases whether we like it or not. ( |
@MikeRalphson I don't know. Are there YAML parsers that will enforce the JSON Schema ruleset, and if so will it still process aliases? What if I rephrased and said that users should not expect OAS tooling to preserve aliases after parsing? Which leads us to another conversation... I don't think application/openapi+yaml should declare support for aliases in fragment identifiers. |
@darrelmiller I'll test with @eemeli's I'm about 75% minded the other way, in that we should allow alias fragments in |
@MikeRalphson You're just a sucker for punishment ;-) |
As long as the resulting document is valid OAS, limiting YAML syntax can be problematic and barely enforceable. |
@darrelmiller I've tested with @eemeli's |
Anchors and aliases are a YAML feature that's independent of the schema. The following works for me: import { parse } from 'yaml'
const src = `
"a": &a 42
"b": *a`
parse(src, { schema: 'core' }) // { a: 42, b: 42 }
parse(src, { schema: 'failsafe' }) // { a: '42', b: '42' }
parse(src, { schema: 'json' }) // { a: 42, b: 42 } In your testing, you may have hit a stumbling block on string scalars needing to be quoted when using the |
Doh! I'm sure that's it, thank you. Glad I tagged you now. |
@darrelmiller Confirmed. You can use aliases in the JSON ruleset/schema if you quote your keys and values. |
It would be great to be able to override example values. We have an in-house API testing framework that uses the examples to run some tests, and in some cases multiple endpoints sharing the same path parameter can't be tested with the same example value. |
It's Jan 2024, still no solution ( > 4 years ) ? |
@zzafarr it is addressed by the Moonwalk (OAS 4) proposal - I'm pretty certain that the amount of change required can only be done in a major version update. I have also filed #3508 to figure out how to clarify this sort of thing, as there are a lot of open issues in this repo that look abandoned but are actually being actively worked on in the Moonwalk repo. [EDIT: There's no guarantee that every aspect of this will be solved by Moonwalk, but it's where the issue is being considered, and I'm confident that there will be some improvements in this area.] |
Hi @handrews, thank you for the info! I just read the Moonwalk proposal, and I couldn't find a way to override the values of a |
@ChihweiLHBird the reason you couldn't find it is that it's not there, at least not yet, and it's not clear to us how to best address that use case. With the scope of JSON Schema, well.. it's a constraint system and requires a very different sort of organization for re-use than (for example) strongly typed OO languages like Java. In the larger scope of OpenAPI, the proposed Overlay Specification is one idea for doing such edits at a higher level, which would target 3.x. For Moonwalk, we just don't know how it's all going to fit together yet. Is JSON Schema even the right technology for all of this? Should we use more JSON Schema? Less JSON Schema? Make it an option to replace it with something else? All of this is being debated in-depth, and it's not clear where we will land yet. The mismatch between JSON Schema as a constraint system and the needs of code generators is one of the most difficult topics we're working through. |
Can't this be done using |
@9ao9ai9ar as you can see in #3528 and #3529, we do intend to stick with semantic versioning. 3.1 was a very complex situation with no good option for compatibility, but it was also for a very specific reason which is not going to be a problem in the future. 3.0.4 and 3.1.1 should be out within a couple of months, and there will be a 3.2 (strictly compatible with 3.1, and with a small amount of enhancements that should make it fairly quick to implement) before there will be a 4.0. We are looking at trying out 4.0 ideas in the 3.x series, so it's possible that shipping "Moonwalk" in 2024 will actually look like shipping incremental 3.x releases containing Moonwalk ideas rather than shipping a full 4.0 within the next few months. It's very up in the air as of this week. Some things in 3.0.4 and 3.1.1 are specifically about clarifying requirements that come from other specificaitons on which the OAS depends. BTW, |
@9ao9ai9ar I forgot to answer your initial question - yes, at least some use cases can be handled by |
@handrews Looking forward to the 3.0.4 and 3.1.1 publications! I like the idea of doing incremental releases; even though OpenAPI still feels lacking in some areas, I think what we currently have in 3.1, if fully supported by available tools and documented clearly, is powerful enough to meet most requirements. About I also have a need for generic types for a personal project I'm working on right now. Sadly, the tool I use is awesome in every way except not supporting |
I believe you could do: openapi: 3.0.1
info:
title: An include file to define common parameters
version: 1.0.0
paths:
/test:
get:
parameters:
- $ref: 'reusableParam.yaml'
responses:
200:
description: OK
/test-2:
get:
parameters:
- name: reusableParam
allOf:
- $ref: 'reusableParam.yaml'
- required: true
- schema:
type: number
default: 50
responses:
200:
description: OK And in another file name: reusableParam
in: query
description: filter something
schema:
type: number
default: 30 |
@guizoxxv |
@handrews It seems to work when I run |
Hello there, I got a small question about the compoments[parameter]
Currently, im trying to make some parameters reusable and the basic seems pretty simple.
Now my question is, how can I avoid to duplicate the
reusableParam
if another path might need the same one but maybe withrequired: true
or differentdefault: 50
what would be the "correct" way to do it?
Thank you in advance.
The text was updated successfully, but these errors were encountered: