Coder Social home page Coder Social logo

Comments (2)

fge avatar fge commented on July 22, 2024

You can use a reference. Note that title is informative, it has no role into validation. What you can do is refer to the schema itself, for this you can use a JSON reference as below:

{
    "title": "myType",
    "type": "object",
    "properties": {
        "id": { 
            "type": "string"
        },
        "complexProp": {                        
            "type": "array",
            "items": { "$ref": "#" }
        }
    }
}

Note also that the required attribute does not help here, it only applies to subschemas in properties. If you want your array to have at least one element, use "minItems": 1 (or maybe you misplaced it?).

Another possibility is to use inline schema addressing (note: 1.3.x only), but note that this is not the default. Your schema would then look like:

{
    "title": "myType",
    "id": "#myType",
    "type": "object",
    "properties": {
        "id": { 
            "type": "string"
        },
        "complexProp": {                        
            "type": "array",
            "items": { "$ref": "#myType" }
        }
    }
}

In order to use inline schema addressing, you must use the .addressingMode() method of JsonSchemaFactory.Builder, as in:

    final JsonSchemaFactory factory = new JsonSchemaFactory.Builder()
        .addressingMode(AddressingMode.INLINE).build();

See also http://fge.github.com/json-schema-validator/devel/org/eel/kitchen/jsonschema/examples/doc-files/Example2.java

from json-schema-validator.

lokee103 avatar lokee103 commented on July 22, 2024

Thanks for your response.

Right now I'm still using 1.2.2 so I'll try to refer to the schema itself with "$ref": "#" and will let you know how it went.

from json-schema-validator.

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.