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

Schema default value not used #40

Closed
arkadyark opened this issue Jan 11, 2018 · 4 comments
Closed

Schema default value not used #40

arkadyark opened this issue Jan 11, 2018 · 4 comments
Assignees
Milestone

Comments

@arkadyark
Copy link

arkadyark commented Jan 11, 2018

Trying to set a default value for a Schema inside of a Parameter. It does not seem to be getting picked up in Swagger when I use the "Try it out" functionality.

My schema looks like this:

    @swagger_auto_schema(
            operation_id="Get a mission plan",
            responses={
                200: 'test'},
            manual_parameters=[
                openapi.Parameter(
                    name='Organization',
                    in_=openapi.IN_HEADER,
                    description="Organization name",
                    required=True,
                    schema=openapi.Schema(
                        type=openapi.TYPE_STRING,
                        default="Organization 1",
                    )
                )
            ]
        )

Perhaps providing a more in depth example in testproj, that uses more of the OpenApi parameters, would be helpful. From what I read here it seems the example field should be used rather than default, but it does not seem to be an available field in the Schema class?

@arkadyark
Copy link
Author

Actually, looking a bit more, it seems like putting an example parameter value for a header is not supported in OpenAPI v2 (see this thread). Then I'm eagerly awaiting this issue to be resolved!

@axnsan12
Copy link
Owner

Hello,

Your example is wrong because in OpenAPI 2.0, parameters can only have a schema attribute if they are in: body. Your header parameter can only have a plain type, and an optional format, pattern, enum, etc - see Parameter Object in the OpenAPI 2.0 specification.

With that said, default is a valid attribute for Parameter, so you can just move it out of the schema and it will work.

@axnsan12
Copy link
Owner

A quick read over this could maybe clear up a bit more stuff.

Will also look into adding more assertions against using wrong combinations of attributes like this.

@axnsan12 axnsan12 reopened this Jan 11, 2018
@axnsan12
Copy link
Owner

Related to the OpenAPI 3 issue - as stated in its text, it won't likely be resolved in the near future (few months at least), since most 3rd party tools have no support for the interesting new features or even the 3.0 spec itself.

@axnsan12 axnsan12 added this to the 1.2.0 milestone Jan 11, 2018
@axnsan12 axnsan12 self-assigned this Jan 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants