diff --git a/fern/apis/fdr/definition/commons.yml b/fern/apis/fdr/definition/commons.yml index ca84eb76f7..558c847de9 100644 --- a/fern/apis/fdr/definition/commons.yml +++ b/fern/apis/fdr/definition/commons.yml @@ -14,6 +14,23 @@ types: DocsConfigId: type: string docs: The ID of a particular docs config. + + EndpointIdentifier: + properties: + path: EndpointPath + method: EndpointMethod + + EndpointPath: + type: string + docs: The relative path for an endpont (e.g. `/users/{userId}`) + + EndpointMethod: + enum: + - PUT + - POST + - GET + - PATCH + - DELETE errors: BadRequestError: diff --git a/fern/apis/fdr/definition/diff.yml b/fern/apis/fdr/definition/diff.yml new file mode 100644 index 0000000000..21ae833962 --- /dev/null +++ b/fern/apis/fdr/definition/diff.yml @@ -0,0 +1,71 @@ +imports: + commons: commons.yml + +types: + APIDiff: + properties: + endpointDiffs: list + + EndpointDiff: + properties: + id: commons.EndpointIdentifier + pathParameterDiff: PathParameterDiff + queryParameterDiff: QueryParameterDiff + requestBodyDiff: RequestBodyDiff + responseBodyDiff: ResponseBodyDiff + + PathParameterDiff: + properties: + added: list + removed: list + + PathParameter: + properties: + wireKey: string + + QueryParameterDiff: + properties: + added: list + removed: list + + QueryParameter: + properties: + wireKey: string + + RequestBodyDiff: + properties: + added: list + removed: list + + RequestBodyParameter: + properties: + wireKey: string + + ResponseBodyDiff: + properties: + added: list + removed: list + + ResponseBodyParameter: + properties: + wireKey: string + +service: + base-path: /registry + auth: true + endpoints: + diff: + method: GET + path: /diff + request: + name: APIDiffRequest + query-parameters: + previousApiDefinitionId: + type: commons.ApiDefinitionId + docs: The id of the previous version of the api definition + currentApiDefinitionId: + type: commons.ApiDefinitionId + docs: The id of the current version of the api definition + response: + type: APIDiff + docs: The diff between the previous and current api definitions diff --git a/fern/apis/fdr/definition/snippets-factory.yml b/fern/apis/fdr/definition/snippets-factory.yml index 7a8858db69..a15e90971a 100644 --- a/fern/apis/fdr/definition/snippets-factory.yml +++ b/fern/apis/fdr/definition/snippets-factory.yml @@ -72,27 +72,27 @@ types: SingleTypescriptSnippetCreate: properties: - endpoint: snippets.EndpointIdentifier + endpoint: commons.EndpointIdentifier snippet: TypeScriptSnippetCode SinglePythonSnippetCreate: properties: - endpoint: snippets.EndpointIdentifier + endpoint: commons.EndpointIdentifier snippet: PythonSnippetCode SingleGoSnippetCreate: properties: - endpoint: snippets.EndpointIdentifier + endpoint: commons.EndpointIdentifier snippet: GoSnippetCode SingleRubySnippetCreate: properties: - endpoint: snippets.EndpointIdentifier + endpoint: commons.EndpointIdentifier snippet: RubySnippetCode SingleJavaSnippetCreate: properties: - endpoint: snippets.EndpointIdentifier + endpoint: commons.EndpointIdentifier snippet: JavaSnippetCode # Snippet Code diff --git a/fern/apis/fdr/definition/snippets.yml b/fern/apis/fdr/definition/snippets.yml index 831606ce87..5905ec27cf 100644 --- a/fern/apis/fdr/definition/snippets.yml +++ b/fern/apis/fdr/definition/snippets.yml @@ -34,7 +34,7 @@ service: docs: | The SDKs for which to load snippets. If unspecified, snippets for the latest published SDKs will be returned. - endpoint: EndpointIdentifier + endpoint: commons.EndpointIdentifier # TODO: Nice to have, allow client variable name to be configurable # clientName: # type: optional @@ -206,23 +206,6 @@ service: }) types: - EndpointIdentifier: - properties: - path: EndpointPath - method: EndpointMethod - - EndpointPath: - type: string - docs: The relative path for an endpont (e.g. `/users/{userId}`) - - EndpointMethod: - enum: - - PUT - - POST - - GET - - PATCH - - DELETE - SDK: union: typescript: TypeScriptSDK @@ -281,13 +264,13 @@ types: type: optional docs: If present, pass this into the `page` query parameter to load the next page. snippets: - type: map + type: map docs: | The snippets are returned as a map of endpoint path (e.g. `/api/users`) to a map of endpoint method (e.g. `POST`) to snippets. SnippetsByEndpointMethod: - type: map> + type: map> # TODO: we should transition snippets to a more user friendly API like below to allow for more flexibility on the consumer side: # Snippet: diff --git a/fern/apis/fdr/definition/templates.yml b/fern/apis/fdr/definition/templates.yml index 34b6eed827..94526e0bc5 100644 --- a/fern/apis/fdr/definition/templates.yml +++ b/fern/apis/fdr/definition/templates.yml @@ -71,7 +71,7 @@ service: docs: | The API name. sdk: snippets.SDK - endpointId: snippets.EndpointIdentifier + endpointId: commons.EndpointIdentifier response: EndpointSnippetTemplate types: @@ -212,13 +212,13 @@ types: SnippetRegistryEntry: properties: sdk: snippets.SDK - endpointId: snippets.EndpointIdentifier + endpointId: commons.EndpointIdentifier snippetTemplate: VersionedSnippetTemplate EndpointSnippetTemplate: properties: sdk: snippets.SDK - endpointId: snippets.EndpointIdentifier + endpointId: commons.EndpointIdentifier snippetTemplate: VersionedSnippetTemplate errors: diff --git a/packages/fdr-sdk/src/client/generated/Client.ts b/packages/fdr-sdk/src/client/generated/Client.ts index 0da4a1f50e..91547c78d3 100644 --- a/packages/fdr-sdk/src/client/generated/Client.ts +++ b/packages/fdr-sdk/src/client/generated/Client.ts @@ -6,6 +6,7 @@ import * as environments from "./environments"; import * as core from "./core"; import { Api } from "./api/resources/api/client/Client"; import { Docs } from "./api/resources/docs/client/Client"; +import { Diff } from "./api/resources/diff/client/Client"; import { SnippetsFactory } from "./api/resources/snippetsFactory/client/Client"; import { Snippets } from "./api/resources/snippets/client/Client"; import { Templates } from "./api/resources/templates/client/Client"; @@ -37,6 +38,12 @@ export class FernRegistryClient { return (this._docs ??= new Docs(this._options)); } + protected _diff: Diff | undefined; + + public get diff(): Diff { + return (this._diff ??= new Diff(this._options)); + } + protected _snippetsFactory: SnippetsFactory | undefined; public get snippetsFactory(): SnippetsFactory { diff --git a/packages/fdr-sdk/src/client/generated/api/resources/snippets/types/EndpointIdentifier.ts b/packages/fdr-sdk/src/client/generated/api/resources/commons/types/EndpointIdentifier.ts similarity index 100% rename from packages/fdr-sdk/src/client/generated/api/resources/snippets/types/EndpointIdentifier.ts rename to packages/fdr-sdk/src/client/generated/api/resources/commons/types/EndpointIdentifier.ts diff --git a/packages/fdr-sdk/src/client/generated/api/resources/snippets/types/EndpointMethod.ts b/packages/fdr-sdk/src/client/generated/api/resources/commons/types/EndpointMethod.ts similarity index 100% rename from packages/fdr-sdk/src/client/generated/api/resources/snippets/types/EndpointMethod.ts rename to packages/fdr-sdk/src/client/generated/api/resources/commons/types/EndpointMethod.ts diff --git a/packages/fdr-sdk/src/client/generated/api/resources/snippets/types/EndpointPath.ts b/packages/fdr-sdk/src/client/generated/api/resources/commons/types/EndpointPath.ts similarity index 100% rename from packages/fdr-sdk/src/client/generated/api/resources/snippets/types/EndpointPath.ts rename to packages/fdr-sdk/src/client/generated/api/resources/commons/types/EndpointPath.ts diff --git a/packages/fdr-sdk/src/client/generated/api/resources/commons/types/index.ts b/packages/fdr-sdk/src/client/generated/api/resources/commons/types/index.ts index 3979bc19b3..eb6074109f 100644 --- a/packages/fdr-sdk/src/client/generated/api/resources/commons/types/index.ts +++ b/packages/fdr-sdk/src/client/generated/api/resources/commons/types/index.ts @@ -2,3 +2,6 @@ export * from "./ApiDefinitionId"; export * from "./OrgId"; export * from "./ApiId"; export * from "./DocsConfigId"; +export * from "./EndpointIdentifier"; +export * from "./EndpointPath"; +export * from "./EndpointMethod"; diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/client/Client.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/client/Client.ts new file mode 100644 index 0000000000..ca0f621d67 --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/client/Client.ts @@ -0,0 +1,71 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as environments from "../../../../environments"; +import * as core from "../../../../core"; +import * as FernRegistry from "../../.."; +import urlJoin from "url-join"; + +export declare namespace Diff { + interface Options { + environment?: core.Supplier; + token?: core.Supplier; + } + + interface RequestOptions { + timeoutInSeconds?: number; + maxRetries?: number; + } +} + +export class Diff { + constructor(protected readonly _options: Diff.Options = {}) {} + + public async diff( + request: FernRegistry.ApiDiffRequest, + requestOptions?: Diff.RequestOptions + ): Promise> { + const { previousApiDefinitionId, currentApiDefinitionId } = request; + const _queryParams: Record = {}; + _queryParams["previousApiDefinitionId"] = previousApiDefinitionId; + _queryParams["currentApiDefinitionId"] = currentApiDefinitionId; + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.FernRegistryEnvironment.Dev, + "/registry/diff" + ), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + }, + contentType: "application/json", + queryParameters: _queryParams, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : undefined, + maxRetries: requestOptions?.maxRetries, + }); + if (_response.ok) { + return { + ok: true, + body: _response.body as FernRegistry.ApiDiff, + }; + } + + return { + ok: false, + error: FernRegistry.diff.diff.Error._unknown(_response.error), + }; + } + + protected async _getAuthorizationHeader() { + const bearer = await core.Supplier.get(this._options.token); + if (bearer != null) { + return `Bearer ${bearer}`; + } + + return undefined; + } +} diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/client/diff.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/client/diff.ts new file mode 100644 index 0000000000..dcbda34cb5 --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/client/diff.ts @@ -0,0 +1,38 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as FernRegistry from "../../.."; +import * as core from "../../../../core"; + +export type Error = FernRegistry.diff.diff.Error._Unknown; + +export declare namespace Error { + interface _Unknown { + error: void; + content: core.Fetcher.Error; + } + + interface _Visitor<_Result> { + _other: (value: core.Fetcher.Error) => _Result; + } +} + +export const Error = { + _unknown: (fetcherError: core.Fetcher.Error): FernRegistry.diff.diff.Error._Unknown => { + return { + error: undefined, + content: fetcherError, + }; + }, + + _visit: <_Result>( + value: FernRegistry.diff.diff.Error, + visitor: FernRegistry.diff.diff.Error._Visitor<_Result> + ): _Result => { + switch (value.error) { + default: + return visitor._other(value as any); + } + }, +} as const; diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/client/index.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/client/index.ts new file mode 100644 index 0000000000..84b3fbddf7 --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/client/index.ts @@ -0,0 +1,2 @@ +export * from "./requests"; +export * as diff from "./diff"; diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/client/requests/ApiDiffRequest.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/client/requests/ApiDiffRequest.ts new file mode 100644 index 0000000000..219a94df40 --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/client/requests/ApiDiffRequest.ts @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as FernRegistry from "../../../.."; + +export interface ApiDiffRequest { + /** + * The id of the previous version of the api definition + */ + previousApiDefinitionId: FernRegistry.ApiDefinitionId; + /** + * The id of the current version of the api definition + */ + currentApiDefinitionId: FernRegistry.ApiDefinitionId; +} diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/client/requests/index.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/client/requests/index.ts new file mode 100644 index 0000000000..8e3e8f7563 --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/client/requests/index.ts @@ -0,0 +1 @@ +export { ApiDiffRequest } from "./ApiDiffRequest"; diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/index.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/index.ts new file mode 100644 index 0000000000..c9240f83b4 --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/index.ts @@ -0,0 +1,2 @@ +export * from "./types"; +export * from "./client"; diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/types/ApiDiff.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/ApiDiff.ts new file mode 100644 index 0000000000..8d99c1fe51 --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/ApiDiff.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as FernRegistry from "../../.."; + +export interface ApiDiff { + endpointDiffs: FernRegistry.EndpointDiff[]; +} diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/types/EndpointDiff.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/EndpointDiff.ts new file mode 100644 index 0000000000..20a70ae8f8 --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/EndpointDiff.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as FernRegistry from "../../.."; + +export interface EndpointDiff { + id: FernRegistry.EndpointIdentifier; + pathParameterDiff: FernRegistry.PathParameterDiff; + queryParameterDiff: FernRegistry.QueryParameterDiff; + requestBodyDiff: FernRegistry.RequestBodyDiff; + responseBodyDiff: FernRegistry.ResponseBodyDiff; +} diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/types/PathParameter.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/PathParameter.ts new file mode 100644 index 0000000000..1dea358feb --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/PathParameter.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface PathParameter { + wireKey: string; +} diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/types/PathParameterDiff.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/PathParameterDiff.ts new file mode 100644 index 0000000000..f1e33f9df5 --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/PathParameterDiff.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as FernRegistry from "../../.."; + +export interface PathParameterDiff { + added: FernRegistry.PathParameter[]; + removed: FernRegistry.PathParameter[]; +} diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/types/QueryParameter.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/QueryParameter.ts new file mode 100644 index 0000000000..55a2c4c519 --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/QueryParameter.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface QueryParameter { + wireKey: string; +} diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/types/QueryParameterDiff.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/QueryParameterDiff.ts new file mode 100644 index 0000000000..93e0baab75 --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/QueryParameterDiff.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as FernRegistry from "../../.."; + +export interface QueryParameterDiff { + added: FernRegistry.QueryParameter[]; + removed: FernRegistry.QueryParameter[]; +} diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/types/RequestBodyDiff.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/RequestBodyDiff.ts new file mode 100644 index 0000000000..9b4f8965be --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/RequestBodyDiff.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as FernRegistry from "../../.."; + +export interface RequestBodyDiff { + added: FernRegistry.RequestBodyParameter[]; + removed: FernRegistry.RequestBodyParameter[]; +} diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/types/RequestBodyParameter.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/RequestBodyParameter.ts new file mode 100644 index 0000000000..6254b02dbb --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/RequestBodyParameter.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface RequestBodyParameter { + wireKey: string; +} diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/types/ResponseBodyDiff.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/ResponseBodyDiff.ts new file mode 100644 index 0000000000..74935c8e79 --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/ResponseBodyDiff.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as FernRegistry from "../../.."; + +export interface ResponseBodyDiff { + added: FernRegistry.ResponseBodyParameter[]; + removed: FernRegistry.ResponseBodyParameter[]; +} diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/types/ResponseBodyParameter.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/ResponseBodyParameter.ts new file mode 100644 index 0000000000..5a7ebbf766 --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/ResponseBodyParameter.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface ResponseBodyParameter { + wireKey: string; +} diff --git a/packages/fdr-sdk/src/client/generated/api/resources/diff/types/index.ts b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/index.ts new file mode 100644 index 0000000000..7f9eb28975 --- /dev/null +++ b/packages/fdr-sdk/src/client/generated/api/resources/diff/types/index.ts @@ -0,0 +1,10 @@ +export * from "./ApiDiff"; +export * from "./EndpointDiff"; +export * from "./PathParameterDiff"; +export * from "./PathParameter"; +export * from "./QueryParameterDiff"; +export * from "./QueryParameter"; +export * from "./RequestBodyDiff"; +export * from "./RequestBodyParameter"; +export * from "./ResponseBodyDiff"; +export * from "./ResponseBodyParameter"; diff --git a/packages/fdr-sdk/src/client/generated/api/resources/index.ts b/packages/fdr-sdk/src/client/generated/api/resources/index.ts index 0d1307e284..3f7b41ba8e 100644 --- a/packages/fdr-sdk/src/client/generated/api/resources/index.ts +++ b/packages/fdr-sdk/src/client/generated/api/resources/index.ts @@ -2,12 +2,15 @@ export * as api from "./api"; export * as docs from "./docs"; export * as commons from "./commons"; export * from "./commons/types"; +export * as diff from "./diff"; +export * from "./diff/types"; export * as snippetsFactory from "./snippetsFactory"; export * from "./snippetsFactory/types"; export * as snippets from "./snippets"; export * from "./snippets/types"; export * as templates from "./templates"; export * from "./templates/types"; +export * from "./diff/client/requests"; export * from "./snippetsFactory/client/requests"; export * from "./snippets/client/requests"; export * from "./templates/client/requests"; diff --git a/packages/fdr-sdk/src/client/generated/api/resources/snippets/types/index.ts b/packages/fdr-sdk/src/client/generated/api/resources/snippets/types/index.ts index 6347c36e13..7060912125 100644 --- a/packages/fdr-sdk/src/client/generated/api/resources/snippets/types/index.ts +++ b/packages/fdr-sdk/src/client/generated/api/resources/snippets/types/index.ts @@ -1,6 +1,3 @@ -export * from "./EndpointIdentifier"; -export * from "./EndpointPath"; -export * from "./EndpointMethod"; export * from "./Sdk"; export * from "./TypeScriptSdk"; export * from "./PythonSdk"; diff --git a/servers/fdr/src/__test__/local/setupMockFdr.ts b/servers/fdr/src/__test__/local/setupMockFdr.ts index 32cf8ae62d..784ffcd37a 100644 --- a/servers/fdr/src/__test__/local/setupMockFdr.ts +++ b/servers/fdr/src/__test__/local/setupMockFdr.ts @@ -7,6 +7,7 @@ import { register } from "../../api"; import { FdrApplication } from "../../app"; import { getReadApiService } from "../../controllers/api/getApiReadService"; import { getRegisterApiService } from "../../controllers/api/getRegisterApiService"; +import { getApiDiffService } from "../../controllers/diff/getApiDiffService"; import { getDocsReadService } from "../../controllers/docs/v1/getDocsReadService"; import { getDocsWriteService } from "../../controllers/docs/v1/getDocsWriteService"; import { getDocsReadV2Service } from "../../controllers/docs/v2/getDocsReadV2Service"; @@ -96,6 +97,7 @@ function runMockFdr(port: number): MockFdr.Instance { snippets: getSnippetsService(fdrApplication), snippetsFactory: getSnippetsFactoryService(fdrApplication), templates: getTemplatesService(fdrApplication), + diff: getApiDiffService(fdrApplication), }); const server = app.listen(port); console.log(`Mock FDR server running on http://localhost:${port}/`); diff --git a/servers/fdr/src/api/generated/api/resources/snippets/types/EndpointIdentifier.d.ts b/servers/fdr/src/api/generated/api/resources/commons/types/EndpointIdentifier.d.ts similarity index 100% rename from servers/fdr/src/api/generated/api/resources/snippets/types/EndpointIdentifier.d.ts rename to servers/fdr/src/api/generated/api/resources/commons/types/EndpointIdentifier.d.ts diff --git a/servers/fdr/src/api/generated/api/resources/snippets/types/EndpointIdentifier.js b/servers/fdr/src/api/generated/api/resources/commons/types/EndpointIdentifier.js similarity index 100% rename from servers/fdr/src/api/generated/api/resources/snippets/types/EndpointIdentifier.js rename to servers/fdr/src/api/generated/api/resources/commons/types/EndpointIdentifier.js diff --git a/servers/fdr/src/api/generated/api/resources/snippets/types/EndpointMethod.d.ts b/servers/fdr/src/api/generated/api/resources/commons/types/EndpointMethod.d.ts similarity index 100% rename from servers/fdr/src/api/generated/api/resources/snippets/types/EndpointMethod.d.ts rename to servers/fdr/src/api/generated/api/resources/commons/types/EndpointMethod.d.ts diff --git a/servers/fdr/src/api/generated/api/resources/snippets/types/EndpointMethod.js b/servers/fdr/src/api/generated/api/resources/commons/types/EndpointMethod.js similarity index 100% rename from servers/fdr/src/api/generated/api/resources/snippets/types/EndpointMethod.js rename to servers/fdr/src/api/generated/api/resources/commons/types/EndpointMethod.js diff --git a/servers/fdr/src/api/generated/api/resources/snippets/types/EndpointPath.d.ts b/servers/fdr/src/api/generated/api/resources/commons/types/EndpointPath.d.ts similarity index 100% rename from servers/fdr/src/api/generated/api/resources/snippets/types/EndpointPath.d.ts rename to servers/fdr/src/api/generated/api/resources/commons/types/EndpointPath.d.ts diff --git a/servers/fdr/src/api/generated/api/resources/snippets/types/EndpointPath.js b/servers/fdr/src/api/generated/api/resources/commons/types/EndpointPath.js similarity index 100% rename from servers/fdr/src/api/generated/api/resources/snippets/types/EndpointPath.js rename to servers/fdr/src/api/generated/api/resources/commons/types/EndpointPath.js diff --git a/servers/fdr/src/api/generated/api/resources/commons/types/index.d.ts b/servers/fdr/src/api/generated/api/resources/commons/types/index.d.ts index 3979bc19b3..eb6074109f 100644 --- a/servers/fdr/src/api/generated/api/resources/commons/types/index.d.ts +++ b/servers/fdr/src/api/generated/api/resources/commons/types/index.d.ts @@ -2,3 +2,6 @@ export * from "./ApiDefinitionId"; export * from "./OrgId"; export * from "./ApiId"; export * from "./DocsConfigId"; +export * from "./EndpointIdentifier"; +export * from "./EndpointPath"; +export * from "./EndpointMethod"; diff --git a/servers/fdr/src/api/generated/api/resources/commons/types/index.js b/servers/fdr/src/api/generated/api/resources/commons/types/index.js index 3979bc19b3..eb6074109f 100644 --- a/servers/fdr/src/api/generated/api/resources/commons/types/index.js +++ b/servers/fdr/src/api/generated/api/resources/commons/types/index.js @@ -2,3 +2,6 @@ export * from "./ApiDefinitionId"; export * from "./OrgId"; export * from "./ApiId"; export * from "./DocsConfigId"; +export * from "./EndpointIdentifier"; +export * from "./EndpointPath"; +export * from "./EndpointMethod"; diff --git a/servers/fdr/src/api/generated/api/resources/diff/index.d.ts b/servers/fdr/src/api/generated/api/resources/diff/index.d.ts new file mode 100644 index 0000000000..fcc81debec --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/index.d.ts @@ -0,0 +1,2 @@ +export * from "./types"; +export * from "./service"; diff --git a/servers/fdr/src/api/generated/api/resources/diff/index.js b/servers/fdr/src/api/generated/api/resources/diff/index.js new file mode 100644 index 0000000000..fcc81debec --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/index.js @@ -0,0 +1,2 @@ +export * from "./types"; +export * from "./service"; diff --git a/servers/fdr/src/api/generated/api/resources/diff/service/DiffService.d.ts b/servers/fdr/src/api/generated/api/resources/diff/service/DiffService.d.ts new file mode 100644 index 0000000000..7081e4689e --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/service/DiffService.d.ts @@ -0,0 +1,22 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +import * as FernRegistry from "../../.."; +import express from "express"; +export interface DiffServiceMethods { + diff(req: express.Request, res: { + send: (responseBody: FernRegistry.ApiDiff) => Promise; + cookie: (cookie: string, value: string, options?: express.CookieOptions) => void; + locals: any; + }): void | Promise; +} +export declare class DiffService { + private readonly methods; + private router; + constructor(methods: DiffServiceMethods, middleware?: express.RequestHandler[]); + addMiddleware(handler: express.RequestHandler): this; + toRouter(): express.Router; +} diff --git a/servers/fdr/src/api/generated/api/resources/diff/service/DiffService.js b/servers/fdr/src/api/generated/api/resources/diff/service/DiffService.js new file mode 100644 index 0000000000..00aac7e949 --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/service/DiffService.js @@ -0,0 +1,54 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +import express from "express"; +import * as errors from "../../../../errors"; +export class DiffService { + constructor(methods, middleware = []) { + this.methods = methods; + this.router = express.Router({ mergeParams: true }).use(express.json({ + strict: false, + }), ...middleware); + } + addMiddleware(handler) { + this.router.use(handler); + return this; + } + toRouter() { + this.router.get("/diff", (req, res, next) => __awaiter(this, void 0, void 0, function* () { + try { + yield this.methods.diff(req, { + send: (responseBody) => __awaiter(this, void 0, void 0, function* () { + res.json(responseBody); + }), + cookie: res.cookie.bind(res), + locals: res.locals, + }); + next(); + } + catch (error) { + console.error(error); + if (error instanceof errors.FernRegistryError) { + console.warn(`Endpoint 'diff' unexpectedly threw ${error.constructor.name}.` + + ` If this was intentional, please add ${error.constructor.name} to` + + " the endpoint's errors list in your Fern Definition."); + yield error.send(res); + } + else { + res.status(500).json("Internal Server Error"); + } + next(error); + } + })); + return this.router; + } +} diff --git a/servers/fdr/src/api/generated/api/resources/diff/service/index.d.ts b/servers/fdr/src/api/generated/api/resources/diff/service/index.d.ts new file mode 100644 index 0000000000..cb0ff5c3b5 --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/service/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/servers/fdr/src/api/generated/api/resources/diff/service/index.js b/servers/fdr/src/api/generated/api/resources/diff/service/index.js new file mode 100644 index 0000000000..cb0ff5c3b5 --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/service/index.js @@ -0,0 +1 @@ +export {}; diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/ApiDiff.d.ts b/servers/fdr/src/api/generated/api/resources/diff/types/ApiDiff.d.ts new file mode 100644 index 0000000000..9efda567f1 --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/ApiDiff.d.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +import * as FernRegistry from "../../.."; +export interface ApiDiff { + endpointDiffs: FernRegistry.EndpointDiff[]; +} diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/ApiDiff.js b/servers/fdr/src/api/generated/api/resources/diff/types/ApiDiff.js new file mode 100644 index 0000000000..0b46289f5b --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/ApiDiff.js @@ -0,0 +1,4 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +export {}; diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/EndpointDiff.d.ts b/servers/fdr/src/api/generated/api/resources/diff/types/EndpointDiff.d.ts new file mode 100644 index 0000000000..f6da2e8da7 --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/EndpointDiff.d.ts @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +import * as FernRegistry from "../../.."; +export interface EndpointDiff { + id: FernRegistry.EndpointIdentifier; + pathParameterDiff: FernRegistry.PathParameterDiff; + queryParameterDiff: FernRegistry.QueryParameterDiff; + requestBodyDiff: FernRegistry.RequestBodyDiff; + responseBodyDiff: FernRegistry.ResponseBodyDiff; +} diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/EndpointDiff.js b/servers/fdr/src/api/generated/api/resources/diff/types/EndpointDiff.js new file mode 100644 index 0000000000..0b46289f5b --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/EndpointDiff.js @@ -0,0 +1,4 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +export {}; diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/PathParameter.d.ts b/servers/fdr/src/api/generated/api/resources/diff/types/PathParameter.d.ts new file mode 100644 index 0000000000..c473f2ef7b --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/PathParameter.d.ts @@ -0,0 +1,6 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +export interface PathParameter { + wireKey: string; +} diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/PathParameter.js b/servers/fdr/src/api/generated/api/resources/diff/types/PathParameter.js new file mode 100644 index 0000000000..0b46289f5b --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/PathParameter.js @@ -0,0 +1,4 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +export {}; diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/PathParameterDiff.d.ts b/servers/fdr/src/api/generated/api/resources/diff/types/PathParameterDiff.d.ts new file mode 100644 index 0000000000..6ef53f63b7 --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/PathParameterDiff.d.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +import * as FernRegistry from "../../.."; +export interface PathParameterDiff { + added: FernRegistry.PathParameter[]; + removed: FernRegistry.PathParameter[]; +} diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/PathParameterDiff.js b/servers/fdr/src/api/generated/api/resources/diff/types/PathParameterDiff.js new file mode 100644 index 0000000000..0b46289f5b --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/PathParameterDiff.js @@ -0,0 +1,4 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +export {}; diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/QueryParameter.d.ts b/servers/fdr/src/api/generated/api/resources/diff/types/QueryParameter.d.ts new file mode 100644 index 0000000000..274c8c6c7c --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/QueryParameter.d.ts @@ -0,0 +1,6 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +export interface QueryParameter { + wireKey: string; +} diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/QueryParameter.js b/servers/fdr/src/api/generated/api/resources/diff/types/QueryParameter.js new file mode 100644 index 0000000000..0b46289f5b --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/QueryParameter.js @@ -0,0 +1,4 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +export {}; diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/QueryParameterDiff.d.ts b/servers/fdr/src/api/generated/api/resources/diff/types/QueryParameterDiff.d.ts new file mode 100644 index 0000000000..c6a70248ef --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/QueryParameterDiff.d.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +import * as FernRegistry from "../../.."; +export interface QueryParameterDiff { + added: FernRegistry.QueryParameter[]; + removed: FernRegistry.QueryParameter[]; +} diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/QueryParameterDiff.js b/servers/fdr/src/api/generated/api/resources/diff/types/QueryParameterDiff.js new file mode 100644 index 0000000000..0b46289f5b --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/QueryParameterDiff.js @@ -0,0 +1,4 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +export {}; diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/RequestBodyDiff.d.ts b/servers/fdr/src/api/generated/api/resources/diff/types/RequestBodyDiff.d.ts new file mode 100644 index 0000000000..c7dd889a46 --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/RequestBodyDiff.d.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +import * as FernRegistry from "../../.."; +export interface RequestBodyDiff { + added: FernRegistry.RequestBodyParameter[]; + removed: FernRegistry.RequestBodyParameter[]; +} diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/RequestBodyDiff.js b/servers/fdr/src/api/generated/api/resources/diff/types/RequestBodyDiff.js new file mode 100644 index 0000000000..0b46289f5b --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/RequestBodyDiff.js @@ -0,0 +1,4 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +export {}; diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/RequestBodyParameter.d.ts b/servers/fdr/src/api/generated/api/resources/diff/types/RequestBodyParameter.d.ts new file mode 100644 index 0000000000..46d95cab67 --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/RequestBodyParameter.d.ts @@ -0,0 +1,6 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +export interface RequestBodyParameter { + wireKey: string; +} diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/RequestBodyParameter.js b/servers/fdr/src/api/generated/api/resources/diff/types/RequestBodyParameter.js new file mode 100644 index 0000000000..0b46289f5b --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/RequestBodyParameter.js @@ -0,0 +1,4 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +export {}; diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/ResponseBodyDiff.d.ts b/servers/fdr/src/api/generated/api/resources/diff/types/ResponseBodyDiff.d.ts new file mode 100644 index 0000000000..cdbaafa837 --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/ResponseBodyDiff.d.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +import * as FernRegistry from "../../.."; +export interface ResponseBodyDiff { + added: FernRegistry.ResponseBodyParameter[]; + removed: FernRegistry.ResponseBodyParameter[]; +} diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/ResponseBodyDiff.js b/servers/fdr/src/api/generated/api/resources/diff/types/ResponseBodyDiff.js new file mode 100644 index 0000000000..0b46289f5b --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/ResponseBodyDiff.js @@ -0,0 +1,4 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +export {}; diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/ResponseBodyParameter.d.ts b/servers/fdr/src/api/generated/api/resources/diff/types/ResponseBodyParameter.d.ts new file mode 100644 index 0000000000..eb8adc48fd --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/ResponseBodyParameter.d.ts @@ -0,0 +1,6 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +export interface ResponseBodyParameter { + wireKey: string; +} diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/ResponseBodyParameter.js b/servers/fdr/src/api/generated/api/resources/diff/types/ResponseBodyParameter.js new file mode 100644 index 0000000000..0b46289f5b --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/ResponseBodyParameter.js @@ -0,0 +1,4 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +export {}; diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/index.d.ts b/servers/fdr/src/api/generated/api/resources/diff/types/index.d.ts new file mode 100644 index 0000000000..7f9eb28975 --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/index.d.ts @@ -0,0 +1,10 @@ +export * from "./ApiDiff"; +export * from "./EndpointDiff"; +export * from "./PathParameterDiff"; +export * from "./PathParameter"; +export * from "./QueryParameterDiff"; +export * from "./QueryParameter"; +export * from "./RequestBodyDiff"; +export * from "./RequestBodyParameter"; +export * from "./ResponseBodyDiff"; +export * from "./ResponseBodyParameter"; diff --git a/servers/fdr/src/api/generated/api/resources/diff/types/index.js b/servers/fdr/src/api/generated/api/resources/diff/types/index.js new file mode 100644 index 0000000000..7f9eb28975 --- /dev/null +++ b/servers/fdr/src/api/generated/api/resources/diff/types/index.js @@ -0,0 +1,10 @@ +export * from "./ApiDiff"; +export * from "./EndpointDiff"; +export * from "./PathParameterDiff"; +export * from "./PathParameter"; +export * from "./QueryParameterDiff"; +export * from "./QueryParameter"; +export * from "./RequestBodyDiff"; +export * from "./RequestBodyParameter"; +export * from "./ResponseBodyDiff"; +export * from "./ResponseBodyParameter"; diff --git a/servers/fdr/src/api/generated/api/resources/index.d.ts b/servers/fdr/src/api/generated/api/resources/index.d.ts index 78336cd3c2..1fcb565aa2 100644 --- a/servers/fdr/src/api/generated/api/resources/index.d.ts +++ b/servers/fdr/src/api/generated/api/resources/index.d.ts @@ -2,6 +2,8 @@ export * as api from "./api"; export * as docs from "./docs"; export * as commons from "./commons"; export * from "./commons/types"; +export * as diff from "./diff"; +export * from "./diff/types"; export * as snippetsFactory from "./snippetsFactory"; export * from "./snippetsFactory/types"; export * as snippets from "./snippets"; diff --git a/servers/fdr/src/api/generated/api/resources/index.js b/servers/fdr/src/api/generated/api/resources/index.js index 78336cd3c2..1fcb565aa2 100644 --- a/servers/fdr/src/api/generated/api/resources/index.js +++ b/servers/fdr/src/api/generated/api/resources/index.js @@ -2,6 +2,8 @@ export * as api from "./api"; export * as docs from "./docs"; export * as commons from "./commons"; export * from "./commons/types"; +export * as diff from "./diff"; +export * from "./diff/types"; export * as snippetsFactory from "./snippetsFactory"; export * from "./snippetsFactory/types"; export * as snippets from "./snippets"; diff --git a/servers/fdr/src/api/generated/api/resources/snippets/types/index.d.ts b/servers/fdr/src/api/generated/api/resources/snippets/types/index.d.ts index 6347c36e13..7060912125 100644 --- a/servers/fdr/src/api/generated/api/resources/snippets/types/index.d.ts +++ b/servers/fdr/src/api/generated/api/resources/snippets/types/index.d.ts @@ -1,6 +1,3 @@ -export * from "./EndpointIdentifier"; -export * from "./EndpointPath"; -export * from "./EndpointMethod"; export * from "./Sdk"; export * from "./TypeScriptSdk"; export * from "./PythonSdk"; diff --git a/servers/fdr/src/api/generated/api/resources/snippets/types/index.js b/servers/fdr/src/api/generated/api/resources/snippets/types/index.js index 6347c36e13..7060912125 100644 --- a/servers/fdr/src/api/generated/api/resources/snippets/types/index.js +++ b/servers/fdr/src/api/generated/api/resources/snippets/types/index.js @@ -1,6 +1,3 @@ -export * from "./EndpointIdentifier"; -export * from "./EndpointPath"; -export * from "./EndpointMethod"; export * from "./Sdk"; export * from "./TypeScriptSdk"; export * from "./PythonSdk"; diff --git a/servers/fdr/src/api/generated/register.d.ts b/servers/fdr/src/api/generated/register.d.ts index c373dbde94..a49142d28a 100644 --- a/servers/fdr/src/api/generated/register.d.ts +++ b/servers/fdr/src/api/generated/register.d.ts @@ -2,6 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ import express from "express"; +import { DiffService } from "./api/resources/diff/service/DiffService"; import { SnippetsFactoryService } from "./api/resources/snippetsFactory/service/SnippetsFactoryService"; import { SnippetsService } from "./api/resources/snippets/service/SnippetsService"; import { TemplatesService } from "./api/resources/templates/service/TemplatesService"; @@ -12,6 +13,7 @@ import { WriteService as docs_v1_write_RootService } from "./api/resources/docs/ import { ReadService as docs_v2_read_RootService } from "./api/resources/docs/resources/v2/resources/read/service/ReadService"; import { WriteService as docs_v2_write_RootService } from "./api/resources/docs/resources/v2/resources/write/service/WriteService"; export declare function register(expressApp: express.Express | express.Router, services: { + diff: DiffService; snippetsFactory: SnippetsFactoryService; snippets: SnippetsService; templates: TemplatesService; diff --git a/servers/fdr/src/api/generated/register.js b/servers/fdr/src/api/generated/register.js index fad0ca9d67..e6d9a3e3da 100644 --- a/servers/fdr/src/api/generated/register.js +++ b/servers/fdr/src/api/generated/register.js @@ -8,6 +8,7 @@ export function register(expressApp, services) { expressApp.use("/registry/docs", services.docs.v1.write._root.toRouter()); expressApp.use("/v2/registry/docs", services.docs.v2.read._root.toRouter()); expressApp.use("/v2/registry/docs", services.docs.v2.write._root.toRouter()); + expressApp.use("/registry", services.diff.toRouter()); expressApp.use("/snippets", services.snippetsFactory.toRouter()); expressApp.use("/snippets", services.snippets.toRouter()); expressApp.use("/snippet-template", services.templates.toRouter()); diff --git a/servers/fdr/src/api/index.ts b/servers/fdr/src/api/index.ts index 198b8deda0..439dc12fa0 100644 --- a/servers/fdr/src/api/index.ts +++ b/servers/fdr/src/api/index.ts @@ -16,4 +16,5 @@ export { WriteService as DocsV2WriteService } from "./generated/api/resources/do export { SnippetsService } from "./generated/api/resources/snippets/service/SnippetsService"; export { SnippetsFactoryService } from "./generated/api/resources/snippetsFactory/service/SnippetsFactoryService"; export { TemplatesService } from "./generated/api/resources/templates/service/TemplatesService"; +export { DiffService } from "./generated/api/resources/diff/service/DiffService"; export { register } from "./generated/register"; diff --git a/servers/fdr/src/controllers/diff/getApiDiffService.ts b/servers/fdr/src/controllers/diff/getApiDiffService.ts new file mode 100644 index 0000000000..51d4aa377d --- /dev/null +++ b/servers/fdr/src/controllers/diff/getApiDiffService.ts @@ -0,0 +1,86 @@ +import { APIV1Db, APIV1Read, DiffService, FdrAPI } from "../../api"; +import { type FdrApplication } from "../../app"; + +export function getApiDiffService(app: FdrApplication): DiffService { + return new DiffService({ + diff: async (req, res) => { + const previous = await app.dao.apis().loadAPIDefinition(req.query.previousApiDefinitionId); + const current = await app.dao.apis().loadAPIDefinition(req.query.currentApiDefinitionId); + + if (!previous || !current) { + throw new APIV1Read.ApiDoesNotExistError(); + } + + const previousEndpoints = getEndpoints(previous); + const currentEndpoints = getEndpoints(current); + + const visitedEndpoints: Set = new Set(); + const endpointDiffs: FdrAPI.EndpointDiff[] = []; + for (const [endpointId, currentEndpoint] of Object.entries(currentEndpoints)) { + const previousEndpoint = previousEndpoints[endpointId]; + if (previousEndpoint == null) { + // TODO: Handle new endpoint + continue; + } else { + const endpointDiff: FdrAPI.EndpointDiff = { + id: { + method: currentEndpoint.method, + path: getEndpointPath(currentEndpoint), + }, + pathParameterDiff: { + added: [], + removed: [], + }, + queryParameterDiff: { + added: [], + removed: [], + }, + requestBodyDiff: { + added: [], + removed: [], + }, + responseBodyDiff: { + added: [], + removed: [], + }, + }; + endpointDiffs.push(endpointDiff); + } + visitedEndpoints.add(endpointId); + } + return res.send({ + endpointDiffs, + }); + }, + }); +} + +function getEndpoints(apiDefinition: APIV1Db.DbApiDefinition): Record { + const endpoints: Record = {}; + apiDefinition.rootPackage.endpoints.forEach((endpoint) => { + endpoints[getEndpointId(endpoint)] = endpoint; + }); + Object.values(apiDefinition.subpackages).forEach((subpackage) => { + subpackage.endpoints.forEach((endpoint) => { + endpoints[getEndpointId(endpoint)] = endpoint; + }); + }); + return endpoints; +} + +function getEndpointId(endpoint: APIV1Db.DbEndpointDefinition): string { + const path = getEndpointPath(endpoint); + return `${endpoint.method}_${path}`; +} + +function getEndpointPath(endpoint: APIV1Db.DbEndpointDefinition): string { + let path = ""; + for (const part of endpoint.path.parts) { + if (part.type === "literal") { + path += part.value; + } else { + path += `{${part.value}}`; + } + } + return path; +} diff --git a/servers/fdr/src/server.ts b/servers/fdr/src/server.ts index 9569bf5f89..42ba3af80d 100644 --- a/servers/fdr/src/server.ts +++ b/servers/fdr/src/server.ts @@ -8,6 +8,7 @@ import { FdrApplication, getConfig } from "./app"; import { registerBackgroundTasks } from "./background"; import { getReadApiService } from "./controllers/api/getApiReadService"; import { getRegisterApiService } from "./controllers/api/getRegisterApiService"; +import { getApiDiffService } from "./controllers/diff/getApiDiffService"; import { getDocsReadService } from "./controllers/docs/v1/getDocsReadService"; import { getDocsWriteService } from "./controllers/docs/v1/getDocsWriteService"; import { getDocsReadV2Service } from "./controllers/docs/v2/getDocsReadV2Service"; @@ -88,6 +89,7 @@ try { snippets: getSnippetsService(app), snippetsFactory: getSnippetsFactoryService(app), templates: getTemplatesService(app), + diff: getApiDiffService(app), }); registerBackgroundTasks(app); app.logger.info(`Listening for requests on port ${PORT}`);