Description
Hi,
When I add a set of values to an entity property documentation.values
it does not get exposed to the Swagger spec via definitions.[MyEntity].properties.[MyProperty].enum
.
For example:
Having this entity:
module API::V1
module Entities
class TestEntity < Grape::Entity
expose :test_property, documentation: { values: [:foo, :bar] }
end
end
end
And referencing it from the using the success documentation method.
module API
module V1
class Test < Grape::API
resource :test_resource do
desc 'Test resource' do
success API::V1::Entities::TestEntity
end
get do
end
end
end
end
end
It generates the following Swagger spec which does not include the enum
array in the TestEntity
.
{
"paths":{
"/v1/test_resource":{
"get":{
"summary":"Test resource",
"description":"Test resource",
"produces":[
"application/json"
],
"responses":{
"200":{
"description":"Test resource",
"schema":{
"$ref":"#/definitions/TestEntity"
}
}
},
"tags":[
"test_resource"
],
"operationId":"getV1TestResource"
}
}
},
"definitions":{
"TestEntity":{
"type":"object",
"properties":{
"test_property":{
"type":"string"
}
},
"description":"Test resource"
}
}
}
Adding enum in an entity definition is valid Swagger/OpenAPI spec and compatible with SwaggerUI as well as you can see in the screenshot below which is using a manually modified json spec.
Please note that enums seems to be supported when used as part of parameters definitions doing something like,
params do
requires :all, using: API::V1::Entities::TestEntity.documentation
end
but the values are still not added in the Swagger entity definition itself.
- Support enum exposure using Grape entities
documentation.values
Thanks,
Miguel