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

@ApiProperty - Include default value when using enumName #2898

Open
1 task done
Eirmas opened this issue Mar 29, 2024 · 2 comments
Open
1 task done

@ApiProperty - Include default value when using enumName #2898

Eirmas opened this issue Mar 29, 2024 · 2 comments
Labels

Comments

@Eirmas
Copy link

Eirmas commented Mar 29, 2024

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

When using @ApiProperty like this:

@ApiProperty({ enum: SortOrder, default: SortOrder.DESC })

It renders the OpenAPI json like this:

{
    "name": "order",
    "required": true,
    "in": "query",
    "schema": {
        "default": "DESC",
        "enum": [
            "DESC",
            "ASC"
    ],
    "type": "string"
    }
}

However, when adding a reference to the enum using enumName instead to avoid duplicate definitions like this:

@ApiProperty({ enum: SortOrder, default: SortOrder.DESC, enumName: 'SortOrder' })

It renders like this:

{
    "name": "order",
    "required": true,
    "in": "query",
    "schema": {
        "$ref": "#/components/schemas/SortOrder"
    }
}

Here we can see that the default property is lost.

Describe the solution you'd like

Here is a discussion that explains a possible solution: OAI/OpenAPI-Specification#2948

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

Improve user experience when using software like Postman, Swagger or similar

@Eirmas Eirmas added the feature label Mar 29, 2024
@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@kimdj2
Copy link
Contributor

kimdj2 commented Mar 31, 2024

スクリーンショット 2024-03-31 11 48 09
ref: https://swagger.io/docs/specification/using-ref/

In v3.1.0, it appears that you can define some sibling elements, but it still don't have default property.
ref: https://spec.openapis.org/oas/v3.1.0#reference-object

OAI/OpenAPI-Specification#2948
In my opinion, the example in this page is no different than the code below.

@ApiProperty({ 
  default: SortOrder.DESC,
  allOf: [
    { $ref: getSchemaPath('SortOrder') },
  ]
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants