Giter Site home page Giter Site logo

Comments (5)

mokkabonna avatar mokkabonna commented on August 30, 2024

No and probably will not be. As that would change the schemas fundamentally and change the original meaning of the schema.

However you can do this yourself if you want that custom behaviour.

  const result = merge(
    {
      type: "string",
      allOf: [
        {
          type: "number",
        },
      ],
    },
    {
      resolvers: {
        type(values, path, mergeSchemas, options) {
          return values;
        },
      },
    }
  );

  console.log(JSON.stringify(result, null, 2));
```

```json
{
  "type": [
    "string",
    "number"
  ]
}
```

You probably also want to remove any duplicates on the values.

from json-schema-merge-allof.

danthegoodman1 avatar danthegoodman1 commented on August 30, 2024

from json-schema-merge-allof.

mokkabonna avatar mokkabonna commented on August 30, 2024

Yes multiple types are allowed and supported.

It is just that this schema will always fail validation. One schema says it must be string, another that it must be number.

{
      type: "string",
      allOf: [
        {
          type: "number",
        },
      ],
}

This library does not combine schemas and allow all variants. It preserves the validation of how it was before.

Either both of the schemas should have "type": ["string", "number"] or just one of them. That way it would work as expected.

from json-schema-merge-allof.

danthegoodman1 avatar danthegoodman1 commented on August 30, 2024

from json-schema-merge-allof.

mokkabonna avatar mokkabonna commented on August 30, 2024

But of course if you have control and know the "risks" then this is a perfect use case for the custom resolver.

The only other variant of this that is officially supported is to ignore the additionalProperties: false during the merge phase. As two schemas with one of them having that set will basically never allow anything outside the schema it is in. And that is not very useful when composing multiple schemas.

from json-schema-merge-allof.

Related Issues (19)

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.