-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JS route with external dependency to example app
This allows testing that API routes written with JS are also supported and that 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 5e3e980
Showing
9 changed files
with
290 additions
and
4 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
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,13 @@ | ||
import { route, routeOperation } from 'next-rest-framework'; | ||
import { JSDOM } from 'jsdom'; | ||
|
||
export const runtime = 'edge'; | ||
|
||
export const { GET } = route({ | ||
jsEndpoint: routeOperation({ | ||
method: 'GET' | ||
}).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,11 @@ | ||
import { apiRoute, apiRouteOperation } from 'next-rest-framework'; | ||
import { JSDOM } from 'jsdom'; | ||
|
||
export default apiRoute({ | ||
jsEndpoint: apiRouteOperation({ | ||
method: 'GET' | ||
}).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.