Skip to content

More flexible schema types #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tamasfe opened this issue Dec 1, 2020 · 0 comments
Open

More flexible schema types #3

tamasfe opened this issue Dec 1, 2020 · 0 comments

Comments

@tamasfe
Copy link

tamasfe commented Dec 1, 2020

The library works flawlessly for small, freshly written schemas, but existing schemas cannot be used currently.

E.g. the following won't work, even though it is a valid schema:

// schema.json
{
    "$schema": "http://json-schema.org/draft-07/schema",
    "type": "object",
    "required": ["myProp"],
    "properties": {
        "myProp": {
            "type": "string"
        }
    }
}
// index.ts
import { ResolvedJsonSchema } from "json-schema-type";
import schema from "schema.json";

type MyObject = ResolvedJsonSchema<typeof schema>;

Also, the JsonSchema* types form the json-schema library would be useful for type inference and completion while writing schemas, but the following would also not work:

import { ResolvedJsonSchema } from "json-schema-type";

const schema = <JSONSchema7>{
  type: "object",
  required: ["myProp"],
  properties: {
    myProp: {
      type: "string",
    },
  },
};

type MyObject = ResolvedJsonSchema<typeof schema>;

edit: I just realized that a JsonSchema type is exposed by the library so that is great, but reading schemas from JSON is probably still worth exploring, here's a related ts issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant