features explanation
Hi
I am just looking into list of available features of swaggerize-express and do not understand ( or simply can not find implementation bits of) API schema validation and Input validation. Regarding Input validation i would expect that appropriate handler method would simple check if body conforms to definitions. Unfortunately https://raw.githubusercontent.com/wordnik/swagger-spec/master/examples/v2.0/json/petstore.json only has GET method so i didn't manage to check my assumptions. Can you explain what you meant exactly by API schema validation and Input validation?
BTW I tried use generator against http://petstore.swagger.io/v2/swagger.json or https://raw.githubusercontent.com/swagger-api/swagger-spec/master/examples/v2.0/json/petstore-expanded.json but unfortuantely generator always throws an exception: undefined:10 _.forEach(Object.keys(properties), function (prop) {; ^ ReferenceError: properties is not defined
The reason you are having an error is because the model you are referencing likely does not exist / path is wrong (although it shouldn't error here, it should simply warn and skip).
Regarding validation, yes - input validation is supported out of the box for body as well as parameters. You can look at the test fixtures in this module to see examples of the definitions.
Hi
Thx a lot. The json from test fixtures worked nicely so i can finally see that if i POST to /pet with body that does not conform to JSON schema i got a nice validation errors. In project README you pointed out that swaggerize-express supports both API schema validation and Input Validation. What is the difference ? By Input Validation do you mean checking that request body itself is a well-formed JSON (is valid according to JSON standard) and API schema validation means checking if input JSON is valid according to JSON schema ? Am i right ? What is API documentation route ? I haven't seen any reference to swagger UI in the project so by "API documentation route" do you mean simply returning a "pure" JSON document accessible at host:port<basePath>/api-docs, the same as the one used during project generation via yo ? Or you are building some fancy documentation page ?
BTW: when i run npm test all 11 tests are failing - all assertions are failing. It is obviously in conflict with Travis build status so maybe i need to run these tests in a different way ?
When it says "schema validation" it means validating your api document against the swagger schema.
API documentation route returns the JSON document which swagger-ui uses to build its UI from.
As far as failing build, what Node version are you on?
Closing due to inactivity.
Is there validation for paths? I want to have my tests reside in the same directory as my handlers so that I can have /user/info.js and /user/info.test.js without swaggerize treating the test file as a file that exports http requests. Is there a way to get swagger to ignore these files with a glob in schema maybe?
Hello,
In my examples it seems that schema validation does not go down to the swagger custom "definitions" level. Is this correct? For example in the pets swagger used in the tests (https://github.com/krakenjs/swaggerize-express/blob/master/test/fixtures/defs/pets.json) does swaggerize-express validate the Pet definition restrictions (i.e. "required": ["id", "name"])? The unit tests (https://github.com/krakenjs/swaggerize-express/blob/master/test/test-swaggerize.js) do not check the scenario of a required property of a definition is missing (e.g. Pet does not have a name or id).
If this is the case, what is the best way to do introduce this kind of validation?
Many Thanks!
@vspiliop may I suggest express-openapi as an alternative? It is 100% based on jsonschema (unlike swaggerize-express) which would support the type of validations you're referring to.