Skip to content

[BUG] [C] Client generator does not handle float properly #21092

@amoweb

Description

@amoweb

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?
Description
openapi-generator version

openapi-generator-cli-7.12.0.jar

OpenAPI declaration file content or url
# Note : requestBody n'est pas supporté par le générateur C++ Qt, on fait
# passer tous les paramètres en type query (donc dans l'URL).
info:
  title: "REST-API"
  version: 1.0.0
openapi: 3.1.1
paths:
  /get_plugin_float_parameter:
    get:
      operationId: get_plugin_float_parameter
      parameters:
      - description: Plugin identifier
        in: query
        name: plugin
        required: true
        schema:
          type: string
      - description: parameter key
        in: query
        name: key
        required: true
        schema:
          type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  success:
                    type: boolean
                  error:
                    type: string
                  value_num:
                    type: number
                    format: float
                required:
                - success
          description: "Expected response to a valid request"
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrWithCode'
          description: "unexpected error"
      summary: Return the float value of the parameter
      tags:
      - Restapi
  /set_plugin_int64_parameter:
    put:
      operationId: set_plugin_int64_parameter
      parameters:
      - description: Plugin identifier
        in: query
        name: plugin
        required: true
        schema:
          type: string
      - description: parameter key
        in: query
        name: key
        required: true
        schema:
          type: string
      - description: int64 value
        in: query
        name: value
        required: true
        schema:
          type: integer
          format: int64
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  success:
                    type: boolean
                  error:
                    type: string
                required:
                - success
          description: "Expected response to a valid request"
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrWithCode'
          description: "unexpected error"
      summary: Set the int64 value of the parameter
      tags:
      - Restapi
  /set_plugin_int32_parameter:
    put:
      operationId: set_plugin_int32_parameter
      parameters:
      - description: Plugin identifier
        in: query
        name: plugin
        required: true
        schema:
          type: string
      - description: parameter key
        in: query
        name: key
        required: true
        schema:
          type: string
      - description: int32 value
        in: query
        name: value
        required: true
        schema:
          type: integer
          format: int32
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  success:
                    type: boolean
                  error:
                    type: string
                required:
                - success
          description: "Expected response to a valid request"
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrWithCode'
          description: "unexpected error"
      summary: Set the int32 value of the parameter
      tags:
      - Restapi
  /set_plugin_float_parameter:
    put:
      operationId: set_plugin_float_parameter
      parameters:
      - description: Plugin identifier
        in: query
        name: plugin
        required: true
        schema:
          type: string
      - description: parameter key
        in: query
        name: key
        required: true
        schema:
          type: string
      - description: float value
        in: query
        name: value
        required: true
        schema:
          type: number
          format: float
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  success:
                    type: boolean
                  error:
                    type: string
                required:
                - success
          description: "Expected response to a valid request"
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrWithCode'
          description: "unexpected error"
      summary: Set the float value of the parameter
      tags:
      - Restapi
  /get_plugin_boolean_parameter:
    get:
      operationId: get_plugin_boolean_parameter
      parameters:
      - description: Plugin identifier
        in: query
        name: plugin
        required: true
        schema:
          type: string
      - description: parameter key
        in: query
        name: key
        required: true
        schema:
          type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  success:
                    type: boolean
                  error:
                    type: string
                  value_bool:
                    type: boolean
                required:
                - success
          description: "Expected response to a valid request"
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrWithCode'
          description: "unexpected error"
      summary: Return the boolean value of the parameter
      tags:
      - Restapi
      
  /set_plugin_boolean_parameter:
    put:
      operationId: set_plugin_boolean_parameter
      parameters:
      - description: Plugin identifier
        in: query
        name: plugin
        required: true
        schema:
          type: string
      - description: parameter key
        in: query
        name: key
        required: true
        schema:
          type: string
      - description: boolean value
        in: query
        name: value
        required: true
        schema:
          type: boolean
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  success:
                    type: boolean
                  error:
                    type: string
                required:
                - success
          description: "Expected response to a valid request"
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrWithCode'
          description: "unexpected error"
      summary: Set the boolean value of the parameter
      tags:
      - Restapi
     
  /set_plugin_string_parameter:
    put:
      operationId: set_plugin_string_parameter
      parameters:
      - description: Plugin identifier
        in: query
        name: plugin
        required: true
        schema:
          type: string
      - description: parameter key
        in: query
        name: key
        required: true
        schema:
          type: string
      - description: string value
        in: query
        name: value
        required: true
        schema:
          type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  success:
                    type: boolean
                  error:
                    type: string
                required:
                - success
          description: "Expected response to a valid request"
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrWithCode'
          description: "unexpected error"
      summary: Set the string value of the parameter
      tags:
      - Restapi
      
servers:
  - url: http://127.0.0.1:8080

components:
  schemas:
    ErrWithCode:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
Generation Details

& 'C:\Program Files\Microsoft\jdk-17.0.5.8-hotspot\bin\java.exe' -jar .\openapi-generator-cli-7.12.0.jar generate -g c -i openapi.yml -o generated

Steps to reproduce
  • Generate
  • Open generated/api/RestapiAPI.c
  • See RestapiAPI_setPluginFloatParameter
  • The function takes a float value as parameter : RestapiAPI_setPluginFloatParameter(apiClient_t *apiClient, char *plugin, char *key, float value)
  • But the generated code is the following
if (value)
    {
        keyQuery_value = strdup("value");
        valueQuery_value = (value);
        keyPairQuery_value = keyValuePair_create(keyQuery_value, &valueQuery_value);
        list_addElement(localVarQueryParameters,keyPairQuery_value);
    }
  • Which as two bugs. If value is 0, the data isn't sent, and keyValuePair_create expects a string and it receives a float*.

  • The same declaration for a Int32 gives the following code (RestapiAPI_setPluginInt32Parameter(apiClient_t *apiClient, char *plugin, char *key, int *value)). Where the value is transformed to string.

if (value)
    {
        keyQuery_value = strdup("value");
        valueQuery_value = calloc(1,MAX_NUMBER_LENGTH);
        snprintf(valueQuery_value, MAX_NUMBER_LENGTH, "%d", *value);
        keyPairQuery_value = keyValuePair_create(keyQuery_value, valueQuery_value);
        list_addElement(localVarQueryParameters,keyPairQuery_value);
    }
Related issues/PRs
Suggest a fix

Use a similar solution as int32.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions