paperclip
paperclip copied to clipboard
Implement actix schema generator for tagged enums
Resolves #97.
About
This pr implements schema generation for complex enums with serde's tag system.
Supported are all types of tagging (see here), except for the enum tuples. Tuple schema generation is currently not implemented correctly anyway, so that should go into another pr.
This pr currently uses anyOf instead of oneOf to cover some possible edge cases, where serde would just use the first variant that matches (especially visible in untagged enums).
To be able to implement this, this pr adds any_of and const to the internal schema representation.
Up for discussion
- Usage of
anyOfvs.oneOfas described above. - Currently the old enum system is kept for enums that use the default tagging (
external) and that only have unit variants. This makes it effectively impossible to add descriptions for the enum variants. Possible workarounds:- Check for documentation on each variant and if present, go for the new
any_ofsystem. - Get rid of the old
enumsystem and just useany_offor everything.
- Check for documentation on each variant and if present, go for the new
Other notes
- The files that I worked on in this pr were incredibly huge, making editing more painful than it needs to be.
- Let me know if there's any more documentation needed :)
Hey @Siphalor, please correct me if I'm wrong, but anyOf is not part of openapi version 2?
Sadly you seem to be right.
It seems like I was over-enthusiastic and got lost in the JSON Schema spec without noticing that OpenAPIv2 doesn't support the latest draft.
Well, maybe this is at least useful as a reference for the v3 implementation then :)
Yes this is not all for naught, it is very useful indeed because we want to eventually output proper openapi v3. I added the initial dumb v2-v3 conversion but sadly for lack of time did not get to the next step.
If you were so inclined, how about adding a new ApiV3Schema trait (eg in core/v3/schema.rs) containing these new additions?