-
-
Notifications
You must be signed in to change notification settings - Fork 160
feat(nx-plugin): add NX Plugin with OpenAPI client generator and executor #1947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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 ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1947 +/- ##
=======================================
Coverage 22.34% 22.34%
=======================================
Files 251 251
Lines 21026 21026
Branches 781 780 -1
=======================================
Hits 4699 4699
Misses 16321 16321
Partials 6 6
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
…ty in update-api and openapi-client
…ing script to js from ts
acb3de8
to
c889844
Compare
@@ -0,0 +1,11 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this file to cache builds
|
||
function App() { | ||
const onClick = async () => { | ||
postFoo({ | ||
addPet({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this file to use actual generated code, I was getting type errors how it was
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ran the code gen
@@ -10,6 +10,19 @@ | |||
"scripts": { | |||
"build": "tsup" | |||
}, | |||
"exports": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this file because vitest fails if an error is uncaught but no trace is given this will add that. This will help future debugging.
@@ -25,6 +25,7 @@ export function createVitestConfig( | |||
}, | |||
}, | |||
root, | |||
setupFiles: ['@config/vite-base/setup'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding our new vitest setup file with the new export path
@@ -2,7 +2,7 @@ | |||
"$schema": "./node_modules/turbo/schema.json", | |||
"tasks": { | |||
"build": { | |||
"cache": false, | |||
"cache": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
was checked
} else { | ||
logger.debug('No existing spec file found. Creating...'); | ||
} | ||
writeFileSync(absoluteExistingSpecPath, newSpecString); |
Check failure
Code scanning / CodeQL
Potential file system race condition High
was checked
df83798
to
c527716
Compare
c527716
to
ab291ee
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
ab291ee
to
395fb62
Compare
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 to fit into an NX project.
TODO:
Stretch in this PR:
Questions:
Q: How to handle when the OpenAPI spec file updates?
A: We have added an executor and a call to each generated project. Each project can run that 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: