2914 graphql api documentation (#3065)

* Remove dead code

* Create playground component

* Remove useless call to action

* Fix graphiql theme

* Fix style

* Split components

* Move headers to headers form

* Fix nodes in open-api components

* Remove useless check

* Clean code

* Fix css differences

* Keep carret when fetching schema
This commit is contained in:
martmull
2023-12-20 12:01:55 +01:00
committed by GitHub
parent d2666dc667
commit ed7bd0ba26
9 changed files with 250 additions and 158 deletions

View File

@ -5,7 +5,6 @@ import { OpenAPIV3 } from 'openapi-types';
import { TokenService } from 'src/core/auth/services/token.service';
import { ObjectMetadataService } from 'src/metadata/object-metadata/object-metadata.service';
import { EnvironmentService } from 'src/integrations/environment/environment.service';
import { baseSchema } from 'src/core/open-api/utils/base-schema.utils';
import {
computeManyResultPath,
@ -23,11 +22,10 @@ export class OpenApiService {
constructor(
private readonly tokenService: TokenService,
private readonly objectMetadataService: ObjectMetadataService,
private readonly environmentService: EnvironmentService,
) {}
async generateSchema(request: Request): Promise<OpenAPIV3.Document> {
const schema = baseSchema(this.environmentService.getFrontBaseUrl());
const schema = baseSchema();
let objectMetadataItems;

View File

@ -2,12 +2,12 @@ import { OpenAPIV3 } from 'openapi-types';
import { computeOpenApiPath } from 'src/core/open-api/utils/path.utils';
export const baseSchema = (frontBaseUrl: string): OpenAPIV3.Document => {
export const baseSchema = (): OpenAPIV3.Document => {
return {
openapi: '3.0.3',
info: {
title: 'Twenty Api',
description: `This is a **Twenty REST/API** playground based on the **OpenAPI 3.0 specification**.\n\nTo use the Playground, please log to your twenty account and generate an API key here: ${frontBaseUrl}/settings/developers/api-keys`,
description: `This is a **Twenty REST/API** playground based on the **OpenAPI 3.0 specification**.`,
termsOfService: 'https://github.com/twentyhq/twenty?tab=coc-ov-file',
contact: {
email: 'felix@twenty.com',

View File

@ -42,17 +42,16 @@ const getSchemaComponentsProperties = (
itemProperty.type = 'boolean';
break;
case FieldMetadataType.RELATION:
itemProperty = {
type: 'array',
items: {
type: 'object',
properties: {
node: {
type: 'object',
},
if (field.fromRelationMetadata?.toObjectMetadata.nameSingular) {
itemProperty = {
type: 'array',
items: {
$ref: `#/components/schemas/${capitalize(
field.fromRelationMetadata?.toObjectMetadata.nameSingular || '',
)}`,
},
},
};
};
}
break;
case FieldMetadataType.LINK:
case FieldMetadataType.CURRENCY:
@ -74,7 +73,9 @@ const getSchemaComponentsProperties = (
break;
}
node[field.name] = itemProperty;
if (Object.keys(itemProperty).length) {
node[field.name] = itemProperty;
}
return node;
}, {} as Properties);