Skip to content

Commit

Permalink
Merge pull request #30 from lifeomic/require-class-name
Browse files Browse the repository at this point in the history
fix!: require name parameter in generate-axios-client
  • Loading branch information
swain authored Jun 6, 2022
2 parents 8b71077 + b430b4e commit ce5ac92
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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',
Expand Down
5 changes: 2 additions & 3 deletions src/bin/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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"
`;
6 changes: 3 additions & 3 deletions src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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, {
Expand Down

0 comments on commit ce5ac92

Please sign in to comment.