From aefe15e8ed26a5f7f033e4ae7517aaff4ed20498 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sun, 25 Sep 2022 17:31:32 +0200 Subject: [PATCH] generate OpenAPI spec for v2 endpoints --- packages/backend/src/server/api/openapi/gen-spec.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/backend/src/server/api/openapi/gen-spec.ts b/packages/backend/src/server/api/openapi/gen-spec.ts index 9902dfa6c..565269e3f 100644 --- a/packages/backend/src/server/api/openapi/gen-spec.ts +++ b/packages/backend/src/server/api/openapi/gen-spec.ts @@ -203,6 +203,18 @@ export function genOpenapiSpec() { } spec.paths['/' + endpoint.name] = path; + + if (endpoint.meta.v2) { + // we need a clone of the API endpoint info because otherwise we change it by reference + const infoClone = JSON.parse(JSON.stringify(info)); + const route = `/v2/${endpoint.meta.v2.alias ?? endpoint.name.replace(/-/g, '_')}`; + + infoClone['operationId'] = infoClone['summary'] = route; + + spec.paths[route] = { + [endpoint.meta.v2.method]: infoClone, + }; + } } return spec;