-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove CLI ESBuild step This fix aims to address various ESBuild issues of users by removing the ESBuild step from the CLI commands and parsing parsing the OpenAPI spec directly from TS/JS files without any build step by using tsx. The `generate` and `validate` functions are now also exposed as entry points for the ESBuild output, allowing those functions to be used for custom CLIs. * Add routes with external dependency to example app This allows testing that API routes with third-party dependencies like JSDom don't cause issues in the OpenAPI generation. This commit also adds an example on writing custom scripts for generating/validating the OpenAPI spec. The deep object comparison as part of the OpenAPI generation/validation is also replaced with a faster stringified comparison between the generated and existing OpenAPI specs. Co-authored-by: Austin Kelleher <[email protected]> --------- Co-authored-by: Austin Kelleher <[email protected]>
- Loading branch information
1 parent
19e5e38
commit 509fa3a
Showing
18 changed files
with
476 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
apps/example/src/app/api/v2/route-with-external-dep/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { TypedNextResponse, route, routeOperation } from 'next-rest-framework'; | ||
import { JSDOM } from 'jsdom'; | ||
import { z } from 'zod'; | ||
|
||
export const { GET } = route({ | ||
routeWithExternalDep: routeOperation({ | ||
method: 'GET' | ||
}) | ||
.outputs([ | ||
{ | ||
contentType: 'text/html', | ||
status: 200, | ||
body: z.string() | ||
} | ||
]) | ||
.handler(() => { | ||
const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>'); | ||
|
||
return new TypedNextResponse(dom.serialize(), { | ||
headers: { 'Content-Type': 'text/html' } | ||
}); | ||
}) | ||
}); |
21 changes: 21 additions & 0 deletions
21
apps/example/src/pages/api/v1/route-with-external-dep/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { apiRoute, apiRouteOperation } from 'next-rest-framework'; | ||
import { JSDOM } from 'jsdom'; | ||
import { z } from 'zod'; | ||
|
||
export default apiRoute({ | ||
routeWithExternalDep: apiRouteOperation({ | ||
method: 'GET' | ||
}) | ||
.outputs([ | ||
{ | ||
contentType: 'text/html', | ||
status: 200, | ||
body: z.string() | ||
} | ||
]) | ||
.handler((_req, res) => { | ||
const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>'); | ||
res.setHeader('Content-Type', 'text/html'); | ||
res.send(dom.serialize()); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { generate } from 'next-rest-framework/dist/cli/generate'; | ||
|
||
generate({ configPath: '/api/v2' }) | ||
.then(() => { | ||
console.log('Completed building OpenAPI schema from custom script.'); | ||
}) | ||
.catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { validate } from 'next-rest-framework/dist/cli/validate'; | ||
|
||
validate({ configPath: '/api/v2' }) | ||
.then(() => { | ||
console.log('Completed validating OpenAPI schema from custom script.'); | ||
}) | ||
.catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export const OPEN_API_VERSION = '3.0.1'; | ||
export const NEXT_REST_FRAMEWORK_TEMP_FOLDER_NAME = '.next-rest-framework'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.