apiaryio / api-blueprint

API Blueprint
https://apiblueprint.org
MIT License
8.65k stars 2.14k forks source link

Support for optional response elements in schema #53

Closed bensleveritt closed 10 years ago

bensleveritt commented 10 years ago

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.
zdne commented 10 years ago

@bensleveritt

API Blueprint and its parser treats all assets as opaque blocks. That is, it does not inspect or interpret anything that is inside a message-body or message-body validation schema. It is up to the tool how it handles the schema. In this case the actual behavior is driven by the Dredd implementation or more precisely Gavel.js – the tool Dredd uses to validate HTTP requests.

Please check the Gavel.js and its Issues.

bensleveritt commented 10 years ago

Thanks for clarifying that. Wasn't sure what handled by which bit. I'll raise it with Gavel.

zdne commented 10 years ago

@bensleveritt

No problem. The important premise here is that API Blueprint does not step into assets what so ever. As tempting as it might be I want to draw a thick line here.