move generated spec file to generated folder and enforce client import

Signed-off-by: Aramis Sennyey <159921952+aramissennyeydd@users.noreply.github.com>
Signed-off-by: aramissennyeydd <aramis.sennyey@doordash.com>
This commit is contained in:
Aramis Sennyey
2024-04-01 19:09:37 -04:00
committed by aramissennyeydd
parent f70da0db54
commit 9cf8209799
6 changed files with 19 additions and 8 deletions
@@ -15,15 +15,15 @@
*/
import chalk from 'chalk';
import { resolve } from 'path';
import { resolve, dirname } from 'path';
import YAML from 'js-yaml';
import {
OLD_SCHEMA_PATH,
OPENAPI_IGNORE_FILES,
OUTPUT_PATH,
TS_SCHEMA_PATH,
} from '../../../../../lib/openapi/constants';
import { paths as cliPaths } from '../../../../../lib/paths';
import { mkdirpSync } from 'fs-extra';
import fs from 'fs-extra';
import { exec } from '../../../../../lib/exec';
import { resolvePackagePath } from '@backstage/backend-common';
@@ -38,6 +38,14 @@ async function generateSpecFile() {
const tsPath = cliPaths.resolveTarget(TS_SCHEMA_PATH);
await fs.mkdirp(dirname(tsPath));
const oldTsPath = cliPaths.resolveTarget(OLD_SCHEMA_PATH);
if (oldTsPath) {
console.warn(`Removing old schema file at ${oldTsPath}`);
fs.removeSync(oldTsPath);
}
// The first set of comment slashes allow for the eslint notice plugin to run
// with onNonMatchingHeader: 'replace', as is the case in the open source
// Backstage repo. Otherwise the auto-generated comment will be removed by the
@@ -50,7 +58,7 @@ async function generateSpecFile() {
// * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. *
// ******************************************************************
import {createValidatedOpenApiRouterFromGeneratedEndpointMap} from '@backstage/backend-openapi-utils';
import {EndpointMap} from '../generated';
import {EndpointMap} from './';
export const spec = ${JSON.stringify(yaml, null, 2)} as const;
export const createOpenApiRouter = async (
options?: Parameters<typeof createValidatedOpenApiRouterFromGeneratedEndpointMap>['1'],
@@ -69,7 +77,6 @@ export const createOpenApiRouter = async (
async function generate(abortSignal?: AbortController) {
const resolvedOpenapiPath = await getPathToCurrentOpenApiSpec();
const resolvedOutputDirectory = await getRelativePathToFile(OUTPUT_PATH);
mkdirpSync(resolvedOutputDirectory);
await fs.mkdirp(resolvedOutputDirectory);
@@ -16,7 +16,9 @@
export const YAML_SCHEMA_PATH = 'src/schema/openapi.yaml';
export const TS_MODULE = 'src/schema/openapi.generated';
export const TS_MODULE = 'src/generated/router';
export const OLD_SCHEMA_PATH = `src/schema/openapi.generated.ts`;
export const TS_SCHEMA_PATH = `${TS_MODULE}.ts`;
@@ -1,3 +1,4 @@
//
export * from './apis';
export * from './apis';
export * from './router';
@@ -15,3 +15,4 @@
*/
export * from './apis';
export * from './router';
@@ -18,7 +18,7 @@
// * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. *
// ******************************************************************
import { createValidatedOpenApiRouterFromGeneratedEndpointMap } from '@backstage/backend-openapi-utils';
import { EndpointMap } from '../generated';
import { EndpointMap } from './';
export const spec = {
openapi: '3.0.3',
@@ -46,7 +46,7 @@ import {
locationInput,
validateRequestBody,
} from './util';
import { createOpenApiRouter } from '../schema/openapi.generated';
import { createOpenApiRouter } from '../generated';
import { parseEntityPaginationParams } from './request/parseEntityPaginationParams';
import {
AuthService,