From 68dda8c04831800302b97a2ad44328833159a8d9 Mon Sep 17 00:00:00 2001 From: aramissennyeydd Date: Tue, 15 Oct 2024 20:34:54 -0400 Subject: [PATCH] address PR feedback Signed-off-by: aramissennyeydd --- .changeset/fair-buttons-divide.md | 5 --- .changeset/healthy-parents-enjoy.md | 5 --- .changeset/wet-hairs-pretend.md | 5 --- docs/openapi/generate-client.md | 43 ++----------------- packages/catalog-client/src/CatalogClient.ts | 2 +- .../src/schema/openapi/index.ts | 17 ++++++++ .../package/schema/openapi/generate/client.ts | 16 ++++--- 7 files changed, 32 insertions(+), 61 deletions(-) delete mode 100644 .changeset/fair-buttons-divide.md delete mode 100644 .changeset/healthy-parents-enjoy.md delete mode 100644 .changeset/wet-hairs-pretend.md create mode 100644 packages/catalog-client/src/schema/openapi/index.ts diff --git a/.changeset/fair-buttons-divide.md b/.changeset/fair-buttons-divide.md deleted file mode 100644 index 873610794c..0000000000 --- a/.changeset/fair-buttons-divide.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@backstage/plugin-search-common': minor ---- - -Adds a new export for the generated client, `@backstage/plugin-search-common/client`. diff --git a/.changeset/healthy-parents-enjoy.md b/.changeset/healthy-parents-enjoy.md deleted file mode 100644 index 8e7157fadd..0000000000 --- a/.changeset/healthy-parents-enjoy.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@backstage/catalog-client': patch ---- - -Moving the generated types to `@backstage/plugin-catalog-common`. diff --git a/.changeset/wet-hairs-pretend.md b/.changeset/wet-hairs-pretend.md deleted file mode 100644 index bd2c3b9af9..0000000000 --- a/.changeset/wet-hairs-pretend.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@backstage/plugin-catalog-common': minor ---- - -Moved the OpenAPI generated client from `@backstage/catalog-client` to this package. Use `@backstage/plugin-catalog-common/client` to directly access it. diff --git a/docs/openapi/generate-client.md b/docs/openapi/generate-client.md index 01e876a82a..29756dcad2 100644 --- a/docs/openapi/generate-client.md +++ b/docs/openapi/generate-client.md @@ -20,44 +20,7 @@ info: ### Generating your client -1. Run `yarn backstage-repo-tools package schema openapi generate --client-package `. This will create a new folder in `/src/schema/openapi/generated` to house the generated content. We recommend that the client package be your plugin's common package. You should then add a new entry point into the package so that the generated content can be accessed like so, `-common/client`. To do that, adjust your `package.json` like so, - -```json - // ... other scripts - - "exports": { - ".": "./src/index.ts", - "./alpha": "./src/alpha.ts", - // highlight-add-next-line - "./client": "./src/client.ts", - "./package.json": "./package.json" - }, - - "typesVersions": { - "*": { - "alpha": [ - "src/alpha.ts" - ], - // highlight-start - "client": [ - "src/client.ts" - ], - // highlight-end - "package.json": [ - "package.json" - ] - } - }, - - // ... other stuff -``` - -and then create a new `src/client.ts` with the following content, - -```ts name="src/client.ts" -export * from './schema/openapi/generated'; -``` - +1. Run `yarn backstage-repo-tools package schema openapi generate --client-package `. This will create a new folder in `/src/schema/openapi/generated` to house the generated content. 2. You should not need to import anything from subfolders of the `src/schema/openapi/generated` parent folder, everything you should require will be accessible from the `src/schema/openapi/generated/index.ts` file. Of note, -1. `DefaultApiClient` - this is the client that you can use to access your specific spec. -1. Any request or response types - these will be available from the index and should match the names in your spec. +3. `DefaultApiClient` - this is the client that you can use to access your specific spec. +4. Any request or response types - these will be available from the index and should match the names in your spec. diff --git a/packages/catalog-client/src/CatalogClient.ts b/packages/catalog-client/src/CatalogClient.ts index ed5b3c049f..8054063c0b 100644 --- a/packages/catalog-client/src/CatalogClient.ts +++ b/packages/catalog-client/src/CatalogClient.ts @@ -42,7 +42,7 @@ import { ValidateEntityResponse, } from './types/api'; import { isQueryEntitiesInitialRequest, splitRefsIntoChunks } from './utils'; -import { DefaultApiClient, TypedResponse } from './schema/openapi/generated'; +import { DefaultApiClient, TypedResponse } from './schema/openapi'; /** * A frontend and backend compatible client for communicating with the Backstage diff --git a/packages/catalog-client/src/schema/openapi/index.ts b/packages/catalog-client/src/schema/openapi/index.ts new file mode 100644 index 0000000000..db98243cbf --- /dev/null +++ b/packages/catalog-client/src/schema/openapi/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './generated'; diff --git a/packages/repo-tools/src/commands/package/schema/openapi/generate/client.ts b/packages/repo-tools/src/commands/package/schema/openapi/generate/client.ts index 1dd38eb6c5..bd8ff8530e 100644 --- a/packages/repo-tools/src/commands/package/schema/openapi/generate/client.ts +++ b/packages/repo-tools/src/commands/package/schema/openapi/generate/client.ts @@ -79,15 +79,21 @@ async function generate( }, ); - await exec( - `yarn backstage-cli package lint --fix ${resolvedOutputDirectory}`, - [], - { signal: abortSignal?.signal }, + const parentDirectory = resolve(resolvedOutputDirectory, '..'); + + await fs.writeFile( + resolve(parentDirectory, 'index.ts'), + `// + export * from './generated';`, ); + await exec(`yarn backstage-cli package lint --fix ${parentDirectory}`, [], { + signal: abortSignal?.signal, + }); + const prettier = cliPaths.resolveTargetRoot('node_modules/.bin/prettier'); if (prettier) { - await exec(`${prettier} --write ${resolvedOutputDirectory}`, [], { + await exec(`${prettier} --write ${parentDirectory}`, [], { signal: abortSignal?.signal, }); }