Comments (7)
@tafm You can now get the desired behavior by setting coerceTypes: false
. This will ensure that null
values are not coerced to the default value of type
specified in the spec. e.g. type: string
would coerce a null
to ''
v1.8.0 allows you to set coerceTypes to false
from express-openapi-validator.
@sheldhur do you know whether its possible to turn off defaults for required parameters only via Ajv. I beleive doing so will be one way to solve this problem
such a solution also aligns with avoiding Common Mistakes (as described in the OpenAPI spec)
Common Mistakes
There are two common mistakes when using the default keyword:
Using default with required parameters or properties, for example, with path parameters. This does not make sense – if a value is required, the client must always send it, and the default value is never used.
from express-openapi-validator.
@tafm thanks for the heads up on coerceTypes. i'll release an update of 1.8 to include the change.
i'll also investigate openapi-schema-to-json-schema.
all in all, please let me know what we can do to make this work for you.
you're interest and feedback is much appreciated. thanks!
from express-openapi-validator.
changing this from bug to enhancement as it hasn't been implemented yet.
from express-openapi-validator.
@tafm I've started some work in this area
please see #46 for details
this sets the foundation to solve the issue you described.
ultimately, it makes express-openapi-validator aware of the nullable
property. essentially, if nullable: true
it will allow the null value to pass through. if nullable: false
or nullable is not provided, it will convert the value to its default
value (as it does today). in the case of string, if a default value is not provided it is empty string.
from express-openapi-validator.
@cdimascio hi. You can change keyword behavior.
https://ajv.js.org/custom.html
from express-openapi-validator.
@cdimascio thank you very much, this is exactly i need to enable in production. Im still unnable to use now, but not really for a "lack" of feature but some incompatibility between json schemas and open api (setting coerceTypes to false makes ajv invalidate: "not of type string"). I had a look at the code and how to fix, one way its using the library openapi-schema-to-json-schema
const toJSONschema = require('openapi-schema-to-json-schema')
then replace const validator = this.ajv.compile(schema);
to const validator = this.ajv.compile(toJSONschema(schema));
this converts types with nullable: true
for a array of types [oldType, null]
. Strangelly i think a better idea would be replace to anyOf, but works.
Another little issue its that coerceTypes
is hardcoded to true at the npm repository / js files, the .ts files are right on github.
from express-openapi-validator.
Related Issues (20)
- 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
- Multiple specs are not supported HOT 1
- Found CVE-2021-23337 in latest version of express-openapi-validator HOT 1
- Request body is marked as invalid, using `oneOf` inside `allOf`
- Request body schema validations are skipped when using multiple external refs
- Subsequent express middleware not invoked after OpenApiValidator HOT 3
- Use Precompiled Validator?
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.