-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[REQ] support for x-const extension #1916
Comments
@jmini the suggestion sounds good to me to start with 👍 |
I have discovered that in combination with the type:
type: string
enum:
- User
default: User With the rest-assured client: User u = new User().firstName("John").lastName("Doe");
JSON j = new JSON();
String s = j.serialize(u); Is producing the expected output: {"type":"User","firstName":"John","lastName":"Doe"} I think there is no need to introduce a new extension for this. This issue can be closed for now, as I have a way to solve my requirement. |
Hi @jmini, @wing328 and other colleagues We need to support this definition of constants. How do you see it? Could this request be reopened? Thank you |
Description
Sometimes in a Schema, you know that one of the property must be set to a specific value.
For those cases it would be great to be able to define the value as
x-const
extension in a SchemaExample:
For a user creation call like this one:
The Request Body looks like this:
For the corresponding
UserBody
schema, you know that thetype
attribute must be set to"User"
.The OpenAPI Spec would looks like:
The OpenAPI Spec is discussing about adding
const
as allowed keyword. Using it as extension in between allow to have something that works with OpenAPI v3.Alternative
My understanding is that the current best-practice is to define an
enum
attribute with a single value in the list.This is already supported by OpenAPI-Generator today, but has the drawback that the type needs explicitly to be set:
Swagger UI interprets this pattern correctly and display the value in the UI:
Additional context
Related OpenAPI Spec discussions:
The text was updated successfully, but these errors were encountered: