Git Product home page Git Product logo

Comments (5)

giann avatar giann commented on June 20, 2024 1

I see thanks a lot!

from php-json-schema-model-generator.

giann avatar giann commented on June 20, 2024

I think I understand what's the issue. The lib doesn't seem to expect multiple types inside a oneOf or allOf list. However I think this is a valid schema.

from php-json-schema-model-generator.

wol-soft avatar wol-soft commented on June 20, 2024

Hi @giann,
the lib is able to handle compositions like oneOf on the top level of a schema. The issue is located in the first branch of your composition which can be simplified into the following schema which makes the issue more obvious:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "string"
}

This schema can't be represented as a object. If this schema is passed to the generator it would be skipped. Due to the composition the generator starts to generate nested objects for each branch of the composition and fails on the first branch as the branch doesn't provide a nested schema which is representable as an object. I think the error message could be more meaningful.

Your schema is a valid JSON-schema but it can't be represented as a object.

from php-json-schema-model-generator.

giann avatar giann commented on June 20, 2024

Thanks for the quick answer @wol-soft
So i could get around this by using the oneOf in the schemas that reference this one so the oneOf is not at the top level but for, say, a property?

from php-json-schema-model-generator.

wol-soft avatar wol-soft commented on June 20, 2024

yes, if you wrap the composition into an object, let's say like in the following example, the generator will generate an object with the address property which is either a string or an instance of the nested object containing the properties from the second oneOf branch.

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "address": {
      "oneOf": [
        { "type": "string" },
        {
          "type": "object",
          "properties": {
            "address": { "type": "string" },
            "specialDelivery": { "type": "string" },
            "zipCode": { "type": "string" },
            "city": { "type": "string" }
          },
          "additionalProperties": false
        }
      ]
    }
  },
  "required": [ "address" ]
}

Also a reference to the schema from another schema (eg. customer) is possible. In this case just make sure you put the schema in let's say an include directory outside of the directory you have configured to generate the models from to make sure the generator doesn't try to generate a model from the address schema.

from php-json-schema-model-generator.

Related Issues (20)

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.