Changed regions doc so it works with query parameters

This commit is contained in:
Timo John 2020-06-29 15:04:11 +02:00
parent ebb1304eeb
commit 3cccdab368
2 changed files with 60 additions and 64 deletions

View File

@ -23,12 +23,8 @@ const app = express();
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const swaggerUIOptions = {
explorer: true
};
// Swagger set up
const swaggerJSOptions = {
const swaggerOptions = {
swaggerDefinition: {
openapi: "3.0.0",
info: {
@ -39,7 +35,7 @@ const swaggerJSOptions = {
"No API Key required.",
license: {
name: "Licensing Pending",
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&feature=youtu.be"
},
contact: {
name: "travOpti",
@ -48,22 +44,22 @@ const swaggerJSOptions = {
}
},
servers: [
{
url: "http://localhost:3000/api/v1"
},
{
url: "https://travopti.de/api/v1"
}
]
},
apis: [
"./Routes/search.js",
"./Routes/regions.js",
"./Routes/place.js",
"./Routes/countries.js",
"./Routes/climate.js", "./Models/handleClimateUpdate.js", "./Models/handleClimateUpdateV2.js",
"./Routes/update.js"
"./Routes/*.js",
"./Models/handleClimateUpdate.js",
"./Models/handleClimateUpdateV2.js",
]
};
const specs = swaggerJsdoc(swaggerJSOptions);
const swaggerDocs = swaggerJsdoc(swaggerOptions);
(async () => {
try {
@ -74,7 +70,7 @@ const specs = swaggerJsdoc(swaggerJSOptions);
app.use(express.static(path.join(__dirname, "../../dist")));
app.use(bodyParser.json());
app.use(cors());
app.use('/api/v1/doc', swaggerUi.serve, swaggerUi.setup(specs, swaggerUIOptions));
app.use('/api/v1/doc', swaggerUi.serve, swaggerUi.setup(swaggerDocs, {explorer: true}));
// Express routes
app.use(search(dbConn));

View File

@ -21,18 +21,13 @@ const sqlSanitzer = require("../util/sqlstring_sanitizer.js")
module.exports = dbConn => {
/**
* @swagger
* path:
* /regions:
* get:
* summary: Get all regions
* tags: [Regions]
* responses:
* "200":
* description: Returns all regions and aviable data
* content:
* application/json:
* schema:
* $ref: ''
* /regions:
* get:
* summary: Get all regions
* tags: [Regions]
* responses:
* "200":
* description: Returns aviable data for all regions
*/
router.get("/api/v1/regions", async (req, res) => {
const data = await getRegions(dbConn)
@ -46,18 +41,18 @@ module.exports = dbConn => {
/**
* @swagger
* path:
* /regions/:id:
* get:
* summary: Get a specific region
* tags: [Regions]
* responses:
* "200":
* description: Returns the specific region and aviable data
* content:
* application/json:
* schema:
* $ref: ''
* /regions/{id}:
* get:
* summary: Get a specific region by id
* tags: [Regions]
* parameters:
* - name: "id"
* in: "path"
* required: true
* type: int
* responses:
* "200":
* description: Returns aviable data for the region
*/
router.get("/api/v1/regions/:id", async (req, res) => {
console.log(typeof req.params.id)
@ -68,41 +63,46 @@ module.exports = dbConn => {
/**
* @swagger
* path:
* /regions/:id/image:
* get:
* summary: Get all country
* tags: [Regions]
* responses:
* "200":
* description: Returns the image for a specific region
* content:
* application/json:
* schema:
* $ref: ''
* /regions/{id}/image:
* get:
* summary: Get image for specific region
* tags: [Regions]
* parameters:
* - name: "id"
* in: "path"
* required: true
* type: int
* responses:
* "200":
* description: Returns the image for a specific region
* "404":
* description: Returns a placeholder image for the region
*/
router.get('/api/v1/regions/:id/image', (req, res) => {
console.log("HERE")
if (fs.existsSync(path.join(__dirname, `../data/regions/images/${req.params.id}.jpg`))) {
res.sendFile(path.join(__dirname, `../data/regions/images/${req.params.id}.jpg`))
console.log("EXISTS")
res.status(200).sendFile(path.join(__dirname, `../data/regions/images/${req.params.id}.jpg`))
} else {
res.sendFile(path.join(__dirname, `../data/regions/images/x.png`))
console.log("NOT EXISTS")
res.status(404).sendFile(path.join(__dirname, `../data/regions/images/x.png`))
}
})
/**
* @swagger
* path:
* /regions/:id/nearby:
* get:
* summary: Get nearby places for a specific region
* tags: [Regions]
* responses:
* "200":
* description: Returns nearby places for a specific region
* content:
* application/json:
* schema:
* $ref: ''
* /regions/{id}/nearby:
* get:
* summary: Get nearby places of a specific region by id
* tags: [Regions]
* parameters:
* - name: "id"
* in: "path"
* required: true
* type: int
* responses:
* "200":
* description: Returns all nearby places for the region
*/
router.get("/api/v1/regions/:id/nearby", async (req,res) => {
const id = sqlSanitzer(req.params.id);