Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support schema validation for root-level arrays #43

Closed
Almad opened this issue Aug 6, 2014 · 5 comments · Fixed by #324
Closed

Support schema validation for root-level arrays #43

Almad opened this issue Aug 6, 2014 · 5 comments · Fixed by #324
Assignees

Comments

@Almad
Copy link
Contributor

Almad commented Aug 6, 2014

See http://stackoverflow.com/questions/25027328/apiary-blueprint-markdown-for-an-array-response-body for issue description.

@netmilk
Copy link
Contributor

netmilk commented Aug 6, 2014

According to the meta schema, items property should accept both an array of schemas or schema object but gavel (tv4 validator) accepts only array when validating schema from blueprint against meta schema. It seems that $ref reference in meta schema to root in items schema property declaration is not working.

As a workaround you can define items schema property as an array and it works:

# My Api

# GET /message

+ Response 200
  + Schema
        {
          "$schema": "http://json-schema.org/draft-03/schema",
          "type": "array",
            "items": [
              {
                  "type": "string"
              }
            ]
        }

@tu1ly
Copy link

tu1ly commented Aug 6, 2014

no workaround needed
578d1e2#diff-2df9ad4288603cce25ab4f3a772dc6feR34

@rafaelkelly
Copy link

Hi @netmilk. I've also experienced this issue and I don't think the workaround you suggest has the correct result. As seen in https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.5:

When this attribute value is an array of schemas and the instance value is an array, each position in the instance array MUST conform to the schema in the corresponding position for this array.

So you would end up validating each position in the array and not all possible items.
Switching to v4 works fine but it's a problem for existing schemas written in draft 3.

@ApiaryBot
Copy link
Collaborator

🎉 This issue has been resolved in version 8.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@artem-zakharchenko
Copy link
Contributor

artem-zakharchenko commented Dec 10, 2019

Root-level arrays validation is supported by both explicit JSON Schema and implicit expected body. Please refer to the regression tests below for the example of usage.

Using JSON Schema

Using inferred schema from expected body

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants