The Value property of OpenApiExample is treated as optional and an optional empty IEnumerable is ignored when writing both JSON and YAML. I don't think it's correct, since an empty array or an empty object could be a real example of a response body and we may want to show it to the API's user.
Minimal OpenAPI document with an empty array:
{
"openapi": "3.0.1",
"info": {
"title": "Example API",
"version": "1.0"
},
"paths": {
"/products": {
"get": {
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
}
}
},
"examples": {
"Success response - no results": {
"value": []
}
}
}
}
}
}
}
}
}
}
The same document after it has been read and written back by OpenAPI.NET:
{
"openapi": "3.0.1",
"info": {
"title": "Example API",
"version": "1.0"
},
"paths": {
"/products": {
"get": {
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
}
}
},
"examples": {
"Success response - no results": {}
}
}
}
}
}
}
}
}
}
The
Valueproperty ofOpenApiExampleis treated as optional and an optional emptyIEnumerableis ignored when writing both JSON and YAML. I don't think it's correct, since an empty array or an empty object could be a real example of a response body and we may want to show it to the API's user.Minimal OpenAPI document with an empty array:
{ "openapi": "3.0.1", "info": { "title": "Example API", "version": "1.0" }, "paths": { "/products": { "get": { "responses": { "200": { "description": "Success", "content": { "application/json": { "schema": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string" } } } }, "examples": { "Success response - no results": { "value": [] } } } } } } } } } }The same document after it has been read and written back by OpenAPI.NET:
{ "openapi": "3.0.1", "info": { "title": "Example API", "version": "1.0" }, "paths": { "/products": { "get": { "responses": { "200": { "description": "Success", "content": { "application/json": { "schema": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string" } } } }, "examples": { "Success response - no results": {} } } } } } } } } }