yarn add --dev @ericwooley/openapi-sdk
or
npm i --dev @ericwooley/openapi-sdk
Create packages that automatically generate a typescript sdk from an open api spec.
For example, if you wanted to generate an sdk for you auth service:
nx g @ericwooley/openapi-sdk:openapi-sdk auth-sdk
Would create lib/auth-sdk
. Inside lib/auth-sdk
, is a new file openapi.yml. Replace the contents of openapi.yml
, with your spec. Then run:
nx digest auth-sdk
You will now have a src folder inside lib/auth-sdk
, it is generated code, but it's recommended that you commit it.
sdk
contains the TS code to interact with your api.
import { DefaultApi } from '@myorg/auth-sdk`
const authApi = new DefaultApi({
basePath: 'http://localhost:8080/auth',
baseOptions: {
withCredentials: true,
},
})
If you want to use the doc with some swagger tools:
import express from 'express'
import swaggerUi from 'swagger-ui-express'
import { openapiDoc } from '@myorg/auth-sdk`
const app = express();
app.use('/openapi', swaggerUi.serve, swaggerUi.setup(authOpenapiDocument));
You must have java installed
This project depends on the openapi generator project, which uses java to build and sdk from an openapi spec. It is build in java, and so java is required.
Install the openapi-sdk plugin
yarn add @ericwooley/openapi-sdk --dev
or
npm i @ericwooley/openapi-sdk --save-dev
generate an sdk.
nx g @ericwooley/openapi-sdk:openapi-sdk my-sdk
In lib/my-sdk
, you will see a file: openapi.yml
Edit that file according to your openapi needs.
When you want to generate an sdk run nx digest my-sdk
and your typescript will be generated.
Unit tests are hard with these kind of projects. Schema does have some useful unit tests nx test openapi-sdk
The real testing is done by the e2e test nx e2e openapi-sdk-e2e
use ./publish.sh patch
, which will create a new release and publish it with the next
tag.
publish.sh forwards all arguments to npm version
./release.sh
will take the current version and make it the latest.
- dependencies and versions are copied from the root package.json
If anyone ends up using this, we could add more options to pass down to the openapi generator. Currently it uses typescript-axios
This project was generated using Nx.
the major versions will match the major versions of nx starting with 10. To use with nx v9, use the 0.x.x releases