Coder Social home page Coder Social logo

Comments (5)

fge avatar fge commented on July 3, 2024

You are indeed doing something wrong, and the question therefore becomes what you want to do.

The problem is that itemsOne is not a node which pointers are collected for. Do you want the first item of your array to obey a certain schema? Do you want all items to obey a certain schema?

from json-schema-validator.

fge avatar fge commented on July 3, 2024

My guess is that the second option is the good one. In this case this is what you have to do:

{
    "items": {
        "description": "an item in the array",
        "$ref": "reference.json"
    }
}

from json-schema-validator.

kelvinpho avatar kelvinpho commented on July 3, 2024

Ah, you are right. In this case, I want all the items in my list to obey a certain schema.

However, there are some more complex scenarios that would create a more complex array definition. For example of the data.

{
    "orderedArray" : [
        {
            "desc" : "required first element personal data",
            "lastname" : "smith",
            "firstname" : "joe"
        },
        {
            "desc" : "any number of these",
            "phonenumber" : "111-111-1111",
            "type" : "cell"
        },
        {
            "desc" : "any number of these",
            "phonenumber" : "111-111-1112",
            "type" : "work"
        },
        {
            "desc" : "required last element personal data",
            "gender" : "M",
        }
    ]
}

Perhaps there is a better way to describe this than using an array, such as pattered properties or additional properties, but I'm not as familiar with these concepts yet.

from json-schema-validator.

fge avatar fge commented on July 3, 2024

Hmmm, you will have difficulties here. Note: properties and {additional,pattern}Properties are only there for validating JSON Objects, not arrays.

The main problem you have is that as far as arrays are concerned, schemas for array elements are decided by both the presence or absence of items and additionalItems. And you cannot, currently, describe the schema for the last element of an array.

In fact, even though you can add keywords with my implementation, even this will not help: the ArraySchema{Digest,Selector} classes only account for the aforementioned two keywords.

The closest to what you could do is having a three-element array, where the first has its own schema, the second is an array of any number of "middle items", and the third has its own schema as well. That is, your data would be:

[
    "firstItem",
    [ "array", "of", "middle", "items" ],
    "lastItem"
]

and the maching schema would be (note: individual schemas for items left empty for brevity):

{
    "type": "array",
    "minItems": 3,
    "maxItems": 3,
    "items": [
        {},
        { "type", "array", "items": { "$ref": "#/definitions/middleItems" } },
        {}
    ],
    "definitions": {
        "middleItems": {}
    }
}

from json-schema-validator.

kelvinpho avatar kelvinpho commented on July 3, 2024

I believe this is fixed, thanks!

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.