-
Hi, I'm just digging into openapi-python-client and trying to use it to generate client code to interact with a Spring-boot based service. Since the Spring-boot project uses openapi and has a spec file, I was able to quickly generate the client code, and after a bit of trial-and-error actually get a response from the service (so, very cool!). However, when I make the API call using the generated client code, the content is returned as a string. Since the service returns JSON, it seems a little cumbersome to have to do this all the time:
Am I better off modifying the So what's the best approach here? Modifying the generated client code? Or wrapping that code and making modifications to the return values in the wrapping class ? Thanks!Paul |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If the return type is properly documented in the OpenAPI spec for the API, then there should be a If the response type is not documented in the OpenAPI spec, then |
Beta Was this translation helpful? Give feedback.
If the return type is properly documented in the OpenAPI spec for the API, then there should be a
Response.parsed
field with the data deserialized already. You can also access this faster by calling thesync()
method in the API module instead ofsync_detailed()
(if you don't need anything else on theResponse
object).If the response type is not documented in the OpenAPI spec, then
openapi-python-client
has no way of knowing how to deserialize it, so you'll have to do it yourself. Your best bet might be to add a preprocessor to modify theopenapi.yml
before running the generator to insert the appropriate OpenAPI types.