-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
2f09414
commit 26cac4f
Showing
9 changed files
with
373 additions
and
8 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
21 changes: 21 additions & 0 deletions
21
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,21 @@ | ||
import { route, routeOperation } from 'next-rest-framework'; | ||
import { JSDOM } from 'jsdom'; | ||
import { NextResponse } from 'next/server'; | ||
import { z } from 'zod'; | ||
|
||
export const { GET } = route({ | ||
routeWithExternalDep: routeOperation({ | ||
method: 'GET' | ||
}) | ||
.outputs([ | ||
{ | ||
contentType: 'application/json', | ||
status: 200, | ||
body: z.custom<JSDOM>() | ||
} | ||
]) | ||
.handler(() => { | ||
const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>'); | ||
return NextResponse.json(dom); | ||
}) | ||
}); |
20 changes: 20 additions & 0 deletions
20
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,20 @@ | ||
import { apiRoute, apiRouteOperation } from 'next-rest-framework'; | ||
import { JSDOM } from 'jsdom'; | ||
import { z } from 'zod'; | ||
|
||
export default apiRoute({ | ||
routeWithExternalDep: apiRouteOperation({ | ||
method: 'GET' | ||
}) | ||
.outputs([ | ||
{ | ||
contentType: 'application/json', | ||
status: 200, | ||
body: z.custom<JSDOM>() | ||
} | ||
]) | ||
.handler((_req, res) => { | ||
const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>'); | ||
res.json(dom); | ||
}) | ||
}); |
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
Oops, something went wrong.