@@ -41,6 +41,7 @@ $ openapi --help
4141 -i, --input <value> OpenAPI specification, can be a path, url or string content (required)
4242 -o, --output <value> Output directory (required)
4343 -c, --client <value> HTTP client to generate [fetch, xhr, axios, node] (default: "fetch")
44+ --name <value> Custom client class name
4445 --useOptions Use options instead of arguments
4546 --useUnionTypes Use union types instead of enums
4647 --exportCore <value> Write core files to disk (default: true)
@@ -96,6 +97,33 @@ OpenAPI.generate({
9697
9798## Features
9899
100+
101+ ### Generate client instance with ` --name ` option
102+ The OpenAPI generator allows creation of client instances to support the multiple backend services use case.
103+ The generated client uses an instance of the server configuration and not the global ` OpenAPI ` constant.
104+ To generate a client instance, set a custom name to the client class, use ` --name ` option.
105+
106+ ```
107+ openapi --input ./spec.json --output ./dist ---name AppClient
108+ ```
109+
110+ The generated client will be exported from the ` index ` file and can be used as shown below:
111+
112+ ``` typescript
113+ // Create the client instance with server and authentication details
114+ const appClient = new AppClient ({
115+ BASE: ' http://server-host.com' ,
116+ TOKEN: ' 1234'
117+ });
118+
119+ // Use the client instance to make the API call
120+ const res = await appClient .organizations .createOrganization ({
121+ name: ' OrgName' ,
122+ description: ' OrgDescription' ,
123+ });
124+ ```
125+
126+
99127### Argument style vs. Object style ` --useOptions `
100128There's no [ named parameter] ( https://en.wikipedia.org/wiki/Named_parameter ) in JavaScript or TypeScript, because of
101129that, we offer the flag ` --useOptions ` to generate code in two different styles.
0 commit comments