diff --git a/packages/twenty-server/src/core/open-api/open-api.controller.ts b/packages/twenty-server/src/core/open-api/open-api.controller.ts index 2dcaf8a4b387..b5617cb4c58b 100644 --- a/packages/twenty-server/src/core/open-api/open-api.controller.ts +++ b/packages/twenty-server/src/core/open-api/open-api.controller.ts @@ -23,7 +23,7 @@ export class OpenApiController { @Req() request: Request, @Res() res: Response, ) { - const data = await this.openApiService.generateMetaDataSchema(); + const data = await this.openApiService.generateMetaDataSchema(request); res.send(data); } diff --git a/packages/twenty-server/src/core/open-api/open-api.service.ts b/packages/twenty-server/src/core/open-api/open-api.service.ts index 80f4ee1accd2..45f05d2c557b 100644 --- a/packages/twenty-server/src/core/open-api/open-api.service.ts +++ b/packages/twenty-server/src/core/open-api/open-api.service.ts @@ -25,16 +25,22 @@ import { getSingleResultSuccessResponse, } from 'src/core/open-api/utils/responses.utils'; import { getRequestBody } from 'src/core/open-api/utils/request-body.utils'; +import { EnvironmentService } from 'src/integrations/environment/environment.service'; @Injectable() export class OpenApiService { constructor( private readonly tokenService: TokenService, + private readonly environmentService: EnvironmentService, private readonly objectMetadataService: ObjectMetadataService, ) {} async generateCoreSchema(request: Request): Promise { - const schema = baseSchema('core'); + const baseUrl = + this.environmentService.getServerUrl() || + `${request.protocol}://${request.get('host')}`; + + const schema = baseSchema('core', baseUrl); let objectMetadataItems; @@ -86,9 +92,14 @@ export class OpenApiService { return schema; } - async generateMetaDataSchema(): Promise { - //TODO Add once Rest MetaData api is ready - const schema = baseSchema('metadata'); + async generateMetaDataSchema( + request: Request, + ): Promise { + const baseUrl = + this.environmentService.getServerUrl() || + `${request.protocol}://${request.get('host')}`; + + const schema = baseSchema('metadata', baseUrl); schema.tags = [{ name: 'placeholder' }]; diff --git a/packages/twenty-server/src/core/open-api/utils/base-schema.utils.ts b/packages/twenty-server/src/core/open-api/utils/base-schema.utils.ts index e7d969a7b52d..d9acf880f8d5 100644 --- a/packages/twenty-server/src/core/open-api/utils/base-schema.utils.ts +++ b/packages/twenty-server/src/core/open-api/utils/base-schema.utils.ts @@ -4,6 +4,7 @@ import { computeOpenApiPath } from 'src/core/open-api/utils/path.utils'; export const baseSchema = ( schemaName: 'core' | 'metadata', + serverUrl: string, ): OpenAPIV3_1.Document => { return { openapi: '3.0.3', @@ -23,9 +24,7 @@ export const baseSchema = ( // Testing purposes servers: [ { - url: `https://api.twenty.com/rest/${ - schemaName !== 'core' ? schemaName : '' - }`, + url: `${serverUrl}/rest/${schemaName !== 'core' ? schemaName : ''}`, description: 'Production Development', }, ],