Code Monkey home page Code Monkey logo

io-ts-from-json-schema's People

Contributors

cyberixae avatar dependabot[bot] avatar konker avatar

Stargazers

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

Watchers

 avatar  avatar

io-ts-from-json-schema's Issues

Incorrect handling of `oneOf`

Because of historical reasons io-ts-from-json-schema converter handles oneOf as if it was anyOf. We should probably remove the incorrect oneOf implementation. We can later decide wether or not we wish to do a proper reimplementation.

Multiline descriptions generate syntax issues

This :

"MyModel": {
      "description": "Ullamco commodo enim nisi in occaecat esse eiusmod ex culpa ea commodo aliquip velit nostrud. Nostrud esse ad tempor adipisicing cillum ipsum exercitation ut. \nPariatur pariatur est consectetur irure laborum non anim amet pariatur dolore mollit aliqua cillum culpa. \nConsequat officia amet consequat commodo labore ex occaecat laboris anim laboris amet.",
      "example": {},
      "properties": {},
      "title": "MyModel",
      "type": "object"
    },

generates that:

// MyModel
// Ullamco commodo enim nisi in occaecat esse eiusmod ex culpa ea commodo aliquip velit nostrud. Nostrud esse ad tempor adipisicing cillum ipsum exercitation ut. 
Pariatur pariatur est consectetur irure laborum non anim amet pariatur dolore mollit aliqua cillum culpa. 

Consequat officia amet consequat commodo labore ex occaecat laboris anim laboris amet.

export type MyModel = t.Branded…

Advice on implementation

Hi @cyberixae and thank you for the great work you are doing here!

I am trying to use your library to generate endpoints for my open source project ts-endpoint but I cannot wrap my head around the best way to do it... I am trying to generate Endpoint definitions (here are a couple of examples), do you have any suggestions on how to approach the problem?

And thanks again for the amazing work!

Tuple validation changes in JSON Schema specification

The way tuples are defined have been going through some changes https://json-schema.org/understanding-json-schema/reference/array.html#tuple-validation

Previously the tuple [string, number] would be defined as

{
  "type": "array",
  "items": [
    { "type": "string"},
    { "type": "number"}
  ]
}

With some of the newer drafts the same tuple [string, number] would be defined as

{
  "type": "array",
  "prefixItems": [
    { "type": "string"},
    { "type": "number"}
  ]
}

The io-ts-from-json-schema converter currently only supports the old tuple schema definition.

There are also some other changes related to how other keywords are interpreted in relation to the tuple definition.

Named null values do not work properly

Consider the following example that defined two error types as null. At the moment iotsfjs translates these into never instead of null. It would be nice if the two nulls were distinguishable at the type level but at least they should not be never.

"definitions": {
  "errorFoo": {
    "type": "null"
  }, 
  "errorBar": {
    "type": "null"
  },

}

Limitations Array and Object schema limitations

According to the specification the following schema is supposed match { foo: 'foo' } and any item that is not an object to begin with.

{
  "properties": {
    "foo": { "const": "foo" }
  }
}

In a similar manner the following schema is supposed to match the tuple [ 'bar', 123 ] and any item that is not an array at all.

{
  "items": [
    { "const": "bar" },
    { "const": 123 }
  ]
}

Iotsfjs currently fails to validate these requirements because I haven't been able to find a good way to describe them in the TypeScript's static type system. Essentially they could be described with somethings like { foo: 'foo' } | Not<Record<string, any>> and ['bar', 123] | Not<Array<any>> but TypeScript doesn't provide Not out of box. It might be possible to represent them with conditional types but this gets quite complicated very easily.

Divide into modules

Ideally the converter code would be divided into several modules that match the modules defined in the JSON schema specification.

The doctest describes are confusing

The generated types have doctests that can be converted to actual tests with doctest-ts. During this conversion doctest-ts creates describes around test cases, and the names of the describes do not currently match tests that get generated. When a test fails it is therefore sometimes difficult to see which test failed.

Bug when referring inside definitions

In the following example bar ends up not being a number.

{
  "definitions": {
    "foo": { "type": "number" },
   "bar": { "$ref": "#/definitions/foo" },
  }
}

Checking of properties should perhaps be dependent on type

I'm starting to think that checking of properties keyword should not be dependent on "type": "object". My current understanding is that each keyword should be processed separately. i.e. processing of properties should not depend on processing of type. If someone wishes to define a null with properties, the converter should probably ignore the absurdity of that. There are various other cases where we already ignore context when processing keywords to support all kinds of unexpected scenarios.

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.