GithubHelp home page GithubHelp logo

How to document query? about oatpp HOT 4 CLOSED

oatpp avatar oatpp commented on May 20, 2024
How to document query?

from oatpp.

Comments (4)

Vi-vi-Vi avatar Vi-vi-Vi commented on May 20, 2024 1

Thanks very much. It works perfectly!

from oatpp.

lganzzzo avatar lganzzzo commented on May 20, 2024

Hello @Vi-vi-Vi ,

Thank you for the question and your interest in the project!

Please see the examples:

Add query parameter manually

  ENDPOINT_INFO(getComputedValues) {
    // general
    info->summary = "Compute values corresponding to the input parameters";
    info->addResponse<UserDto::ObjectWrapper>(Status::CODE_200, "application/json");
    info->addResponse<String>(Status::CODE_404, "text/plain");
    // params specific
    info->queryParams.add<String>("param1").description = "Input value 1"; // add query parameter manually
    info->queryParams.add<String>("param2").description = "Input value 2"; // add query parameter manually
    info->queryParams.add<String>("param3"); // add query parameter with no description manually
    info->queryParams["param3"].required = false; // make parameter optional
  }
  ENDPOINT("GET", "compute/*", getComputedValues,
           REQUEST(std::shared_ptr<IncomingRequest>, request) // Map request object to endpoint method
  ) {

    auto p1 = request->getQueryParameter("param1", "" /* default value */);
    auto p2 = request->getQueryParameter("param2", "" /* default value */);
    auto p3 = request->getQueryParameter("param3", "" /* default value */);

    OATPP_LOGD("Endpoint", "p1=%s, p2=%s, p3=%s", p1->getData(), p2->getData(), p3->getData());

    return createResponse(Status::CODE_200, "ok");

  }

Add query parameters by mapping param to a method variable

ENDPOINT_INFO(getComputedValues2) {
    // general
    info->summary = "Compute values corresponding to the input parameters";
    info->addResponse<UserDto::ObjectWrapper>(Status::CODE_200, "application/json");
    info->addResponse<String>(Status::CODE_404, "text/plain");
    // params specific
    info->queryParams["param1"].description = "Input value 1";
    info->queryParams["param2"].description = "Input value 2";
    info->queryParams["my-param-name"].description = "Input value 3";
  }
  ENDPOINT("GET", "compute2/*", getComputedValues2,
           QUERY(String, param1), // Add query parameters by mapping param to a method variable
           QUERY(String, param2),
           QUERY(String, param3, "my-param-name") // query param with name qualifier
  ) {

    OATPP_LOGD("Endpoint", "p1=%s, p2=%s, p3=%s", param1->getData(), param2->getData(), param3->getData());

    return createResponse(Status::CODE_200, "ok");
  }

Please let me know if you have more questions.

Best Regards,
Leonid

from oatpp.

acidtonic avatar acidtonic commented on May 20, 2024

Is this possible for repeating query params?

Such as ?status=1&status=2&status=3

Since the number of repeating params can be variable, can swagger handle this?

from oatpp.

lganzzzo avatar lganzzzo commented on May 20, 2024

Hey @acidtonic ,

Not yet. At the moment you can't parse query params as an array of values.

from oatpp.

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.