-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Nullable enum ? #165
Comments
Found a workaround to get it working :
The empty string But it kind of break the swagger-ui and documentation by adding two possibles values just for the "nullable" validation thing to be working. |
Cool. I appreciate the write-up and the example. It's super helpful. Based on your feedback, it seems their issue is an issue in the request validator's query param handler. I'm sure, with a small fix, we can get this working with In any case, I'm glad you found a workaround in the near term. |
@ctiaffay-conserto i believe this will be (at least partially) resolved by #190. once merged, you should be able to set keeping open as the response side must be addressed |
Hello all, I am trying to get the following to work correctly, but unfortunately I receive an error during response validation when the value is Thistype:
type: string
nullable: true
enum:
- ADHOC
- SCHEDULE
- ANONYMOUS
- KIOSK Causes ThisInternal Server Error: /response/type must be equal to one of the allowed values: ADHOC, SCHEDULE, ANONYMOUS, KIOSK
at ResponseValidator._validate (/my-repo/node_modules/express-openapi-validator/src/middlewares/openapi.response.validator.ts:201:13)
at /my-repo/node_modules/express-openapi-validator/src/middlewares/openapi.response.validator.ts:73:23
at ServerResponse.json_hook (/my-repo/node_modules/express-openapi-validator/src/framework/modded.express.mung.ts:39:16)
at ServerResponse.json_hook (/my-repo/node_modules/express-mung/index.js:56:29)
Errors: [
{
path: '/response/type',
message: 'must be equal to one of the allowed values: ADHOC, SCHEDULE, ANONYMOUS, KIOSK',
errorCode: 'enum.openapi.validation'
}
] "Workaround"The only thing I have tried that did not cause an error is the following, but it unfortunately also considers an empty object as valid as well... Notes
type:
oneOf:
- type: object
nullable: true
additionalProperties: false
- type: string
enum:
- ADHOC
- SCHEDULE
- ANONYMOUS
- KIOSK @cdimascio do you have any suggestions for a schema that would work with the code base today and only allow the enum strings or If not, what needs to be addressed in this library to resolve this? Thanks in advance for your help and in general your contributions to this library! Cheers, |
We're still running into this as well. However, reading through the OpenAPI specification, it seems as though this is actually expected behaviour. The Therefore, the validator performs according to the OpenAPI specification and I don't think this actually a bug with the validator. Perhaps something can be done about the generated schema for enums, but that should be addressed in nestjs/swagger instead |
@Tlepel So are you saying I need to add If so, that doesn't feel quite right. The list of enum values in the example I gave are all string values (I think), so I'm not sure how I can add |
@Jackman3005 yes, that's right. I agree that it doesn't feel right, but according to the clarification that's how it should be specified. However, I did some digging and found some more information for OAS 3.1, take a look at this issue: OAI/OpenAPI-Specification#3148 Here a different solution is proposed, which could be what you're looking for:
|
@Tlepel I tried something similar to what you suggested as my enum was actually a type:
oneOf:
- type: "null"
- $ref: "schemas.yaml#/QuestType" This required me to drop However, after getting that far I found out that
Despite the rather verbose output, I'm guessing the first error is the real error, in that Unfortunately, this still seems to be hung up on AJV support for 3.1 which from what I can tell is only blocked by this one issue which has a $500 bounty on it if anyone is interested to tackle that... |
Hi there
I have to filter a list of entities on a field which is based on a nullable enum :
http://localhost/list?limit=10&filter=val_1
I need to be able to get :
http://localhost/list?limit=10
http://localhost/list?limit=10&filter=enum_val1
http://localhost/list?limit=10&filter=
The part where I declare and use my enum field :
The third is the one (only entities with NO enum value) I can't figure out. The validation middleware keep telling me :
Thanks for the help
The text was updated successfully, but these errors were encountered: