feat(nx-plugin): add NX Plugin with OpenAPI client generator and executor#1947
feat(nx-plugin): add NX Plugin with OpenAPI client generator and executor#1947seriouslag wants to merge 5233 commits into
Conversation
|
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
37ec549 to
d84ba4c
Compare
|
d84ba4c to
fb901bc
Compare
fb901bc to
438dac9
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1947 +/- ##
=======================================
Coverage 22.53% 22.53%
=======================================
Files 324 324
Lines 31840 31840
Branches 1232 1232
=======================================
Hits 7174 7174
Misses 24657 24657
Partials 9 9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@hey-api/client-axios
@hey-api/client-fetch
@hey-api/client-next
@hey-api/client-nuxt
@hey-api/nuxt
@hey-api/nx-plugin
@hey-api/openapi-ts
@hey-api/vite-plugin
commit: |
0a60e87 to
d4711ce
Compare
acb3de8 to
c889844
Compare
| @@ -0,0 +1,11 @@ | |||
| { | |||
There was a problem hiding this comment.
Added this file to cache builds
| function App() { | ||
| const onClick = async () => { | ||
| postFoo({ | ||
| addPet({ |
There was a problem hiding this comment.
Changed this file to use actual generated code, I was getting type errors how it was
There was a problem hiding this comment.
Sample is meant to be a playground for local development and testing. I thought I ignored it in ESLint?
There was a problem hiding this comment.
Maybe was an issue with my IDE, why not use actual code instead of adding broken imports and ignoring it with comments?
There was a problem hiding this comment.
I don't remember, I was probably testing something and didn't clean it up. It's similar to the sample snapshot script except it contains a whole app with UI. The idea is to be able to test drive the output since snapshots are never actually executed. Obviously should be way more polished!
| @@ -1,7 +1,32 @@ | |||
| // This file is auto-generated by @hey-api/openapi-ts | |||
There was a problem hiding this comment.
Ran the code gen
| "scripts": { | ||
| "build": "tsup" | ||
| }, | ||
| "exports": { |
There was a problem hiding this comment.
Was facing issues with our new configs, adding the exports and adding cjs fixed the issues,
| "default": "./dist/index.cjs" | ||
| } | ||
| }, | ||
| "./setup": "./src/setup.ts" |
There was a problem hiding this comment.
Exporting the setup file as a direct source file for other vitests to use as a setup file.
| @@ -0,0 +1,5 @@ | |||
| // FAIL LOUDLY on unhandled promise rejections / errors | |||
There was a problem hiding this comment.
Adding this file because vitest fails if an error is uncaught, but no trace is given to the logs. This change adds the trace. This will help future debugging.
| }, | ||
| }, | ||
| root, | ||
| setupFiles: ['@config/vite-base/setup'], |
There was a problem hiding this comment.
Adding our new vitest setup file with the new export path
| "tasks": { | ||
| "build": { | ||
| "cache": false, | ||
| "cache": true, |
There was a problem hiding this comment.
Enabled caching for quicker local dev
| }); | ||
| if (existsSync(v2SpecPath)) { | ||
| logger.debug(`Spec file already exists: ${v2SpecPath}`); | ||
| await writeFile(v2SpecPath, v2Spec); |
Check failure
Code scanning / CodeQL
Potential file system race condition High test
df83798 to
c527716
Compare
- fix typo in vitest.config output - change vitest.config to mts for better type support - list vite and vitest as a dep if enabled - change vitest to single fork runner - change build to only output cjs to support nx plugins - add caching and nx linking if spec file is in another project
- Replace direct mkdir calls with makeDir utility for consistent directory creation. - Update plugin handling in client generation to support additional plugins. - Modify tests and schemas to reflect changes in plugin structure and options. - Improve error handling and logging in updateApi executor. - Add formatting functionality for generated files and update README for clarity.
- Replace the existing openapi-diff dependency with api-smart-diff for improved comparison accuracy. - Add comprehensive test cases to validate spec comparison logic across various scenarios.
…verrides in package.json files to support node 18
… management - Introduce `baseTsConfigName` and `baseTsConfigPath` options in the OpenAPI client generator and update executor schemas. - Enhance README documentation to reflect new options and their usage. - Implement `getBaseTsConfigPath` utility to resolve tsconfig paths based on provided options. - Update tests to cover new tsconfig path handling logic.
- Introduce functions to standardize OpenAPI and Swagger specs, including version detection and conversion. - Implement `removeExamples` function to clean up specs before comparison, ensuring accurate diff results. - Add comprehensive tests for new functionality, covering various scenarios for OpenAPI 3.1 and Swagger 2.0 specs. - Update existing comparison logic to utilize standardized specs for improved accuracy.
… for directory creation
…t for generated files
a5eb2fa to
0613b46
Compare
|
Not dead, been using this for quite a few months, need to update with latest openapi-ts. I have an idea to infer these tasks from an openapi.config.* file in the NX project (this is how other executors work like vitest, rspack, vite, webpack, eslint, etc.) This will improve the DX and config. |
|
@seriouslag would you be interested in publishing this plugin as a part of ecosystem? We could feature it in the docs as such, so there'd be no pressure to merge it into |
|
This is exactly the plugin I've been looking for. Would love to see the inferred task support as it would make setting this up and maintaining it on a monorepo super easy. |
Hey @jinder i will look at releasing this in the coming weeks |
|
@seriouslag I've actually been playing with the plugin from your repository with inferred tasks and it works really well! My only suggestion (and change I made) was to remove the npx calls to prevent it downloading the npm packages for openapi-ts rather than using the pre-installed one. |
|
@jinder feel free to open a PR and we can start tracking issues on that repo. |
Update June 2026
I am keeping this up to date at seriouslag/openapi-ts-nx-plugin and plan to do so for the foreseeable future.
Any feature requests or notes post there.
This NX plugin will generate an NX package from an OpenAPI spec file and run the openapi-ts on the spec.
This is useful for NX projects.
Also very useful to let AI agents know how to use the plugin to automate setting up client code for an NX project.
TODO:
Stretch in this PR:
Questions:
Q: How to handle updates to the OpenAPI spec file?
A: We have added an executor and a call to each generated project. Each project can run the executor to update the spec file and regenerate the client code.
Q: How do we list the plugin in the NX plugin repository
A: https://nx.dev/extending-nx/recipes/publish-plugin#list-your-nx-plugin
Fixes: #1910
Related PRs: