mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
add own api to servers
This commit is contained in:
@@ -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())
|
||||
}));
|
||||
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user