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

Default value for parameters aren't working in OpenAPI v3 #2227

Closed
Place1 opened this issue Jun 11, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@Place1
Copy link
Contributor

commented Jun 11, 2019

Currently the swaggerToCSharpController doesn't correctly generate default values for parameters. I've been debugging NSwag locally and while i've struggled to find the root cause i've noticed a few things that might be relevant:

I've included an example spec below.

openapi: 3.0.0

info:
  title: My API
  version: 0.0.0

paths:
  /Api/Endpoint/:
    get:
      tags:
        - Endpoint
      summary: list resource
      operationId: example
      parameters:
        - name: page
          in: query
          schema:
            type: integer
            format: int32
            default: 10
@RicoSuter

This comment has been minimized.

Copy link
Owner

commented Jun 11, 2019

For OpenAPI 3 it's _parameter.ActualSchema.Default - for Swagger 2 it's _parameter.Default...

Maybe we should add new property to OpenApiParameter and use that:

ActualDefault => _parameter.Default ?? _parameter.ActualSchema?.Default;

And use that everywhere we generate something...

@Place1

This comment has been minimized.

Copy link
Contributor Author

commented Jun 11, 2019

@RicoSuter that sounds like a good idea to me :D would you like me to submit a PR? or are you happy to do it for me 😅

@RicoSuter

This comment has been minimized.

Copy link
Owner

commented Jun 12, 2019

Maybe we should always use _parameter.ActualSchema.Default? Or will this break swagger 2?

@RicoSuter RicoSuter closed this in a6b1915 Jun 12, 2019

@RicoSuter

This comment has been minimized.

Copy link
Owner

commented Jun 12, 2019

Is this ok? We should also add tests.

@RicoSuter

This comment has been minimized.

Copy link
Owner

commented Jun 13, 2019

v13.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.