Add basic support for parsing enums to integer or string values.#8
Open
saleweaver wants to merge 1 commit intoGabrielCappelli:masterfrom
Open
Add basic support for parsing enums to integer or string values.#8saleweaver wants to merge 1 commit intoGabrielCappelli:masterfrom
saleweaver wants to merge 1 commit intoGabrielCappelli:masterfrom
Conversation
Owner
|
Hi, thanks for your contribution. I'm having a look at the openapi docs for enums and it seems we may go a bit further and also specify all possible values for this enum. This will give a nice dropdown in Swagger to pick the valid values for the Enum: As far as implementation goes. I would take a slightly different approach, where we use def resolve_enum(openapi_schema_resolver: "OpenApiSchemaResolver", data_type: type):
if not isinstance(data_type, enum.EnumMeta):
return
openapi_schema = openapi_schema_resolver.get_schema(data_type.__base__)
openapi_schema["enum"] = [member.value for member in data_type]
return openapi_schema |
Author
|
Hi, yes - makes sense. Do you want me to add something? |
Comment on lines
+101
to
+107
| def resolve_enum(openapi_schema_resolver: "OpenApiSchemaResolver", data_type: type): | ||
| if not isinstance(data_type, enum.EnumMeta): | ||
| return | ||
|
|
||
| openapi_type = OPENAPI_TYPE_MAP.get(data_type.__base__) | ||
|
|
||
| return {"type": openapi_type} |
Owner
There was a problem hiding this comment.
Suggested change
| def resolve_enum(openapi_schema_resolver: "OpenApiSchemaResolver", data_type: type): | |
| if not isinstance(data_type, enum.EnumMeta): | |
| return | |
| openapi_type = OPENAPI_TYPE_MAP.get(data_type.__base__) | |
| return {"type": openapi_type} | |
| def resolve_enum(openapi_schema_resolver: "OpenApiSchemaResolver", data_type: type): | |
| if not isinstance(data_type, enum.EnumMeta): | |
| return | |
| openapi_schema = openapi_schema_resolver.get_schema(data_type.__base__) | |
| openapi_schema["enum"] = [member.value for member in data_type] | |
| return openapi_schema |
if you can apply these changes I'll merge, test and release
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Hey,
I've been trying to add basic support for parsing enums as string or integer values and added tests. All pass. :-)
Happy to change things if needed.