-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
How can I extend all models with x-nullable extensions if the type is Option? #69
Comments
I figured it out. I need to add the listener to the apiTypes. |
@jenol if you could do a small sample demonstrating your solution on your github or bitbucket account, I can link to it from the README page. |
@pjfanning this is how far I got. I still need a way to recognize the original property type. I can add the x-nullable based on that. io.swagger.models.properties.Property doesn't seem to have a reference to the original type or original type name which would make things easier. I need to check if I can use required or format or a combination of properties to figure out if the type meant to be nullable. For this I will need to look deeper into the reader implementation. https://gist.github.com/jenol/975ea072e60a893efedb9d51643ac812 |
Options should have property.isRequired() == false |
It looks like getRequired is true for Option property types. I will keep digging |
https://github.com/swagger-akka-http/swagger-akka-http/blob/master/src/main/scala/com/github/swagger/akka/SwaggerScalaModelConverter.scala has the support scala.Option - maybe you could add an option test case that demonstrates an option that isn't appearing as required=false (see the src/test dir for existing unit tests like this) |
Good suggestion. I will do that. Thank you |
I did some testing and getRequired seems to work correctly but the type is not correct. I updated the gist.
Should generate
but generates
|
@pjfanning do you think this change would fix this issue? https://github.com/jenol/swagger-akka-http/commit/14805d6fb0dcd00251e01cde6146378c8a1542ec |
@jenol your code does not compile and it looks like a lot of unit tests will be affected by the change |
Sorry about that. I am having issues with setting up the project on Windows and IntelliJ. I should have sent a gist. I just wanted to show the part of the code which may not handle all option types correctly. I will keep at it when I have a bit of time. :) |
The code for inferring swagger models from Java/Scala classes is based on Java reflection and jackson-databind. It appears that for Option[T] where T is a primitive type like Int/Long/Double that this type info is erased. |
hi @pjfanning not sure if I understand... |
@ddfic I meant subclassing the classes generated by protoc |
Hello, i saw this issue after we upgraded to 0.13.0 |
I am using this tool on a large Akka HTTP project and I am very pleased with it. Keep up the good work!
I need a bit of help with one issue though. I would like to enrich all model types with an x-nullable vendor extension for property types of Option. This seems to be the most common workaround to support nullable types in Swagger 2.
I cannot decorate the models directly with annotations (because they are generated by protoc) and I am looking for a way to enrich the model types with nullable hints.
I see that there is a io.swagger.jaxrs.config.ReaderListener I can use to change the swagger document but I am not sure where I could register it and how to add the extension values on Option type. If you give me some direction, I could create a PR for this if code changes are needed.
Thank you for your help in advance.
The text was updated successfully, but these errors were encountered: