Giter VIP home page Giter VIP logo

Comments (8)

yeefan avatar yeefan commented on July 22, 2024 1

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.

lganzzzo avatar lganzzzo commented on July 22, 2024 1

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.

yeefan avatar yeefan commented on July 22, 2024 1

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/):

image

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.

lganzzzo avatar lganzzzo commented on July 22, 2024

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.

lganzzzo avatar lganzzzo commented on July 22, 2024

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.

bamkrs avatar bamkrs commented on July 22, 2024

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.

lganzzzo avatar lganzzzo commented on July 22, 2024

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.

lganzzzo avatar lganzzzo commented on July 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.