-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import swaggerJsDoc from 'swagger-jsdoc'; | ||
import swaggerUi from 'swagger-ui-express'; | ||
import './env'; | ||
|
||
const swaggerDefinition = { | ||
openapi: '3.0.1', | ||
info: { | ||
title: 'Barefoot Nomad API documentation', | ||
version: '1.0.0', | ||
description: 'Barefoot Nomad auto generated swagger documentation', | ||
contact: { | ||
email: 'kolaakindoju@gmail.com' | ||
} | ||
}, | ||
servers: [ | ||
{ | ||
url: process.env.DOC_BASE_URL || 'http://localhost:3000' | ||
} | ||
], | ||
components: { | ||
securitySchemes: { | ||
bearerAuth: { | ||
type: 'http', | ||
scheme: 'bearer', | ||
bearerFormat: 'JWT' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const options = { | ||
swaggerDefinition, | ||
apis: ['src/routes/*.js'], | ||
}; | ||
|
||
|
||
const specs = swaggerJsDoc(options); | ||
|
||
module.exports = (router) => { | ||
router.get('/docs', swaggerUi.setup(specs)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import messages from '../utils/messages'; | ||
import response from '../utils/response'; | ||
|
||
const routes = (router) => { | ||
router | ||
.route('/') | ||
/** | ||
* @swagger | ||
* /api/v1: | ||
* get: | ||
* tags: | ||
* - name: Welcome Message Endpoint | ||
* summary: Welcome message endpoint | ||
* description: Endpoint returns welcome message | ||
* responses: | ||
* 200: | ||
* description: Successful operation | ||
* content: | ||
* application/json: | ||
* schema: | ||
* $ref: '#/components/schemas/welcomeResponse' | ||
* components: | ||
* schemas: | ||
* welcomeResponse: | ||
* type: object | ||
* properties: | ||
* status: | ||
* type: string | ||
* data: | ||
* type: object | ||
* properties: | ||
* message: | ||
* type: string | ||
*/ | ||
.get((req, res) => response(res, 200, 'success', { | ||
message: messages.apiV1Welcome, | ||
})); | ||
}; | ||
|
||
export default routes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { | ||
app, messages, chai, expect | ||
} from '../testHelpers/config'; | ||
|
||
describe('Index route', () => { | ||
it('should return 200 if successful', async () => { | ||
const response = await chai.request(app).get('/api/v1'); | ||
expect(response.status).to.equal(200); | ||
expect(response.body.data.message).to.equal(messages.apiV1Welcome); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters