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
  • #13635
Closed
Open
Issue created Oct 07, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] [PHP] query parameters with value 0 are missing from URL

Created by: robopzet

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

Optional parameters with value 0 (zero) are not included in the query parameters of the generated URL for the API request. This makes it impossible to pass those values to the API.

If the parameter is defined as required and the value is 0, the parameter is included, but without value: https://example.com/?arg=.

What I expect is:

  1. when the parameter is optional and any value is passed to the PHP call that is not NULL, the parameter with value is included in the request URL.
  2. when the parameter is required the parameter and its are always included, even if the value is NULL.
openapi-generator version

v6.2.0

OpenAPI declaration file content or url

Part of the swagger 2.0 schema, cannot post all.

"paths": {
    "/my/path": {
        "get" : {
            "parameters" : [
                {
                    "name" : "aid",
                    "in"   : "query",
                    "type" : "integer"
            }
        ],
    }
}
Generation Details

Command to generate client:

java -jar openapi-generator-cli-6.2.0.jar generate -c openapi-options.json -i api-definition.json -g php -o pkg --git-user-id user --git-repo-id package-name

openapi-options.json:

{
    "invokerPackage"      : "my\\client",
    "apiPackage"          : "api",
    "modelPackage"        : "model",
    "srcBasePath"         : "client",
    "artifactVersion"     : "1.0.0"
}
Steps to reproduce

Adapted from real code:

$cfg = Configuration::getDefaultConfiguration()
    ->setUsername('USR')
    ->setPassword('PASW');

$api  = new MyApi(new Client(), $cfg);
$rslt = $api->apiGet(0);

The query parameter that is set to 0 is missng, causing the API to fail.

For other details see previous descriptions.

Related issues/PRs

Not found.

Suggest a fix

It looks like the generated method toQueryValue in class ObjectSerializer does not process value 0 correctly for all types of parameters.

It tests for empty values. but I think it should test with is_null() because that is the default value for an optional parameter. With value 0 the expression empty($val) is TRUE and the returned value is [].

I don't know exactly what the method should return in all situations, so I'm not sure this is the complete solution.

Assignee
Assign to
Time tracking