-
Notifications
You must be signed in to change notification settings - Fork 483
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
feat(spec): allow additional fields on enum refs #2816
Conversation
}; | ||
} | ||
// Allow given fields to be part of the referenced enum schema | ||
const additionalParams = ['description', 'deprecated', 'default'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not sure if we should just allow all fields, so I added an allowlist here. I did not find any information in the swagger spec on what they technically support on an enum ref field.
LGTM |
Is there any reason to assume metadata of ApiProperty as enum's metadata? I have problem by this pr. I declared dto as below. enum TestEnum {
A = "A",
B = "B"
}
class EnumTest {
@ApiProperty({
enum: TestEnum,
enumName: 'TestEnum',
isArray: true,
default: [],
})
readonly testEnum: TestEnum[] = [];
} A class called EnumTest has a property called testEnum, which expects TestEnum to enter the form of an array. components:
schemas:
TestEnum:
type: string
enum:
- A
- B
# .....
EnumTest
type: object
properties:
testEnum:
type: array
default: []
items:
$ref: "#/components/schemas/TestEnum" But I got the yaml as below. components:
schemas:
TestEnum:
type: string
default: [] # It cause error on openAPI specification.
enum:
- A
- B
# .....
EnumTest
type: object
properties:
testEnum:
type: array
items:
$ref: "#/components/schemas/TestEnum" I know that |
In my opinion, if you want to field description and default for enum, it looks good to create another field that is isolated from property. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
If there is an
enumName
supplied, all the additionalFields are currently just added as a ref-sibling. This is not swagger-spec compliant and therefore gets ignored.Does this PR introduce a breaking change?
Other information
See this issue for more information: #2806