From b430b4ebbdb04b8d4bb37d081d69d6316dfb4b76 Mon Sep 17 00:00:00 2001 From: Swain Molster Date: Mon, 6 Jun 2022 12:14:18 -0400 Subject: [PATCH] fix!: require name parameter in generate-axios-client --- README.md | 5 +++-- src/bin/__snapshots__/cli.test.ts.snap | 5 ++--- src/bin/cli.ts | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a5a68d1..8b26caa 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,7 @@ Then, use the `generate-axios-client` command to generate a nicely typed Axios-b one-schema generate-axios-client \ --schema src/schemas/my-service.json \ --output generated-client.ts \ + --name MyService \ --format ``` @@ -172,10 +173,10 @@ How to use the generated client: ```typescript import axios from 'axios'; -import { Client } from './generated-client'; +import { MyService } from './generated-client'; // Provide any AxiosInstance, customized to your needs. -const client = new Client(axios.create({ baseURL: 'https://my.api.com/' })); +const client = new MyService(axios.create({ baseURL: 'https://my.api.com/' })); const response = await client.createPost({ message: 'some-message', diff --git a/src/bin/__snapshots__/cli.test.ts.snap b/src/bin/__snapshots__/cli.test.ts.snap index 0497b9b..820015b 100644 --- a/src/bin/__snapshots__/cli.test.ts.snap +++ b/src/bin/__snapshots__/cli.test.ts.snap @@ -76,8 +76,7 @@ Options: 'none', or a comma-separated list containing one or more of: noAdditionalPropertiesOnObjects, objectPropertiesRequiredByDefault [string] [default: \\"all\\"] - --className The name of the generated client class. - [string] [default: \\"Client\\"] + --name The name of the generated client class. [string] [required] -Missing required arguments: schema, output" +Missing required arguments: schema, output, name" `; diff --git a/src/bin/cli.ts b/src/bin/cli.ts index 62ea3e5..2684bac 100644 --- a/src/bin/cli.ts +++ b/src/bin/cli.ts @@ -110,10 +110,10 @@ const program = yargs(process.argv.slice(2)) 'generate-axios-client', 'Generates an Axios client using the specified schema and options.', (y) => - getCommonOptions(y).option('className', { + getCommonOptions(y).option('name', { type: 'string', description: 'The name of the generated client class.', - default: 'Client', + demandOption: true, }), async (argv) => { const spec = loadSchemaFromFile( @@ -122,7 +122,7 @@ const program = yargs(process.argv.slice(2)) ); const output = await generateAxiosClient({ spec, - outputClass: argv.className, + outputClass: argv.name, }); writeGeneratedFile(argv.output.replace('.ts', '.js'), output.javascript, {