justeat / ts-jsonschema-builder Goto Github PK
View Code? Open in Web Editor NEWFluent TypeScript JSON Schema builder.
License: Apache License 2.0
Fluent TypeScript JSON Schema builder.
License: Apache License 2.0
As per the suggestion in #8 PR review.
Create static builder factories for creating schema objects.
Such fluent builders will be more convenient to use and easier to discover the API with IntelliSense.
For example:
const schema = new Schema<Model>()
.with(m => m.StringProp, new AnyOf([
"specificValueNotMatchingRegex",
/^[A-z]+\.[A-z]+$/,
new StringSchema({
enum: ["123"]
})
]))
.build();
could be expressed as something like
const schema = new Schema<Model>()
.with(m => m.StringProp, jsonschema.matching.anyOf([
"specificValueNotMatchingRegex",
/^[A-z]+\.[A-z]+$/,
jsonschema.string.exactMatch("123")
]))
.build();
See Security tab in repo (lodash library should be updated).
Objects which have properties using quote strings for names break if any schema rules are setup which validate that property.
repro steps.
Change Model like so:
export class Model {
public "Quote-Prop"?: string;
public StringProp?: string;
// SNIP
And add the following test:
it("Should pass when string property name is a string", () => {
const model: Model = {};
model["Quote Prop"] = "abc.def";
const schema = new Schema<Model>()
.with(m => m["Quote Prop"], new StringSchema())
.build();
assertValid(schema, model);
});
The the test fails with the following output:
Error: schema is invalid: data.required[0] should be string
at Ajv.validateSchema (node_modules\ajv\lib\ajv.js:177:16)
at Ajv._addSchema (node_modules\ajv\lib\ajv.js:306:10)
at Ajv.compile (node_modules\ajv\lib\ajv.js:112:24)
at assert (tests\assertion.ts:20:25)
at Object.assertValid (tests\assertion.ts:10:3)
at Context.<anonymous> (tests\string.spec.ts:36:7)
This might be an underlying issue with Ajv, I haven't had time to create a reproduction in that library.
This was an issue, as I was trying to validate a json document which had spaces/dashes in the property name.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.