Closed magx2 closed 2 months ago
I don't really know how to handle this case since we often consider "Optional" as a java syntaxic sugar - not translated into json.
For example, with Spring MVC with a default configuration, if you return an optional in a controller : it return the original object or null.
Do you have the use case only for you Dtos? Or for your api body/return contracts declarations also? *
Example for the second case :
Optional
I think that there is a misunderstanding.
If I have an optional in class it's being unpacked to concrete type. On the other side optional in interfaces are not unpacked.
I would like to see the same behavior in interfaces as we have with classes
Oh, got it! Indeed, I got it wrong. This is a fine request, added to the todo. :)
Same problem would appear in parameters:
public String optionalParameter(@RequestParam("optional") Optional<String> optional) {
return optional.orElse("default");
}
parameters:
- name: optional
in: query
required: true # HERE!
schema:
type: object
properties:
value:
type: string
I think that there is a misunderstanding.
If I have an optional in class it's being unpacked to concrete type. On the other side optional in interfaces are not unpacked.
I would like to see the same behavior in interfaces as we have with classes
Are you sure it is linked to class vs interface? I could not reproduce this bug. For me the only unwrapping actually in the app is if an Optional is used as a webservice response. Everywhere else, there is no unwrapping. (before the PR I'm working on)
Here you have code to reproduce it https://github.com/magx2/openapi-maven-plugin-error/commit/198880cdd3cb9ee233e4bb074e88ed82d8daf082
It's not a problem of not unpacking Optional in interface but rather not setting required to false. I thought it's similar code space so I've pointed it here. If you want you can create new issue
Ok, got it. No, it's ok, no worries, I'll keep working on my current MR.
Hello Martin. Do you mind testing if you have the time the current version on the "dev" branch? And check if it fix this bug well for you?
Thank you very much by advance. ;)
Works for me :). LGTM!
sob., 24 lut 2024 o 16:13 Kévin Buntrock @.***> napisał(a):
Hello Martin. Do you mind testing if you have the time the current version on the "dev" branch? And check if it fix this bug well for you?
Thank you very much by advance. ;)
— Reply to this email directly, view it on GitHub https://github.com/kbuntrock/openapi-maven-plugin/issues/106#issuecomment-1962397890, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAWTLHQN5LH65DC2NUJR66LYVH7Q3AVCNFSM6AAAAABAWCR4MSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRSGM4TOOBZGA . You are receiving this because you authored the thread.Message ID: @.***>
-- Pozdrawiam Martin Grześlowski
Nice, thank you :)
I just found that if you have
Optional
in interface it does not get unpacked:Produces this YML:
instead of unpacked Optional:
If you want to reproduce it you can look at my repo: https://github.com/magx2/openapi-maven-plugin-error