-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: experimental typescript-nextjs template #152
base: main
Are you sure you want to change the base?
Conversation
54335e8
to
3033f06
Compare
adds https://github.com/mnahkies/openapi-code-generator/ / https://openapi-code-generator.nahkies.co.nz/ to the list. it currently supports generating typescript client sdks based on fetch / axios, and server routing / request+response validation based on koa (choice of zod / joi for runtime validation). an experimental nextjs server implementation is in the works (mnahkies/openapi-code-generator#152), and my longer term plan is to add other languages such as kotlin to the set of templates.
3033f06
to
58f706b
Compare
fd15300
to
258f9ab
Compare
258f9ab
to
aedad74
Compare
paths.includes(relative), | ||
) | ||
|
||
return alias ? alias[0].replace("*", "") : undefined |
Check failure
Code scanning / CodeQL
Incomplete string escaping or encoding High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 2 months ago
To fix the problem, we need to ensure that all occurrences of the asterisk (*
) are replaced in the string. This can be achieved by using a regular expression with the global flag (g
). This change will ensure that all instances of the asterisk are replaced, not just the first one.
The specific change will be made in the findImportAlias
function, where the replace
method is used. We will replace the current replace
call with a call to replace
that uses a regular expression with the global flag.
-
Copy modified line R469
@@ -468,3 +468,3 @@ | ||
|
||
return alias ? alias[0].replace("*", "") : undefined | ||
return alias ? alias[0].replace(/\*/g, "") : undefined | ||
} |
Creates a new
typescript-nextjs
template./src/generated
containing the types and validation boilerplateApproach
Due to the NextJS file based routing paradigm I couldn't see anyway to avoid manipulating files that will contain manually written code.
Pending Refactoring
Currently there is a lot of duplicated code between this and the
typescript-koa
template which needs rationalizing, as well as it depending on thetypescript-koa-runtime
package. Part of the motivation behind this is to have more than one server template to allow it to become more generic like the client templates.Because of the
typescript-koa-runtime
hack, to actually use this in a NextJS application you need to add the following to yournext.config.mjs
:I also don't love the explosion of files this creates when running the standard set of integration suites, and might limit the scope down to one spec to reduce the noise. Ideally I'd like to separate the integration tests to their own repo and also start testing more permutations of options (eg:
joi
,extract-inline-schemas
).Additionally to make multiple suites play nicely I've had to fudge the output paths in the tests, technically producing incorrect routes.
Performance
I've been told that
ts-morph
can be relatively slow, so it's probably useful to check the performance between this andtypescript-koa
Overall it looks similar, aside from calculation of the dependency graph. I'm not sure if this is the bug in the timing code, or if the larger number of compilation units is somehow causing this. Warrants some investigation in case we're calculating it repeatedly or something.
typescript-nextjs - api.github.com.yaml
typescript-koa - api.github.com.yaml