@jambff/oac
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "@jambff/oac", | ||
"description": "A JavaScript OpenAPI client generator.", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": "Alex Mendes", | ||
@@ -42,2 +42,3 @@ "license": "MIT", | ||
"jwt-decode": "^3.1.2", | ||
"node-fetch": "^2.6.1", | ||
"openapi-types": "^11.0.0", | ||
@@ -44,0 +45,0 @@ "openapi-typescript": "^4.0.0", |
@@ -11,3 +11,3 @@ # OAC | ||
- [Usage](#usage) | ||
- [Models](#models) | ||
- [Typescript](#typescript) | ||
- [Authorization](#authorization) | ||
@@ -38,2 +38,8 @@ - [Error handling](#error-handling) | ||
```text | ||
yarn oac http://example.api.com/docs.json | ||
``` | ||
Alternatively, you can use a JSON file: | ||
```text | ||
yarn oac -f spec.json | ||
@@ -154,11 +160,30 @@ ``` | ||
## Models | ||
## Typescript | ||
You can import TypeScript interfaces generated from the API server models via | ||
`ApiModels`, for example: | ||
Two types are generated for each API operation. One for the options | ||
(`params`, `query` and `data`) and one for the response, for example: | ||
```js | ||
import { | ||
createOpenApiClient, | ||
MyExampleOptions, | ||
MyExampleResponse, | ||
} from '@jambff/oac'; | ||
const client = createOpenApiClient({ baseUrl: 'http://example.api.com' }); | ||
export const getMyExample = ( | ||
options: MyExampleOptions | ||
): MyExampleResponse => ( | ||
client.myExampleOperation(options) | ||
); | ||
``` | ||
Types are also generated for each [OpenAPI component](https://swagger.io/docs/specification/components/) | ||
present in your specification. These can be imported from `ApiComponents`, for example: | ||
```ts | ||
import { ApiModels } from '@jambff/client'; | ||
import { ApiComponents } from '@jambff/oac'; | ||
const post: ApiModels['Post'] = { | ||
const post: ApiComponents['Post'] = { | ||
title: 'My Post', | ||
@@ -165,0 +190,0 @@ }; |
@@ -9,2 +9,2 @@ // @ts-ignore | ||
export type ApiModels = components['schemas']; | ||
export type ApiComponents = components['schemas']; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20870
249
13
+ Addednode-fetch@^2.6.1