add own api to servers

This commit is contained in:
Nitwel
2020-10-05 10:02:10 +02:00
parent 46275688d4
commit 6e3841d69d
2 changed files with 12 additions and 3 deletions

View File

@@ -6,7 +6,8 @@ import asyncHandler from 'express-async-handler';
const router = Router();
router.get('/specs/oas', asyncHandler(async (req, res, next) => {
const service = new SpecificationService({accountability: req.accountability})
const url = req.protocol + '://' + req.get('host') + '/'
const service = new SpecificationService(url, {accountability: req.accountability})
res.json(await service.generateOAS())
}));

View File

@@ -92,13 +92,15 @@ export class SpecificationService {
accountability: Accountability | null;
fieldsService: FieldsService | null;
collectionsService: CollectionsService | null;
relationsService: RelationsService | null
relationsService: RelationsService | null;
url: string | null;
constructor(options?: AbstractServiceOptions) {
constructor(url: string, options?: AbstractServiceOptions) {
this.accountability = options?.accountability || null;
this.fieldsService = new FieldsService(options)
this.collectionsService = new CollectionsService(options)
this.relationsService = new RelationsService(options)
this.url = url;
}
async generateOAS() {
@@ -145,6 +147,12 @@ export class SpecificationService {
description: 'This is a dynamicly generated api specification for all endpoints existing on the api.',
version: version
},
servers: [
{
url: this.url,
description: 'Your current api server.'
}
],
tags: this.generateTags(collections),
paths: this.generatePaths(collections),
components: {