Skip to content
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

[python-experimental] models + endpoints, replace allowed_values with enums #7058

Closed
spacether opened this issue Jul 27, 2020 · 7 comments
Closed

Comments

@spacether
Copy link
Contributor

spacether commented Jul 27, 2020

Include python Enums when the schema defines an enum

This applies to:

  • endpoints
    • inline enum
    • $ref enum
  • enums in object type models
    • inline enum
    • $ref enum
  • models of type enum (ModelSimple models)
@cgfarmer4
Copy link
Contributor

@spacether Any movement here? Accessing enums should be as simple as Type.VALUE but I can't seem to get this to work.

@spacether
Copy link
Contributor Author

spacether commented Jan 7, 2021

No progress here yet in the python-generator or the python-legacy generator.

This is difficult to implement because:

  • Enums can be combined in composed schemas
  • Composed schemas can contain any type: oneOf: - null, -int -StrEnum
  • Enums can be mixed types (nullable string)

Inline Enum definitiona also means that:

  • our mustache templates must be recursive
  • all our java classes that represent Schema (CodegenModel, CodegenProperty, CodegenResponse, CodegenParameter) must implement all the common schema properties to store the data that the enums use rather than just using a model $ref

I am slowly making progress on this at #8325
If you look in that branch at StringEnum my code there allows
Type.OPTION
In that branch I am working to get that working on the java classes CodegenModel, CodegenProperty and probably CodegenResponse and CodegenParameter.

@cgfarmer4
Copy link
Contributor

Thanks for the quick reply @spacether. So what is the proper way to access them currently?

The model serialization fails if they aren't passed as Type('stringvalue') however this emits incorrect values in the JSON.

I get {value: 'stringvalue'} when I would expect it to be 'stringvalue'

@spacether
Copy link
Contributor Author

The way to access them now is through allowed_values.

@spacether
Copy link
Contributor Author

spacether commented Jan 8, 2021

If there is a bug can you open up a separate issue with a reproducible example?
If your enum is a primitive value (ModelSimple base class in python) then it should be serialized as that primitive value.

@cgfarmer4
Copy link
Contributor

Thanks @spacether. Filed #8377

@spacether
Copy link
Contributor Author

Closing this because python-experimental implements a singleton class which stores enum options and it will be merged soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants