Empty ENUM included in Schema
weejames opened this issue · comments
I'm struggling to find a data structure syntax that generates JSON schema from MSON 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.
I am not sure, but it looks like you would like the arrays, array[Language]
and array[Year]
to contain only Language
and Year
object respectively. In that case you should mark them not as fixed
but fixed-type
. Like so
## 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-type) The languages available within this Nation
+ years (array[Year], fixed-type) 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
which give following JSON Schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string"
},
"label": {
"type": "string"
},
"languages": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string"
},
"label": {
"type": "string"
},
"code": {
"type": "string"
}
}
}
},
"years": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string"
},
"label": {
"type": "string"
}
}
}
}
}
}
Thanks - that looks right on that side of things.
Can i ask what you used to generate the JSON schema? I still have the empty enums in the output from Dredd so I'm starting to think there's a difference in whatever it uses to parse the MSON.
I have used drafter https://github.com/apiaryio/drafter and piped its output through https://github.com/apiaryio/drafter/blob/master/tools/refract-filter.py