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, {