Documenting met Swagger en Testing met JEST
Installeer swagger-ui-express
npm install swagger-ui-express
Installeer JEST
npm install jest
import swaggerDefinition from './docs/swagger.js';
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDefinition));
Documenting met Swagger en Testing met JEST
Swagger allows you to describe the structure of your APIs so that machines can read them. Swagger does this by asking your API to return a YAML or JSON that contains a detailed description of your entire API. This file is essentially a resource listing of your API which adheres to OpenAPI Specification.
export default {
openapi: "3.0.0",
info: {},
servers: [],
tags: [],
paths: {},
components: {}
}
export default {
openapi: "3.0.0",
info: {},
servers: [],
tags: [],
paths: {},
components: {}
}
import schemas from "./schemas.js";
components: {
schemas,
}
export default {
"User": {
properties: {
id: { type: "number" },
firstname: { type: "string" },
lastname: { type: "string" },
}
}
)
export default {
[...],
"UserMeta": {
properties: {
id: { type: "number" },
address: { type: "string" },
zipCode: { type: "string" },
city: { type: "string" }
}
},
)
export default {
"User": {
properties: {
id: { type: "number" },
firstname: { type: "string" },
lastname: { type: "string" },
user_meta: {
$ref: '#/components/schemas/UserMeta'
},
}
},
[...],
)