Swagger — JSON documentation on a simple calculator API

--

To start we will need a simple calculator api to then document.

To keep it simple here is how your folder structure needs to look like.

Visual Studio Code Folder Structure

Then we will add the following packages with npm.

npm i -s swagger-ui-express express

Now our main.js (index.js) code:

routes.js:

controller.js:

Now lets tackle the swaggerdoc.json in parts.

1st we need to give the project a description:

2nd, in order to not repeat ourselves in each endpoint with what could be a lot, we create a schema component.

3rd we can now start making the endpoints actual documentation.

This is the example for the sum its easy to get the rest from here.

Here is the whole swaggerdoc if you for some reason feel like you need it.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response