-
Notifications
You must be signed in to change notification settings - Fork 5
better response type handling #68
Comments
In the Spring module this is also annoying since even if you put
it will generate Could you give me some hints on how you would implement it? I'm willing to write an implementation. Reference: https://docs.openapiprocessor.io/spring/2021.3/mapping/result.html |
Yes, I think that has the same cause. Thanks for the offer to help -) Here are a few notes to get you started. I did a few lines on this to get the new option but that's just a minimal start that does not yet do anything. It is on this branch: https://github.com/openapi-processor/openapi-processor-core/tree/response-type-handling Current idea is to replace the return type of the controller method in the openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/writer/java/MethodWriter.kt Line 47 in e25f7ab
This is the line that adds the response type to the method. Replacing The code to get the wanted type exists and is currently private in the openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/model/EndpointResponse.kt Line 37 in e25f7ab
Note that the identical selection is required to create the import list. Getting that option is probably the harder part. Converting the If the options is configured like this # mapping.yaml
openapi-processor-mapping: v2
map:
response-type: all # all (default) or success the openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/converter/mapping/MappingFinder.kt Line 122 in e25f7ab
The The new option will need a new implementation of the Mapping interface: https://github.com/openapi-processor/openapi-processor-core/blob/response-type-handling/src/main/kotlin/io/openapiprocessor/core/converter/mapping/Mapping.kt Converting the yaml to the I hope this helps and i didn't miss any annoying detail that breaks this approach :) |
collecting the import happens here openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/writer/java/InterfaceWriter.kt Line 65 in e25f7ab
|
@JonasGroeger Hi, I have it nearly running.... I hope you didn't waste to much on on it. |
Please don't feel obligated to implement something just because somebody wants it. It's open source after all. In case you didnt: all good ;) |
It something I like to see myself :-) A colleague mentioned it and then your comment on the issue. Funny is, that it all happend in a couple of days. ;-) |
If an api has multiple response content types (success & errors) the java response type of the controller method will be
Object
to allow return values with different java types.If the errors are handled by throwing an exception there is no need to have an
Object
response and the controller method could use the type of the success response to improve readability of the interface.mapping could be like this, using a globally applied option:
or like this, allowing endpoint & endpoint/method configuration:
all
: consider all response types to select the method return typesuccess
: consider only the success response type, i.e. usually 200The text was updated successfully, but these errors were encountered: