question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Required fields within array of object

See original GitHub issue

Expected behavior

Required fields should validate within an array ‘items’ object.

Actual behavior

Validation does not occur

Steps to reproduce the behavior

Schema as shown;

{
    "type": "array",
    "format": "tabs",
    "title": "Cronjobs",
    "items": {
        "type": "object",
        "title": "Job",
        "format": "grid",
        "headerTemplate": "{{ self.title }}",
        "additionalProperties" : false,
        "required": [
            "title",
            "job",
            "minute",
            "hour",
            "day",
            "month",
            "year"
        ],
        "properties": {
            "title": {
                "title": "Title",
                "type": "string"
            },
            "job": {
                "title": "Job",
                "type": "string"
            },
            "minute": {
                "title": "Minute",
                "type": "string",
                "default": "*"
            },
            "hour": {
                "title": "Hour",
                "type": "string",
                "default": "*"
            },
            "day": {
                "title": "Day",
                "type": "string",
                "default": "*"
            },
            "month": {
                "title": "Month",
                "type": "string",
                "default": "*"
            },
            "year": {
                "title": "Year",
                "type": "string",
                "default": "*"
            },
            "active": {
                "title": "Active",
                "type": "boolean",
                "format": "checkbox",
                "default": true
            }
        }
    }
}

All fields for each item should be required, however they can be blank and validation reports no issues. The above schema validates array items correctly at https://www.jsonschemavalidator.net/ so there should be no issues with the schema itself.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
germanbisurgicommented, Aug 7, 2018

In the json-schema world required does not mean that some value must be set. It means that the value must be present (valid also if its empty).

What you need is “minLength”, probably.

https://json-schema.org/understanding-json-schema/reference/object.html#required-properties

0reactions
schmunk42commented, Oct 4, 2018

You can set the required property for a property, but this is connected to json-schema’s required, which means that the key has to exist in the JSON output.

@germanbisurgi Could you have a look at the part for the atttributes required placeholder="Placeholder text" - please open a new issue, if needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

From an array of objects, extract value of a property as array
Example to collect the different fields from the object array ... provided list to an array containing either the requested field or the...
Read more >
Validating Array objects for required fields, .exists() - doesn't ...
Is there a way to force that a field must be present in array object? the exists() doesn't seem to work for arrays....
Read more >
Performing a $lookup on Object Fields within an Array of ...
I'm trying to come up with an aggregation pipeline that will allow me to obtain some information from an enumerations collection which has...
Read more >
Arrays | Elasticsearch Guide [8.5] | Elastic
In Elasticsearch, there is no dedicated array data type. Any field can contain zero or more values by default, however, all values in...
Read more >
Nested Objects and Arrays - VeeValidate
fields : a read-only version of your array field items, it includes some useful properties like key , isFirst and isLast , the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found