-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from DVGY/feature=api/api-docs-and-tours-field
add swagger docs and open api specs
- Loading branch information
Showing
12 changed files
with
289 additions
and
12 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 @@ | ||
const basicInfo = { | ||
openapi: '3.0.3', // present supported openapi version | ||
info: { | ||
title: 'Tours.dev api', // short title. | ||
description: 'An API to book tours', // desc. | ||
version: '1.0.0', // version number | ||
contact: { | ||
name: 'Gaurav Yadav', // your name | ||
email: '[email protected]', // your email | ||
url: 'https://tours-api-prod.herokuapp.com', // your website | ||
}, | ||
}, | ||
}; | ||
|
||
export { basicInfo }; |
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,152 @@ | ||
const component = { | ||
components: { | ||
schemas: { | ||
// todo model | ||
Trips: { | ||
type: 'object', // data type | ||
properties: { | ||
id: { | ||
type: 'string', // data-type | ||
description: 'A trip id', // desc | ||
example: '6145a6c4991f41fb47f63bfe', // example of an id | ||
}, | ||
name: { | ||
type: 'string', // data-type | ||
description: 'Name of Trip', // desc | ||
example: 'The Visitor Palace', // example of a title | ||
unique: true, | ||
required: true, | ||
}, | ||
slug: { | ||
type: 'string', // data type | ||
description: 'Name of Trip, used in client trip search', // desc | ||
example: 'the visitor palace', // example of a completed value | ||
}, | ||
duration: { | ||
type: 'number', // data type | ||
description: 'Total Number of Days', // desc | ||
example: 4, // example of a completed value | ||
required: true, | ||
}, | ||
price: { | ||
type: 'number', // data type | ||
description: 'Price of Trip', // desc | ||
example: '220', // example of a completed value | ||
}, | ||
priceDiscount: { | ||
type: 'number', // data type | ||
description: 'Discount on Trip', // desc | ||
example: '10', // example of a completed value | ||
}, | ||
difficulty: { | ||
type: 'string', // data type | ||
description: 'Trip difficulty level (Easy, Medium, Hard)', // desc | ||
example: 'medium', // example of a completed value | ||
}, | ||
ratingsAverage: { | ||
type: 'number', // data type | ||
description: 'Average ratings of a Trip', // desc | ||
example: '4.4', // example of a completed value | ||
default: 4.5, | ||
}, | ||
ratingsQuantity: { | ||
type: 'number', | ||
description: 'Number of ratings of a Trip', // desc | ||
example: '50', | ||
default: 0, | ||
}, | ||
summary: { | ||
type: 'string', // data type | ||
description: 'A short summary of Trip', // desc | ||
example: 'This is best ............', // example of a completed value | ||
}, | ||
description: { | ||
type: 'string', // data type | ||
description: 'A short description of Trip', // desc | ||
example: 'The tours of the .....', // example of a completed value | ||
}, | ||
imageCover: { | ||
type: 'string', // data type | ||
description: 'A cover photo/image url of a Trip', // des | ||
example: 'https://www.myimageurl.com', | ||
}, | ||
images: { | ||
type: 'array', | ||
description: 'All images/photos url of a Trip', // des | ||
example: [ | ||
'https://www.myimageurl1.com', | ||
'https://www.myimageurl2.com', | ||
], | ||
}, | ||
createdAt: { | ||
type: 'string', | ||
description: 'Timestamp when Trip was created', // des | ||
example: 'https://www.myimageurl.com', | ||
}, | ||
guides: { | ||
$ref: '#/components/schemas/user', | ||
}, | ||
startDates: { | ||
type: 'array', | ||
description: 'Start dates of each trip location', // des | ||
example: [ | ||
'2021-06-19T09:00:00.000Z', | ||
'2021-07-20T09:00:00.000Z', | ||
'2021-08-18T09:00:00.000Z', | ||
], | ||
}, | ||
startLocation: { | ||
type: 'object', | ||
description: 'Geo JSON Point', | ||
example: { | ||
description: 'Banff, CAN', | ||
type: 'Point', | ||
coordinates: [-115.570154, 51.178456], | ||
address: '224 Banff Ave, Banff, AB, Canada', | ||
}, | ||
properties: { | ||
coordinates: { | ||
type: 'array', | ||
}, | ||
address: { | ||
type: 'string', | ||
}, | ||
description: { | ||
type: 'string', | ||
}, | ||
}, | ||
// longitute, latitude | ||
}, | ||
locations: { | ||
type: 'array', | ||
description: 'Geo JSON Points', | ||
}, | ||
|
||
secretTrip: { | ||
type: 'boolean', | ||
description: 'Special Secret Trips ', | ||
}, | ||
}, | ||
}, | ||
|
||
// error model | ||
Error: { | ||
type: 'object', //data type | ||
properties: { | ||
message: { | ||
type: 'string', // data type | ||
description: 'Error message', // desc | ||
example: 'Not found', // example of an error message | ||
}, | ||
internal_code: { | ||
type: 'string', // data type | ||
description: 'Error internal code', // desc | ||
example: 'Invalid parameters', // example of an error internal code | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export { component }; |
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,13 @@ | ||
import { basicInfo } from './basicInfo'; | ||
import { server } from './server'; | ||
import { tag } from './tags'; | ||
import { component } from './components'; | ||
import trips from './trips'; | ||
|
||
export = { | ||
...basicInfo, | ||
...server, | ||
...tag, | ||
...component, | ||
...trips, | ||
}; |
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,14 @@ | ||
const server = { | ||
servers: [ | ||
{ | ||
url: 'http://localhost:1337/api/v1', // url | ||
description: 'Local server', // name | ||
}, | ||
{ | ||
url: 'https://tours-api-prod.herokuapp.com', // url | ||
description: 'Production server', // name | ||
}, | ||
], | ||
}; | ||
|
||
export { server }; |
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,9 @@ | ||
const tag = { | ||
tags: [ | ||
{ | ||
name: 'An API to book tours', // name of a tag | ||
}, | ||
], | ||
}; | ||
|
||
export { tag }; |
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,34 @@ | ||
const getATrip = { | ||
// method of operation | ||
get: { | ||
tags: ['Get A Trip'], // operation's tag. | ||
description: 'Get A Trip', // operation's desc. | ||
operationId: 'getATrip', // unique operation id. | ||
parameters: [ | ||
{ | ||
name: 'id', // name of the param | ||
in: 'path', // location of the param | ||
schema: { type: 'string', default: null }, | ||
required: false, // Mandatory param | ||
description: 'id of Trip', // param desc. | ||
}, | ||
], // expected params. | ||
// expected responses | ||
responses: { | ||
// response code | ||
200: { | ||
description: 'Get A Trip', // response desc. | ||
content: { | ||
// content-type | ||
'application/json': { | ||
schema: { | ||
$ref: '#/components/schemas/Trips', // Todo model | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export { getATrip }; |
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,9 @@ | ||
import { getATrip } from './getATrip'; | ||
|
||
export = { | ||
paths: { | ||
'/trips/:id': { | ||
...getATrip, | ||
}, | ||
}, | ||
}; |
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