apiaryio / gavel.js

Validator of HTTP messages (JavaScript implementation)
MIT License
97 stars 22 forks source link

Are optional keys in schema supported? #30

Closed bensleveritt closed 7 years ago

bensleveritt commented 10 years ago

This is a repost from API Blueprint (https://github.com/apiaryio/api-blueprint/issues/53), but they've pointed my question in the direction of Gavel, so here goes.

Does 1A support required/optional flags in schema specifications?

My specification is:

## Entities [/api/entities]
+ Model

    + Body
    {
        "entities": [
            {
                "id": "entity1",
                "name": "Entity"
            }
        ],
        "total": 1
    }
    ```

+ Schema

    ```
    {
        "title": "Entities Schema",
        "type": "object",
        "properties": {
            "entities": {
                "type": "array",
                "items": {
                    "required": ["id"]
                }
            },
            "total": {
                "type": "integer"
            }
        }
    }
    ```


Trying to validate this response with Dredd, and it says that `name` is required and is missing. I've validated the schema against http://json-schema-validator.herokuapp.com/ and it's all clear, leading me to suspect that it's how I've written the schema.

Thanks in advance.
tomgco commented 10 years ago

Any update on this?

bensleveritt commented 10 years ago

None from me, other thanks to say I've stopped trying to use schemas, instead using blank objects (which will pass the validation in general, just not the specific components).

Almad commented 10 years ago

Hi, sorry, this totally went through my checks. I think it looks like bug, but I'll let @netmilk to verify.

Long-term, we plan to push MSON more then schemas, but I think the underlying error will be same for both.

bensleveritt commented 10 years ago

Okay, after spending all day writing schemas, I now believe MSON is superior for my needs (not to mention easier/quicker).

Am I right in thinking required/optional is still not usable?

honzajavorek commented 7 years ago

I wasn't able to reproduce this. It looks like this is not relevant anymore. Thanks for reporting this though!