-
-
Notifications
You must be signed in to change notification settings - Fork 176
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
Enum by_value creates OpenAPI property without type #875
Comments
@sloria if you are able to point me in the direction of the code that defines how that |
@zedrdave thanks for volunteering! i believe the relevant method is field2type_and_format, which takes a marshmallow field and returns the corresponding OAI type and format as a dict. relevant test is here: apispec/tests/test_ext_marshmallow_field.py Line 294 in fb58570
|
A couple more details on how the type is decided: For enum fields there is enum2properties. This is indirectly calling
That's typically because apispec can't infer the type of a generic field. Not sure what the proper behavior would be in this case because I don't have any experience working with enum fields. |
@Bangertm thanks for diving into this further. I must admit I'll need a bit of time to potentially wrap my head around that But basically the behaviour we want to achieve is: |
@Bangertm OK, I think I understand better, and as best as I can tell, this is an upstream issue with Marshmallow setting field to Short of this being changed upstream, it seems like the only option would be to correct it inside |
FWIW: passing |
I don't remember the whole story, there may be retro-compatibility involved, but I think the rationale in marshmallow is that when using In any case, my advice would be to set I wouldn't expect apispec to set a string type if nothing is specified. If values are integers, for instance, documenting them as string would be wrong. |
Indeed, I'm not sure I see how adding a default type (if no
|
I understand. But I still think explicit is better than implicit. Also, I'm afraid using More history here if you're interested (I'm the author of the PRs adding Enum to marshmallow): We use |
I would argue there is already a strong implicit behaviour (people setting I would still recommend finding a way to warn users of that behaviour (if only by putting a note in Happy to close this in any case. |
Upon reading this thread more closely, I agree that explicitly passing a field to Closing for now. Thanks for the discussion all! |
If using a native Enum:
then using it in a schema:
We get the correct OpenAPI JSON:
But if we set
by_value
toTrue
, we get:The missing
"type": "string",
trips up Swagger, which does not display the enum contents…This seems potentially related to #807, but I can't see anything in the code that would lead to this difference (I can't quite figure where
type
is inferred)…The text was updated successfully, but these errors were encountered: