Giter Club home page Giter Club logo

ts-jsonschema-builder's People

Contributors

bingnz avatar sergej-popov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ts-jsonschema-builder's Issues

Static factories for schema builders.

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();

Properties with string names not supported

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.