Comments (5)
Yes ! this resolves my problem.
On the other hand, you might want to check why specifying enum
with properties leads to weird results. I would have expected a consistent behavior or an error.
Feel free to leave this bug open to track this issue or to close it.
Thanks for the help ! :-)
All the best
from express-openapi-validator.
i'm a bit confused by what you are trying to express.
It seems you have an enum of type object with values of a different type (string). im not sure think itβs correct . Also it has a property foo where that key is the enum value. Also a bit puzzling.
EnumBody:
required: true
content:
application/json:
schema:
type: object
enum: # <-- hmm
- foo
required:
- foo
properties:
foo:
type: string
Perhaps you want something like the following:
an object with property foo which is an enum of type string with acceptable values bar and baz
EnumBody:
required: true
content:
application/json:
schema:
type: object
required:
- foo
properties:
foo:
type: string
enum:
- bar
- baz
Can you describe what you are trying to express, perhaps I can help
from express-openapi-validator.
@cdimascio We want to validate that the body contains an object with only allowed keys. In this case, I've boiled down the issue to only one property.
In other word, I want the validation to allow a body containing { foo: "bar" }
and fail a body containing {foo: "baz", bogus: "baz"}
.
The second example should fail because bogus
is not in the list of allowed keys (as specified in the enum
).
Sorry for not being clear in my original request.
from express-openapi-validator.
No problem. Have you tried additionalProperties: false.
See example here:
The spec:
https://github.com/cdimascio/express-openapi-validator/blob/master/test/resources/additional.properties.yaml#L52
The test:
https://github.com/cdimascio/express-openapi-validator/blob/master/test/additional.props.spec.ts#L37
This test ensures that only explicit props are allowed. In this case, name (required) and tags (optional). Any other property will result in a validation error.
from express-openapi-validator.
Woop! Excellent news! I'm glad it worked out.
The validator is properly handling the enum cases. There are examples of them working in the tests. I'm fairly certain that the specification you provided above is not behaviorally valid, despite it passing validation. Enums describe values and not keys. The OpenAPI spec allows one to define an enum property as a type object, however, the value should also be an object.
I'll keep this open while I validate this is indeed the case.
from express-openapi-validator.
Related Issues (20)
- Request Body content-types don't consider custom parameters
- How to specify middleware handler for single endpoint HOT 1
- multipartMiddleware preceeds securityMiddleware so files begin uploading before security check HOT 3
- Security handlers cannot access request params
- The validation doesn't work at all HOT 2
- Question: should serdes.serialize be called when validateResponse=false
- Serdes Does Not Work for Items in Request Parameters in Array HOT 1
- HTTP HEAD not implemented for HTTP GET similar to ExpressJS v4.
- Multer worked on 5.0.1 throws internal server error in 5.1.0 HOT 5
- Introduction of multiple swagger docs with new endpoint now versioned returns 404 HOT 2
- the same oneOf schema can pass request validation. But cannot pass response validation
- version 5.1.1, apiKey cookie authentication results in error HOT 1
- Email format validation does not accept non-ascii characters
- Multiple spec support breaks if validateResponses: true HOT 2
- readonly is ignored when properties are inherited through allOf
- Type coercion stops working if request validation is turned off HOT 1
- Support for the HyperExpress web framework HOT 1
- Multiple path params break support for URI path param HOT 1
- Upgrade or replace lodash
- Server variables without enum don't get validated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-openapi-validator.