address PR feedback

Signed-off-by: aramissennyeydd <aramis.sennyey@doordash.com>
This commit is contained in:
aramissennyeydd
2024-10-15 20:34:54 -04:00
parent c31cd07f69
commit 68dda8c048
7 changed files with 32 additions and 61 deletions
-5
View File
@@ -1,5 +0,0 @@
---
'@backstage/plugin-search-common': minor
---
Adds a new export for the generated client, `@backstage/plugin-search-common/client`.
-5
View File
@@ -1,5 +0,0 @@
---
'@backstage/catalog-client': patch
---
Moving the generated types to `@backstage/plugin-catalog-common`.
-5
View File
@@ -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.
+3 -40
View File
@@ -20,44 +20,7 @@ info:
### Generating your client
1. Run `yarn backstage-repo-tools package schema openapi generate --client-package <directory>`. This will create a new folder in `<directory>/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, `<plugin>-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 <directory>`. This will create a new folder in `<directory>/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.
+1 -1
View File
@@ -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
@@ -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';
@@ -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,
});
}