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

Enums don't support default values in controllers' arguments #6

Open
pristupa opened this issue Jan 29, 2019 · 3 comments
Open

Enums don't support default values in controllers' arguments #6

pristupa opened this issue Jan 29, 2019 · 3 comments
Labels
bug Something isn't working

Comments

@pristupa
Copy link
Collaborator

Using drf-yasg 1.13 doesn't seem to help

@mofr mofr added the bug Something isn't working label Jan 29, 2019
@mofr mofr closed this as completed in 15f3aa8 Jan 30, 2019
@pristupa
Copy link
Collaborator Author

Oops, probably wrong commit message closed the wrong issue

@mofr mofr reopened this Jan 30, 2019
@mofr
Copy link
Collaborator

mofr commented Feb 7, 2019

The fix needs a pull request to drf-yasg which makes drf-yasg to use JSONRenderer specified in django settings instead of direct json.dumps and drf.JSONRenderer calls.

@teamush
Copy link

teamush commented Sep 23, 2020

Hey, guys. Met same bug recently and decided to prepare it's description for you to assist with making problem visibility more clear.

Bug description
When the argument of a route is annotated as enum and default value is set, following exception happens on attempt to access Swagger schema: TypeError: Object of type 'SomeEnum' is not JSON serializable

To Reproduce

  1. Prepare a controller with some route_get;
  2. Add a parameter to route_get like: @route_get('/hello/{?param}');
  3. Annotate parameter with enum and set enum-based default;
from enum import Enum

import winter


class FooParam(Enum)
    FOO = 'foo'
    BAR = 'bar'
    

@winter.controller
class HelloWorldController:

    @winter.route_get('/hello/{?param}')
    def hello(self, param: FooParam1 = FooParam.FOO):
        return f'Hello, world!'
  1. Properly setup drf-yasg to a project:
    4.1. Set 'DEFAULT_AUTO_SCHEMA_CLASS': 'winter_openapi.inspectors.SwaggerAutoSchema' in SWAGGER_SETTINGS;
    4.2. Call winter_openapi.setup() somewhere in service entrypoint code;
  2. Try access Swagger schema.

Expected behavior
Default enum value is scanned normally, Swagger schema is successfully built and can be accessed.

Code snippets
Minimal code snippet is given above.

Screenshots
image

Environment:

  • OS: Docker 19.03.12
  • Python: CPython 3.6
  • Winter version: 4.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants