Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #5880
Closed
Open
Issue created Apr 09, 2020 by Administrator@rootContributor

[BUG][C++][Pistache] required field is meaningless in query parameters

Created by: kuzkry

Description

It seems that the required field is broken for query parameters as using it in all variants has no impact on generated code. Pameter type can be anything so I've made it for boolean.

openapi-generator version

I use OpenAPI Generator 4.3.0. I've got no idea if this is regression.

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  description: Some description
  version: 1.0.0
  title: Some title

tags:
  - name: foo

paths:
  "/bar":
    get:
      operationId: barGet
      tags:
        - foo
      summary: Do something
      parameters:
        - in: query
          name: duck
          required: true
          description: property value
          schema:
            type: boolean
      responses:
        200:
          description: Successful operation
          content:
            text/plain:
              schema:
                type: string
servers:
  - url: http://localhost:8080

The problem is that no matter if I make my "duck" parameter mandatory (required: true) or optional (required: false or leave it out), the generated code is exactly the same:

void FooApi::bar_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {

    // Getting the query params
    auto duckQuery = request.query().get("duck");
    Pistache::Optional<bool> duck;
    if(!duckQuery.isEmpty()){
        bool valueQuery_instance;
        if(fromStringValue(duckQuery.get(), valueQuery_instance)){
            duck = Pistache::Some(valueQuery_instance);
        }
    }
    // ...

The only difference is in the generated comment in .h file which is:

  • for required: true
/// <param name="duck">property value</param>
  • for required: false or "nothing"
/// <param name="duck">property value (optional, default to false)</param>
Command line used for generation

java -jar openapi-generator-cli.jar generate -i issue.yaml -g cpp-pistache-server -o generated

Steps to reproduce

N/A

Related issues/PRs

I haven't found one.

Suggest a fix/enhancement

I might be wrong here but I suppose it's a bug as I'd expect the generated handler to return some sort of user error code (400? 404?) if the user didn't provide parameter for the required: true field. The generated code is IMO fine for optional parameters now, but perhaps mandatory fields could be handled like that:

response.send(Pistache::Http::Code::Bad_Request, R"(Field "duck" wasn't provided)"); // "duck" was the first unsatisfied

or something more generic when there are multiple required parameters.

Assignee
Assign to
Time tracking