-
Notifications
You must be signed in to change notification settings - Fork 86
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
No $ref when the required attribute of the schema is used #308
Comments
According to smallrye-open-api/core/src/main/java/io/smallrye/openapi/runtime/util/JandexUtil.java Lines 441 to 450 in e617fc7
Which is used in smallrye-open-api/core/src/main/java/io/smallrye/openapi/runtime/io/schema/SchemaFactory.java Line 221 in f640f55
This is an expected behavior. But is that correct given that the annotation provided is using the default values? |
/cc @MikeEdgar |
@agoncal, @gastaldi - thank you for opening and initiating the research on this. I agree that this is not ideal behavior and should be improved. As you've noted, specifying any attribute other than |
This situation can be handled simply, but the case where a non-default value is given would still result in this behavior. I think that is generally good because What are your thoughts on this? |
What if you (blindly) merge the two schemas without worrying about the number of properties defined? Would that produce an invalid output? |
The situation where there are two (or more) |
And what about having an |
@agoncal - those are questions about the specification. That being said, in version 2.0 there will be two new annotations that may help - The more I think about this issue, the more I lean away from attempting to treat property values that are equal to the annotation defaults the same as unspecified annotation properties. We have usually considered values that are specified to be the user/developer declaring that the property should be serialized in the resulting OpenAPI result. This is a challenging situation because using If we treat specified values that are equal to the defaults as if they were unspecified, we may immediately run into trouble where the app developer was expecting values in the output that no longer appear. @phillip-kruger , @EricWittmann - what are your thoughts on this topic? |
I'll be honest, I have no idea... I don't understand the issue at all... Just looking at the original issue logged, it seems like adding required should not change the schema much, but I don't have all the context and background you have... |
The idea is this - if I have two The question with this issue is, if a user provides a customization to |
Ok , so is the |
To be honest, I set |
Suppose I have two @Schema(implementation = MyBean.class)
Object bean1;
@Schema(implementation = MyBean.class)
Object bean2; The scanner "knows" that it can create an entry in @Schema(implementation = MyBean.class, nullable = false) // Explicitly giving the default value
Object bean1;
@Schema(implementation = MyBean.class)
Object bean2; Regarding the question of how default values should be handled, the scanner will only output annotation properties that have been specified in the code. Even if a property is the same as the default value, its presence is taken as a request by the application to display that value in the output, default or not. At the moment, the scanner actually doesn't know anything about the annotations' default values. If we change that, then we will break many applications that are currently specifying values equal to the defaults via annotations where those properties would no longer appear in the resulting output. I hope I'm making sense - happy to keep discussing if not :-D |
paths:
/hello:
get:
responses:
default:
content:
application/json:
schema:
$ref: '#/components/schemas/Fruit'
required: true is not valid. See OAI/OpenAPI-Specification#556. This will be improved with OpenAPI |
@agoncal , @gastaldi , @jmini - I think a good balance here would be to allow the Thoughts? |
@MikeEdgar yes, I think it's a good balance... but documentation has to be clear. Because when I am in front of my IDE, hit CTRL+SPACE and see all the possible attributes of an annotation, it's not totally clear that using some of those attributes will totally change the behaviour. So +1 because it's the best/easiest path |
You can find the code here : https://github.com/agoncal/agoncal-bug-openapi
When documenting the OpenAPI with a
required
schema attribute set to eithertrue
orfalse
, the$ref
is not generated.Take the following POJO:
And the following REST endpoint with no
required
attribute in@APIResponse
:You get the following generated contract (notice the
$ref
)Now, add the
required
attribute in@Schema
(to eithertrue
orfalse
):The generated contract does not have a
$ref
anymore (the fruit components is still generated though):The text was updated successfully, but these errors were encountered: