15
15
- Quick, lightweight, robust and framework-agnostic 🚀
16
16
- Supports generation of TypeScript clients
17
17
- Supports generations of [ Axios] ( #axios-support ) client
18
- - Supports OpenAPI specification v2.0 and v3.0
18
+ - Supports OpenAPI specification v3.0
19
19
- Supports JSON and YAML files for input
20
20
- Supports generation through CLI, Node.js and NPX
21
21
- Supports tsc and @babel/plugin-transform-typescript
@@ -40,7 +40,7 @@ $ openapi --help
40
40
-V, --version output the version number
41
41
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
42
42
-o, --output <value> Output directory (required)
43
- -c, --client <value> HTTP client to generate [fetch, xhr, axios, node ] (default: "fetch ")
43
+ -c, --client <value> HTTP client to generate [axios] (default: "axios ")
44
44
--useOptions Use options instead of arguments
45
45
--useUnionTypes Use union types instead of enums
46
46
--exportCore <value> Write core files to disk (default: true)
@@ -56,7 +56,7 @@ $ openapi --help
56
56
Examples
57
57
$ openapi --input ./spec.json
58
58
$ openapi --input ./spec.json --output ./dist
59
- $ openapi --input ./spec.json --output ./dist --client xhr
59
+ $ openapi --input ./spec.json --output ./dist --client axios
60
60
```
61
61
62
62
@@ -336,34 +336,6 @@ enum EnumWithStrings {
336
336
}
337
337
```
338
338
339
-
340
- ### Nullable in OpenAPI v2
341
- In the OpenAPI v3 spec you can create properties that can be NULL, by providing a ` nullable: true ` in your schema.
342
- However, the v2 spec does not allow you to do this. You can use the unofficial ` x-nullable ` in your specification
343
- to generate nullable properties in OpenApi v2.
344
-
345
- ``` json
346
- {
347
- "ModelWithNullableString" : {
348
- "required" : [" requiredProp" ],
349
- "description" : " This is a model with one string property" ,
350
- "type" : " object" ,
351
- "properties" : {
352
- "prop" : {
353
- "description" : " This is a simple string property" ,
354
- "type" : " string" ,
355
- "x-nullable" : true
356
- },
357
- "requiredProp" : {
358
- "description" : " This is a simple string property" ,
359
- "type" : " string" ,
360
- "x-nullable" : true
361
- }
362
- }
363
- }
364
- }
365
- ```
366
-
367
339
Generated code:
368
340
``` typescript
369
341
interface ModelWithNullableString {
@@ -372,31 +344,6 @@ interface ModelWithNullableString {
372
344
}
373
345
```
374
346
375
-
376
- ### Authorization
377
- The OpenAPI generator supports Bearer Token authorization. In order to enable the sending
378
- of tokens in each request you can set the token using the global OpenAPI configuration:
379
-
380
- ``` typescript
381
- import { OpenAPI } from ' ./generated' ;
382
-
383
- OpenAPI .TOKEN = ' some-bearer-token' ;
384
- ```
385
-
386
- Alternatively, we also support an async method that provides the token for each request.
387
- You can simply assign this method to the same ` TOKEN ` property in the global OpenAPI object.
388
-
389
- ``` typescript
390
- import { OpenAPI } from ' ./generated' ;
391
-
392
- const getToken = async () => {
393
- // Some code that requests a token...
394
- return ' SOME_TOKEN' ;
395
- }
396
-
397
- OpenAPI .TOKEN = getToken ;
398
- ```
399
-
400
347
### Generate client instance with ` --exportClient ` option
401
348
402
349
The OpenAPI generator allows to create client instances to support the multiple backend services use case.
@@ -411,7 +358,7 @@ openapi --input ./spec.json --output ./dist --exportClient true --name DemoAppCl
411
358
The generated client will be exported from the ` index ` file and can be used as shown below:
412
359
``` typescript
413
360
// create the client instance with server and authentication details
414
- const appClient = new DemoAppClient ({ base: ' http://server-host.com ' , token: ' 1234' });
361
+ const appClient = new DemoAppClient ({ token: ' 1234' });
415
362
416
363
// use the client instance to make the API call
417
364
const res: OrganizationResponse = await appClient .organizations .createOrganization ({
@@ -420,6 +367,11 @@ const res: OrganizationResponse = await appClient.organizations.createOrganizati
420
367
});
421
368
```
422
369
370
+ ``` typescript
371
+ // NODE.JS Only. You can provide AccountSid and AuthToken instead.
372
+ const appClient = new DemoAppClient ({ accountSid: ' ACXXX' , authToken: " 1234" });
373
+ ```
374
+
423
375
### References
424
376
425
377
Local references to schema definitions (those beginning with ` #/definitions/schemas/ ` )
0 commit comments