Skip to content

PHP generator omits QueryParameter class import for snake_case query parameters #7602

@Jensderond

Description

@Jensderond

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Linux executable

Client library/SDK language

PHP

Describe the bug

When a PHP client is generated from an OpenAPI spec that has a query parameter whose name is renamed by the generator (e.g. snake_case like category_idcategoryId), the resulting *RequestBuilderGetQueryParameters.php file contains the @QueryParameter("category_id") docblock annotation but does not import Microsoft\Kiota\Abstractions\QueryParameter.

At runtime, Microsoft\Kiota\Abstractions\RequestInformation::setQueryParameters() resolves the annotation through Doctrine's AnnotationReader, which requires a matching use statement in the file. The missing import produces:

Doctrine\Common\Annotations\AnnotationException:
[Semantical Error] The annotation "@QueryParameter" in property
...RequestBuilderGetQueryParameters::$categoryId was never imported.
Did you maybe forget to add a "use" statement for this annotation?

Every request that passes query parameters to such an endpoint throws this exception, making the generated client unusable against the affected operations.

Expected behavior

When using @QueryParameter, the generated code should import the correct class use Microsoft\Kiota\Abstractions\QueryParameter;

How to reproduce

Generate php application based on the open-api spec and see that we are missing the import.

docker run --rm -v .:/app/output -v ./openapi.yaml:/app/openapi.yaml \
  mcr.microsoft.com/openapi/kiota:1.31.0 generate \
  -l PHP \
  -c ReproClient \
  -n Example\\ReproClient \
  -o /app/output/src --co

Open API description file

openapi: 3.0.3
info:
title: Repro
version: 1.0.0
servers:

  • url: https://example.test/api
    paths:
    /things:
    get:
    operationId: listThings
    parameters:
    - name: category_id
    in: query
    schema:
    type: string
    responses:
    "200":
    description: OK

Kiota Version

1.31.0

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

No response

Configuration

No response

Debug output

Click to expand log ```

info: Kiota.Builder.KiotaBuilder[659500454]
Cleaning output directory /app/output/src
dbug: Kiota.Builder.KiotaBuilder[1405590561]
kiota version 1.31.0
info: Kiota.Builder.KiotaBuilder[1423726202]
loaded description from local source
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 1 - reading the stream - took 00:00:00.0044530
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 2 - parsing the document - took 00:00:00.0346265
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 3 - updating generation configuration from kiota extension - took 00:00:00.0000635
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 4 - filtering API paths with patterns - took 00:00:00.0017065
info: Kiota.Builder.KiotaBuilder[543457275]
Client root URL set to https://example.test/api
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 5 - checking whether the output should be updated - took 00:00:00.0088611
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 6 - create uri space - took 00:00:00.0011084
dbug: Kiota.Builder.KiotaBuilder[1605292753]
InitializeInheritanceIndex 00:00:00.0013523
dbug: Kiota.Builder.KiotaBuilder[1605292753]
CreateRequestBuilderClass 00:00:00
dbug: Kiota.Builder.KiotaBuilder[1605292753]
MapTypeDefinitions 00:00:00.0149445
dbug: Kiota.Builder.KiotaBuilder[1605292753]
TrimInheritedModels 00:00:00
dbug: Kiota.Builder.KiotaBuilder[1605292753]
CleanUpInternalState 00:00:00
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 7 - create source model - took 00:00:00.0379782
dbug: Kiota.Builder.KiotaBuilder[1306343761]
16ms: Language refinement applied
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 8 - refine by language - took 00:00:00.0182923
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 9 - writing files - took 00:00:00.0139909
info: Kiota.Builder.KiotaBuilder[1423726202]
loaded description from local source
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 10 - writing lock file - took 00:00:00.0064115
Generation completed successfully
Client base url set to https://example.test/api
dbug: Kiota.Builder.KiotaBuilder[2121673205]
Api manifest path: /app/apimanifest.json

</details>


### Other information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Needs Triage 🔍

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions