Comments (8)
Hi Leonid,
I admit I am very new to Swagger or OpenAPI, but in the Java world, I was able to get field descriptions to show up when I use the Spring Framework together with SpringFox annotations, so I am rather intrigued as to why I can't do likewise in the C++ world.
In the link you gave me, it appears that it is possible to add "description" fields when describing a model, both at the object level as well as the field level. See for example the following Cat schema, which incidentally also contains an enum field with a description:
{
"components": {
"schemas": {
...
"Cat": {
"description": "A representation of a cat. Note that `Cat` will be used as the discriminator value.",
"allOf": [
{
"$ref": "#/components/schemas/Pet"
},
{
"type": "object",
"properties": {
"huntingSkill": {
"type": "string",
"description": "The measured skill for hunting",
"default": "lazy",
"enum": [
"clueless",
"lazy",
"adventurous",
"aggressive"
]
}
},
"required": [
"huntingSkill"
]
}
]
},
...
}
}
}
from oatpp-swagger.
Hey @yeefan ,
You are absolutely right!
I was looking into the schema specification before sending the response to you, and I just didn't see it there :).
Thanks for double-checking!
Then, we'll have to investigate the way of adding this functionality to oatpp...
Maybe it can be something like this (same as in ApiController):
class Cat : public oatpp::Object {
DTO_INIT(Cat, Object)
DTO_FIELD_INFO(huntingSkill) { // <--- hypothetical code
info->description = "The measured skill for hunting";
}
DTO_FIELD(String, huntingSkill);
}
@bhorn , what do you think?
@yeefan , thanks again for double-checking!
Best Regards,
Leonid
from oatpp-swagger.
Thanks!
To be clear, what I am looking for is the ability to have Swagger UI display descriptions and enum values as illustrated in the following example, taken from Swagger Petstore (http://petstore.swagger.io:8080/):
So perhaps the ability to do something like the following would be nice. :)
DTO_FIELD_INFO(huntingSkill) { // <--- hypothetical code
info->description = "The measured skill for hunting";
info->enumValues = {"clueless", "lazy", "adventurous", "aggressive"};
}
Having said that, for completeness sake (although I am not specifically requesting for them), you might also consider allowing users to specify other properties in object fields that you can specify in path parameters and query parameters, such as default value, minimum and maximum values, regular expressions, and so on. As far as I know, these can be done with SpringFox.
Thanks again.
from oatpp-swagger.
Hello @yeefan ,
Thanks for the question!
Currently, there is no way to annotate the individual fields of DTO.
Also, as far as I know, it's a limitation of swagger specification currently -
According to Schema Object specification you can't put a description to object fields.
As for annotating the DTO, you may consider the feature introduced in oatpp/oatpp#212
Basically you can add a description to a response:
ENDPOINT_INFO(root) {
info->summary = "root_summary";
info->addResponse<MyDto::ObjectWrapper>(Status::CODE_200, "text/plain", "Your custom description");
}
ENDPOINT("GET", "/", root) {
auto myDto = MyDto::createShared();
...
return createResponse(Status::CODE_200, myDto);
}
Additionally, support for enum fields in a DTO (in a manner similar to #19) would be much appreciated.
Most probably this feature will be introduced in 1.1.0
- the next release.
Best Regards,
Leonid
from oatpp-swagger.
If we are able to make it on time, we'll ship it with the nearest 1.1.0
.
If not, it will be scheduled for the next release.
Regards,
Leonid
from oatpp-swagger.
This definitely sounds like a great change for 1.1.0
and would fit nicely to the other enum-related requests. I have several ideas how one could accomplish that. Either with a DTO-Registry which registers all dtos in DTO_INIT
and then use the same process as in the API-Controller or - the easy way - let the users register all DTO's by themselfs after adding the DTO_FIELD_INFO
.
from oatpp-swagger.
Hey @bhorn ,
We have a static Property object associated with each field.
It should be pretty easy to extend the Property
with the needed information.
And then get all the info from there.
The class property
- https://github.com/oatpp/oatpp/blob/master/src/oatpp/core/data/mapping/type/Type.hpp#L331
from oatpp-swagger.
Hey @yeefan ,
The support for Enum
and for DTO_FIELD_INFO
is already added in the latest oatpp
and oatpp-swagger
.
Please see the oatpp changelog for details.
Regards,
Leonid
from oatpp-swagger.
Related Issues (20)
- Header parameters not shown in Swagger UI HOT 2
- missing cpack for module HOT 2
- Content-Type not set for CSS or JS responses HOT 2
- Error on start
- oatpp-swagger with HTTPS
- swagger-ui authorize bug
- To use "application/x-www-form-urlencoded" with readBodyDtoAsync HOT 1
- Set hosting base path
- Adding a Response with No Message Body Leads to an Oat++ Assertion Error at Runtime
- How To Describe File Type for `multipart/form-data` HOT 1
- The contact information cannot be an email. HOT 1
- bad interpretation of enum schemas
- Add authorization on the swagger controller
- Windows Support
- Crashed when added doc controller
- Access to raw OpenAPI JSON
- Problem with cmake FetchContent_* both oatpp-swagger and oatpp
- Support for schemas which better reflect DTO polymorphic fields
- [Help Wanted] how to group endpoints and give it a titile?
- Failed to load API definition HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oatpp-swagger.