repo-tools: add additional properties to generate command
Signed-off-by: Symbat Nurbay <symbat01011996@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/repo-tools': minor
|
||||
---
|
||||
|
||||
Add --additional-properties option to generate command to pass properties to @openapitools/openapi-generator-cli
|
||||
@@ -54,6 +54,10 @@ function registerPackageCommand(program: Command) {
|
||||
.description(
|
||||
'Command to generate a client and/or a server stub from an OpenAPI spec.',
|
||||
)
|
||||
.option('--additional-properties [properties]')
|
||||
.description(
|
||||
'Additional properties that can be passed to @openapitools/openapi-generator-cli',
|
||||
)
|
||||
.action(
|
||||
lazy(() =>
|
||||
import('./package/schema/openapi/generate').then(m => m.command),
|
||||
|
||||
@@ -27,12 +27,18 @@ import { exec } from '../../../../../lib/exec';
|
||||
import { resolvePackagePath } from '@backstage/backend-plugin-api';
|
||||
import { getPathToCurrentOpenApiSpec } from '../../../../../lib/openapi/helpers';
|
||||
|
||||
async function generate(outputDirectory: string) {
|
||||
async function generate(
|
||||
outputDirectory: string,
|
||||
additionalProperties?: string,
|
||||
) {
|
||||
const resolvedOpenapiPath = await getPathToCurrentOpenApiSpec();
|
||||
const resolvedOutputDirectory = cliPaths.resolveTargetRoot(
|
||||
outputDirectory,
|
||||
OUTPUT_PATH,
|
||||
);
|
||||
const openapiProperties = additionalProperties
|
||||
? `--additional-properties=${additionalProperties}`
|
||||
: '';
|
||||
mkdirpSync(resolvedOutputDirectory);
|
||||
|
||||
await fs.mkdirp(resolvedOutputDirectory);
|
||||
@@ -60,6 +66,7 @@ async function generate(outputDirectory: string) {
|
||||
),
|
||||
'--generator-key',
|
||||
'v3.0',
|
||||
openapiProperties,
|
||||
],
|
||||
{
|
||||
maxBuffer: Number.MAX_VALUE,
|
||||
@@ -87,9 +94,12 @@ async function generate(outputDirectory: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function command(outputPackage: string): Promise<void> {
|
||||
export async function command(
|
||||
outputPackage: string,
|
||||
additionalProperties?: string,
|
||||
): Promise<void> {
|
||||
try {
|
||||
await generate(outputPackage);
|
||||
await generate(outputPackage, additionalProperties);
|
||||
console.log(
|
||||
chalk.green(`Generated client in ${outputPackage}/${OUTPUT_PATH}`),
|
||||
);
|
||||
|
||||
@@ -26,7 +26,7 @@ export async function command(opts: OptionValues) {
|
||||
process.exit(1);
|
||||
}
|
||||
if (opts.clientPackage) {
|
||||
await generateClient(opts.clientPackage);
|
||||
await generateClient(opts.clientPackage, opts.additionalProperties);
|
||||
}
|
||||
if (opts.server) {
|
||||
await generateServer();
|
||||
|
||||
Reference in New Issue
Block a user