Custom swagger endpoint for docs (#3869)

* custom swagger endpoint
metadata graphql
remove /rest from endpoint

* fixed pseudo scheme creation

* move graphql playground creation to own file, added navbar to change baseurl and token

* add schema switcher, fix changing url not applied, add invalid overlay

* fix link color

* removed path on Graphql Playground, naming fixes subdoc

* - fixed overflow issue Rest docs

* history replace & goBack

* Small fix GraphQL playground broken

---------

Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
brendanlaschke
2024-02-08 16:54:20 +01:00
committed by GitHub
parent 719da29795
commit c53b593ea6
13 changed files with 338 additions and 113 deletions

View File

@ -8,9 +8,22 @@ import { OpenApiService } from 'src/core/open-api/open-api.service';
export class OpenApiController {
constructor(private readonly openApiService: OpenApiService) {}
@Get()
async generateOpenApiSchema(@Req() request: Request, @Res() res: Response) {
const data = await this.openApiService.generateSchema(request);
@Get('core')
async generateOpenApiSchemaCore(
@Req() request: Request,
@Res() res: Response,
) {
const data = await this.openApiService.generateCoreSchema(request);
res.send(data);
}
@Get('metadata')
async generateOpenApiSchemaMetaData(
@Req() request: Request,
@Res() res: Response,
) {
const data = await this.openApiService.generateMetaDataSchema();
res.send(data);
}

View File

@ -24,7 +24,7 @@ export class OpenApiService {
private readonly objectMetadataService: ObjectMetadataService,
) {}
async generateSchema(request: Request): Promise<OpenAPIV3.Document> {
async generateCoreSchema(request: Request): Promise<OpenAPIV3.Document> {
const schema = baseSchema();
let objectMetadataItems;
@ -42,8 +42,8 @@ export class OpenApiService {
return schema;
}
schema.paths = objectMetadataItems.reduce((paths, item) => {
paths[`/rest/${item.namePlural}`] = computeManyResultPath(item);
paths[`/rest/${item.namePlural}/{id}`] = computeSingleResultPath(item);
paths[`/${item.namePlural}`] = computeManyResultPath(item);
paths[`/${item.namePlural}/{id}`] = computeSingleResultPath(item);
return paths;
}, schema.paths as OpenAPIV3.PathsObject);
@ -62,4 +62,13 @@ export class OpenApiService {
return schema;
}
async generateMetaDataSchema(): Promise<OpenAPIV3.Document> {
//TODO Add once Rest MetaData api is ready
const schema = baseSchema();
schema.tags = [{ name: 'placeholder' }];
return schema;
}
}

View File

@ -21,7 +21,7 @@ export const baseSchema = (): OpenAPIV3.Document => {
// Testing purposes
servers: [
{
url: 'https://api.twenty.com/',
url: 'https://api.twenty.com/rest',
description: 'Production Development',
},
],