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:
@ -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;
|
||||
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user