This repo is to develop and test the @seriouslag/nx-openapi-ts-plugin
The package is a NX plugin that assits with the automation of generating NX projects to a workspace based off an OpenAPI spec file. Under the hood it uses @hey-api/openapi-ts to generate client code from the OpenAPI spec file.
This plugin helps generate packages to be linked correctly in the NX environment and to provide executors to update the client code when an change in the spec file is detected.
pnpm install# run the generator to generate a package
npx nx run @seriouslag/nx-openapi-ts-plugin:build && nx g @seriouslag/nx-openapi-ts-plugin:openapi-client pokemon-api --directory ./packages --scope @test-api --client @hey-api/client-fetch --spec https://raw.githubusercontent.com/seriouslag/pokemon-api-spec/refs/heads/main/spec.yaml --plugins @tanstack/react-query --private false --verbose
# Install will happen automatically after new package is generated
# runs the executor to update the generated package
npx nx run @test-api/pokemon-api:updateApi
# There will be no update since the spec is the same
# This result will be cached by nx, for a new result the API spec file must change or the `--skip-nx-cache --force` flags must be used
# to test an update: Ether change the source spec file or make a change to one of the routes paths in the cached spec file located at ./packages/pokemon-api/src/spec.yaml
# then run the executor again and you will see it recreate the client code
npx nx run @test-api/pokemon-api:updateApi --skip-nx-cache --forceAfter running the generator you will see a new package in the packages folder named pokemon-api.
To run the dev server for your app, use:
npx nx serve test-pluginTo create a production bundle:
npx nx build test-pluginTo see all available targets to run for a project, run:
npx nx show project test-pluginThese targets are either inferred automatically or defined in the project.json or package.json files.
More about running tasks in the docs »
While you could add new projects to your workspace manually, you might want to leverage Nx plugins and their code generation feature.
Use the plugin's generator to create new projects.
To generate a new application, use:
npx nx g @nx/react:app demoTo generate a new library, use:
npx nx g @nx/react:lib mylibYou can use npx nx list to get a list of installed plugins. Then, run npx nx list <plugin-name> to learn about more specific capabilities of a particular plugin. Alternatively, install Nx Console to browse plugins and generators in your IDE.
Learn more about Nx plugins » | Browse the plugin registry »
To connect to Nx Cloud, run the following command:
npx nx connectConnecting to Nx Cloud ensures a fast and scalable CI pipeline. It includes features such as:
- Remote caching
- Task distribution across multiple machines
- Automated e2e test splitting
- Task flakiness detection and rerunning
Use the following command to configure a CI workflow for your workspace:
npx nx g ci-workflowNx Console is an editor extension that enriches your developer experience. It lets you run tasks, generate code, and improves code autocompletion in your IDE. It is available for VSCode and IntelliJ.
Learn more:
- Learn more about this workspace setup
- Learn about Nx on CI
- Releasing Packages with Nx release
- What are Nx plugins?
And join the Nx community: