Coder Social home page Coder Social logo

to-json-schema's People

Contributors

danielruf avatar forivall avatar ruzicka avatar slavivanov 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  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  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  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

to-json-schema's Issues

anyOf spec

Hi, interesting project.

I was wondering if you had given any thought about how to do anyOf support in maybe a custom function

some string are inferred as "format":"style"

strings which are not "style" are inferred as styles.
for example, given this code:

import toJsonSchema from 'to-json-schema'

const json = {
  'notAStyle': '10:00',
}

console.log(toJsonSchema(json))

the following json schema is generated:
{
"type": "object",
"properties": {
"notAStyle": {
"type": "string",
"format": "style"
}
}
}

I think the regex here can be improved to avoid this mistakes: https://github.com/ruzicka/to-json-schema/blob/master/src/jsonSchemaHelpers.js#L74

I would love to upload PR for this one if possible

Show nested object

Is there any way to show the nested objects which I do not know the schema of?

Im getting:

{
  type: 'object',
  properties: {
    bpi: { type: 'object', properties: [Object] },
    disclaimer: { type: 'string' },
    time: { type: 'object', properties: [Object] }
  }
}

where I want:

{
  type: 'object',
  properties: {
    bpi: { type: 'object', properties: { valueIdontknowA: { type: 'string' } , valueIdontknowB: { type: 'string' } } },
    disclaimer: { type: 'string' },
    time: { type: 'object', properties: 
        { valueA: { type: 'string' } , valueB: { type: 'string' } }  
  }
  }
}

Fail to create schema of array of strings

Conversion attempt of ["1", "two", "3", "four"] to schema throws exception with message "Failed to load schema: Cannot read properties of null (reading 'type')".
The cause is that mergeSchemaObjs returns null because list items schemas restored as {"type": "string", "format": "utc-millisec"} for "1" and "3", and {"type": "string"} for the rest.

{ required: true } doesn't appear to be valid JSON-schema

Hi there -- not sure if this project is very active but figured I'd post this for the benefit of anyone else wondering.

I believe the required: true notation used to indicate properties are required is not valid JSON-schema syntax in any draft. I tested this by pasting the generated output of to-json-schema into a JSON schema validator and checking it against the existing JSON schema drafts!

That said, there appears to be an easy fix, which would be to use the example you define farther down:

const options = {
  objects: {
    postProcessFnc: (schema, obj, defaultFnc) => ({...defaultFnc(schema, obj), required: Object.getOwnPropertyNames(obj)})
  }
};

Thanks for this library @ruzicka, it's nicely engineered!

API flexibility suggestions

options.object, options.string, options.postProcessFnc are not flexible enough to handle complex cases, such as patch/merge some schema fileds on toJsonSchema processing.

For details:

  1. Lack of array options.

  2. Lack of options.preProcessFnc

  3. Lack of object.keys and array.index hook

What I really need is the node path during toJsonSchema iteration process, something like:

options.postProcessFnc(nodePath = ['a', 1, 'b'], value = 'myValue', schema) {
  // patch on result schema
  if (nodePath.join('.') === 'a.1.b') {
    schema.example = 'my code';
    schema.anything = 'xxxx';
  }
  return schema;
}

But at this point, documented API seems not working for this case (especially array index), any idea or workaround would be also appreciated.

It is there a CLI?

Hi,

I'd like to define a JSON file such as

{
 "user" : "sample"
}

And save it as user.json and then run something such as to-json-schema users.json userschema.json in order to create a schema file for the users.json file

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.