danielgtaylor / aglio

An API Blueprint renderer with theme support that outputs static HTML
4.75k stars 480 forks source link

Empty Enum specified when no example given #315

Closed weejames closed 7 years ago

weejames commented 7 years ago

I'm struggling to find a data structure syntax that generates JSON schema that I can use effectively with Dredd.

My data structure is as follows:

## Nation (object)

+ id (string) Zid for Nation
+ type (string) The object type that this data represents
+ label (string) Name of nation
+ languages (array[Language], fixed) The languages available within this Nation
+ years (array[Year], fixed) The years available within this Nation

## Year (object)
+ id (string) Zid for Nation
+ type (string) The object type that this data represents
+ label (string) The name of the year group

## Language (object)
+ id (string) Zid for Language
+ type (string) The object type that this data represents
+ label (string) The name of the supported language
+ code (string) The code for the supported language

But when the resulting JSON-schema includes an empty enum property that causes my test to fail due to the

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "data": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "enum": [
              ""
            ]
          },
          "type": {
            "type": "string",
            "enum": [
              ""
            ]
          },
          "label": {
            "type": "string",
            "enum": [
              ""
            ]
          },
          "languages": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "enum": [
                    ""
                  ]
                },
                "type": {
                  "type": "string",
                  "enum": [
                    ""
                  ]
                },
                "label": {
                  "type": "string",
                  "enum": [
                    ""
                  ]
                },
                "code": {
                  "type": "string",
                  "enum": [
                    ""
                  ]
                }
              },
              "required": [
                "id",
                "type",
                "label",
                "code"
              ],
              "additionalProperties": false
            }
          },
          "years": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "enum": [
                    ""
                  ]
                },
                "type": {
                  "type": "string",
                  "enum": [
                    ""
                  ]
                },
                "label": {
                  "type": "string",
                  "enum": [
                    ""
                  ]
                }
              },
              "required": [
                "id",
                "type",
                "label"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "id",
          "type",
          "label",
          "languages",
          "years"
        ],
        "additionalProperties": false
      }
    },
    "meta": {
      "type": "object",
      "properties": {}
    }
  },
  "required": [
    "data"
  ]
}

This empty enum results in my tests failing as the data returned from my API doesn't match it.

Not sure if I've misinterpreted the documentation or if this is a genuine bug.

weejames commented 7 years ago

Realise this probably isn't an issue with Agilio - likely at a lower level component.