![]() ![]() ![]() When combined with comprehensive integration tests you assert the correctness of your server. ![]() The swagger-express-validator validates the inputs and outputs of your API route controllers against their Swagger definitions. There’s one path, GET /ping, that returns a JSON response: Other tools swagger: "2.0" info: description: Something about the API version: "1.0.0" title: My Cool API basePath: "/api/v1" schemes: - "https" paths: /ping: get: tags: - "root" summary: "Get Server Information" operationId: "ping" produces: - "application/json" responses: 200: description: "success" schema: $ref: "#/definitions/ServerInfo" definitions: ServerInfo: type: "object" properties: name: type: "string" description: type: "string" version: type: "string" uptime: type: "number" The following is a simple API defined with Swagger in a file my-api.yml, placed at the root of the project. To make this easy I have written a small package called swagger-routes-express (updated recently to support OpenAPI 3 in addition to Swagger 2). To avoid repetition it’s desirable to also use the Swagger definition of your API to tell Express how to map incoming paths to route controller functions. Wiring up an API server with Express and SwaggerĮxpressJS is the go-to framework for writing API servers with NodeJS, and Swagger is a brilliant way to specify the details of your API in a way that allows you to ensure the API is consistent, documented, and testable, using a range of handy tools. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |