-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from sellersindustry/103-ajv-support-on-vercel
Added AJV Support
- Loading branch information
Showing
8 changed files
with
177 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,23 @@ | ||
/* | ||
* Copyright (C) 2024 Sellers Industries, Inc. | ||
* distributed under the MIT License | ||
* | ||
* author: Evan Sellers <[email protected]> | ||
* date: Wed May 22 2024 | ||
* file: index.ts | ||
* project: SherpaJS - Module Microservice Platform | ||
* purpose: AJV Wrapper | ||
* | ||
*/ | ||
|
||
|
||
import { ValidateFunction, Schema, JSONSchemaType } from "ajv"; | ||
|
||
|
||
export function AJV<T=unknown>(schema:Schema|JSONSchemaType<T>):ValidateFunction<T> { | ||
return schema as ValidateFunction<T>; | ||
} | ||
|
||
|
||
// The grace of the Lord Jesus Christ be with your spirit. Amen. | ||
// - Philippians 4:23 |
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,17 @@ | ||
import { Request, Response, AJV } from "../../../../../index.js"; | ||
import schemaFoo from "../../src/foo.schema.json"; | ||
const validatorFoo = AJV(schemaFoo); | ||
|
||
|
||
export function POST(request:Request) { | ||
try { | ||
if (!validatorFoo(request.body)) { | ||
return Response.text(JSON.stringify(validatorFoo.errors)); | ||
} | ||
return Response.text("OK"); | ||
} catch (e) { | ||
console.log(e); | ||
return Response.text(e.toString()); | ||
} | ||
} | ||
|
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,10 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"foo": { | ||
"type": "number" | ||
} | ||
}, | ||
"required": ["foo"], | ||
"additionalProperties": false | ||
} |