-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Description
Having the schema defined like this
{
"openapi": "3.0.0",
"servers": [
{
"url": "/"
}
],
"info": {
"title": "Foo",
"version": "1.0.0",
"description": ":)\n"
},
"tags": [
{
"name": "foo",
"description": "Operations related to foo"
}
],
"paths": {
"/Foo": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"additionalProperties": false,
"properties": {
"apples": {
"$ref": "#/components/schemas/apples"
}
},
"type": "object"
}
}
}
},
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/whatever"
}
}
},
"description": "The new legal entity"
}
}
}
}
},
"components": {
"schemas": {
"apples": {
"items": {
"additionalProperties": false,
"properties": {
"type": {
"$ref": "#/components/schemas/apple"
}
},
"type": "object"
},
"type": "array",
"nullable": true,
"x-label": "apples"
},
"apple": {
"enum": [
"good","bad"
],
"type": "string",
"x-label": "rate"
}
}
}
}It is an array of object and objetc has enum in there.
In the schema defined above, the enum reference won't properly be resolved.
if I change the schema to
{
"openapi": "3.0.0",
"servers": [
{
"url": "/"
}
],
"info": {
"title": "Foo",
"version": "1.0.0",
"description": ":)\n"
},
"tags": [
{
"name": "foo",
"description": "Operations related to foo"
}
],
"paths": {
"/Foo": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"additionalProperties": false,
"properties": {
"Apple": {
"$ref": "#/components/schemas/Apples"
}
},
"type": "object"
}
}
}
},
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Whatever"
}
}
},
"description": "The new legal entity"
}
}
}
}
},
"components": {
"schemas": {
"Apples": {
"items": {
"$ref": "#/components/schemas/Apple"
},
"type": "array",
"nullable": true,
"x-label": "Apples"
},
"Apple": {
"additionalProperties": false,
"properties": {
"type": {
"$ref": "#/components/schemas/rate"
}
},
"type": "object"
},
"rate": {
"enum": [
"good", "bad"
],
"type": "string",
"x-label": "rate"
}
}
}
}Then it will resolve.
The major difference is, rather than define the object in the items directly, I $ref it. As many examples mentioned.
However, I don't think the schema I had in the first one is wrong. As what I can find about the restriction for items
items - Value MUST be an object and not an array. Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. items MUST be present if the type is an array.
Please help me to verify that the first schema is valid.
I already know the line that resolves the reference, if the first one is valid. I will send out the fix on swagger-parser right away.