wework / speccy

Well Spectually 🤓 Enforce quality rules on your OpenAPI 3.0.x specifications.
http://speccy.io
MIT License
824 stars 78 forks source link

Adding propertyNames to json schema failes speccy #293

Open svrnwnsch opened 5 years ago

svrnwnsch commented 5 years ago

Detailed description

I found a bug: I added as a response schema with $ref the following json schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "propertyNames": {
    "enum": ["Key1", "Key2"]
  }
}

I got the entry for propertyNames from this stackoverflow question.

When I start speccy via speccy serve openapi/index.openapi.yml -j --verbose it fails with:

GET /path-to-json/seeabove.json #
Expected object or boolean as schema, got array
Expected object or boolean as schema, got array
Expected object or boolean as schema, got array
undefined

Removing the part or renaming it e.g. from "propertyNames" -> "propertyName" at least starts the webserver (even if this schema is not working).

Possible implementation

If displaying some stuff for such validation is hard then at least do not fail or print better message when calling the command. Without the --verbose flag I just got returned undefined and the program exited with code 1.

Your environment

philsturgeon commented 5 years ago

Yep this would be expected. The -j switch was designed to convert certain JSON Schema functionality to OpenAPI, and not all of it has been done. propertyNames is JSON Schema, and that is not a keyword in OpenAPI v3. Maybe you could send a PR to https://github.com/wework/json-schema-to-openapi-schema