Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [C++][Pistache] requestBody application/json schema "type: boolean" generates type mismatch #20483

Open
5 of 6 tasks
trimble opened this issue Jan 15, 2025 · 0 comments
Open
5 of 6 tasks

Comments

@trimble
Copy link

trimble commented Jan 15, 2025

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

If requestBody is specified as application/json type boolean, code similar to the following is generated...and request.body() can not be coerced into boolean without parse(...).get_to().

void DefaultApi::pet_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
    try {


    // Getting the body param
    
    bool body;
    
    try {
        body = request.body();
openapi-generator version

7.10.0...but have seen similar in many versions since 4.1.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Swagger Petstore - OpenAPI 3.0
  version: 1.0.11
paths:
  /pet:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: boolean
        required: true
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'          
            application/xml:
              schema:
                $ref: '#/components/schemas/Pet'
components:
  schemas:
    Pet:
      required:
        - name
      type: object
      properties:
        name:
          type: string
          example: doggie
Generation Details
Steps to reproduce

java -jar Downloads/openapi-generator-cli-7.10.0.jar generate -i dog.yaml -g cpp-pistache-server -o exp

Related issues/PRs

Appears to be caused by https://github.com/OpenAPITools/openapi-generator/pull/3509/files

Suggest a fix

Generate code similar to what 4.0.2 generates:

void DefaultApi::pet_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {

    // Getting the body param
    
    bool body;
    
    try {
      nlohmann::json::parse(request.body()).get_to(body);
      this->pet_post(body, response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant