Generate OpenAPI response schema (application/json) for function return types - #257
Generate OpenAPI response schema (application/json) for function return types#257bduncanj wants to merge 43 commits into
Conversation
…ield type (instead of throwing error)
|
Internally we use the |
|
Thanks @ndortega. Perhaps a safe next step might be manually encode the logic found in the automatic dispatch of The exception (for now) would be responses generated with It is then consumed by an additional I'd like your thoughts on this before putting more time into it. |
|
Hi @bduncanj, Yeah, I think your approach does make sense, the only way to track those types would be to return some wrapper type to hold that information. Now as far as using that information to generate types, I'm not seeing you pass the underlying content_type - but I assume you're just holding off until I responded. One approach I'd recommend: Let me know what you think of my suggestion |
|
@ndortega thanks for the feedback. A pattern which achieves this with the least boilerplate would be something like this in which In the branch above ( Happy to continue in this direction if the above sounds good. LMK if you'd like me to extend work to Protobuf extension or leave that returning a |
|
@bduncanj I'm a big fan of using type parameters to help simplify code, so that approach sounds good to me. But there is one constraint: consistent api - whatever pattern we go with should alos be used in our package extensions. So to answer your question, I'd like these changes to also extend to the protobuf extension |
|
I use a method of modifying templates and creating macros to obtain the return type, and it works. I think the return type should be obtainable from the macro. https://github.com/Juliaoscode/JuliaOS/pull/84
|



This builds on PR 255
Understand there may be some discussion around architecture, and this rather selfishly caters to my use case, in which I'm building a REST API and so know all object responses will be of type
application/json.For functions which return a type that can be inferred, this generates an
application/jsoncontent type in the OpenAPI200response payload.json()render function (as this converts type to string first).application/jsonreturn type. (1)(1) I'd like to find the code that decides how to serialize the response from a HTTP handler and use that to infer the content type of the response schema.
Other:
JSON3.write()- this fixes default values for structs.Realfields mapped tonumberin OpenAPIDictfields no longer throw an error (from my notes, need to confirm this was actually an issue)