Skip to content

Required attribute of properties defined as stringArray #221

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

Closed
MonsJovis opened this issue Dec 1, 2014 · 6 comments · May be fixed by umar2code/OpenAPI-Specification#3 or enterstudio/OpenAPI-Specification#7

Comments

@MonsJovis
Copy link

I marked properties of one of my schema objects as required.

"definitions": {
    "Credentials": {
    "title": "Credentials",
    "properties": {
        "client_id": {
        "type": "string",
        "required": true
    },
    "client_secret": {
        "type": "string",
        "required": true
    },
    "username": {
        "type": "string",
        "required": true
    },
    "password": {
        "type": "string",
        "required": true
    }
}

The validator says the value of required has to be a stringArray:

[ {
  "level" : "error",
  "schema" : {
    "loadingURI" : "http://json-schema.org/draft-04/schema#",
    "pointer" : "/definitions/stringArray"
  },
  "instance" : {
    "pointer" : "/definitions/Credentials/properties/client_id/required"
  },
  "domain" : "validation",
  "keyword" : "type",
  "message" : "instance type (boolean) does not match any allowed primitive type (allowed: [\"array\"])",
  "found" : "boolean",
  "expected" : [ "array" ]
} ]

So I'm wondering why the required attribute of properties is defined as stringArray?

"required": {
     "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray"
}
@mohsen1
Copy link
Contributor

mohsen1 commented Dec 2, 2014

This is how JSON Schema works. See this example:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Product",
    "description": "A product from Acme's catalog",
    "type": "object",
    "properties": {
        "id": {
            "description": "The unique identifier for a product",
            "type": "integer"
        }
    },
    "required": ["id"]
}

More info here

@MonsJovis
Copy link
Author

@mohsen1 It works! Great! Thanks! But isn't it a little bit confusing defining the required attribute of the parameters as boolean and the required attribute of the schema properties as array?

@webron
Copy link
Member

webron commented Dec 3, 2014

@MonsJovis - for models, we basically use a subset (fsvo 'subset) of json schema which defines 'required' that way. The rest of the spec is built based on our own design and it doesn't necessarily adhere to the json-schema design.

We can argue which is better ;)

@MonsJovis
Copy link
Author

@webron ok :) Thanks for explaining!

@ePaul
Copy link
Contributor

ePaul commented Jul 15, 2015

The error message is still misleading, as the required attribute is not just of the wrong type, but also at the wrong location. So I guess a better message would be "there is no required attribute for properties".

@webron
Copy link
Member

webron commented Jul 15, 2015

We don't really control the validation error messages.

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