Comments (7)
Thanks, you're awesome. Looks like I'll be able to replace swaggerize-express lib with this one after all.
from open-api.
world.js
module.exports = {
put: function (req, res, next) {
console.log(req.body);
res.json({ok: "ok"});
}
};
main.js
const apiDoc = {
swagger: '2.0',
info: {
title: 'A getting started API.',
version: '1.0.0'
},
paths: {
"/world": {
"put": {
parameters: [
{
in: 'body',
name: 'body',
required: true,
schema: {
type: "object",
properties: {
filtered: {
description: "test",
type: "boolean"
}
},
required: ["filtered"]
}
}
],
responses: {
200: {
description: "ok",
},
default: {
description: "error",
}
}
}
}
}
};
const bodyParser = require("body-parser");
const express = require("express");
const openapi = require("express-openapi");
const http = require("http");
const app = express();
app.use(
bodyParser.json(),
bodyParser.urlencoded({ extended: false })
);
openapi.initialize({
app,
apiDoc: apiDoc,
paths: "./api-v1/paths"
});
app.listen(3200);
setTimeout(function () {
// Required property filtered is not set
const postData = JSON.stringify({test: "test"});
const options = {
hostname: "127.0.0.1",
port: 3200,
path: "/world",
method: "PUT",
headers: {
"Content-Type": "application/json",
"Content-Length": Buffer.byteLength(postData)
}
};
console.log("Making request");
const req = http.request(options, res => {
console.log("Got response from " + options.path, res.statusCode);
req.on("data", data => console.log(data));
req.on("end", data => console.log("END"));
});
req.on("error", err => console.log(err));
req.write(postData);
req.end();
}, 1000);
Got output:
Making request
{ test: 'test' }
Got response from /world 200
Expected output:
Making request
Got response from /world 400
from open-api.
The schema seems right. Have you looked at the sample projects? Here's a spec from the basic-usage
project that seems to do what you want: https://github.com/kogosoftwarellc/express-openapi/blob/master/test/sample-projects/basic-usage/spec.js#L77
from open-api.
I was breaking my head for hours as to why this doesn't work.
This unreleased change fixes the issue: 471f9a3#diff-168726dbe96b3ce427e7fedce31bb0bc
how about making a release? @jsdevel
from open-api.
@juliusza done. published @alrik 's PR as v1.5.0
from open-api.
@juliusza if the latest version works for you, would you mind closing this? Let us know if you still have problems. I see why it didn't work for you now, as defining paths
in the global apiDoc
wasn't added until @alrik 's PR. Should be good to go now.
from open-api.
You're welcome! Happy to have you! Don't hesitate to report issues here.
from open-api.
Related Issues (20)
- openapi-request-validator doesn't validate JSON objects given in headers or query params HOT 1
- Type 'string' is not assignable to type 'NonArraySchemaObjectType | undefined'. HOT 4
- [express-openapi] How to open the swagger UI web interface? HOT 1
- express-openapi: Unclear how to validate successful completion of tutorial HOT 5
- pnpm and glob issue in express-openapi
- Add application/json content type support in openapi-request-coercer
- Add support for `prefixItems` HOT 3
- SyntaxError: Invalid regular expression during path-to-regexp conversion HOT 4
- openapi-framework: fixed windows path names HOT 4
- [enhancement] openapi-response-validator: native ESM node modules default export not working as intended HOT 3
- [ft. request] openapi-response-validator - allow access to response param in errorTransformer HOT 1
- Using automatic paths with ESM HOT 2
- OpenAPI Types package, Path Item Object HOT 1
- Supertest integration tests fail after update to express-openapi 12.x.x
- parameters from Swagger 2.0 (openapi 2.0) YAML file are not caught by express-openapi HOT 2
- parameters from Swagger 2.0 (openapi 2.0) YAML file are not caught by express-openapi
- External refs not captured in parameters for request validation HOT 1
- Bug: OpenAPIResponseValidatorArgs responses object incorrectly defined
- Support for Asynchronous Custom Keywords in openapi-request-validator
- Support for validating OpenAPI 3.1
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 open-api.