Skip to content

Generated RequestBuilderGetQueryParameters class in C# does not include the default value #6836

@StefH

Description

@StefH

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Csharp

Describe the bug

OpenApi json has this query parameter definition which has a default value defined:

{
  "name": "$top",
  "in": "query",
  "required": true,
  "schema": {
    "type": "integer",
    "default": 1
  }
}

The generated C# code is just this:

[QueryParameter("%24top")]
public int? Top { get; set; }

Expected behavior

I would expect the integer value of 1 to set as default value.

[QueryParameter("%24top")]
public int? Top { get; set; }  = 1;

How to reproduce

Generate a OpenApi json file with a GET path and a request query parameter as described.

Open API description file

{
    "openapi": "3.0.3",
    "info": {
        "title": "REST API",
        "version": "0.0.1"
    },
    "servers": [
        {
            "url": "https://example.com"
        }
    ],
    "paths": {
        "/api/v1/Abc": {
            "get": {
                "parameters": [
                    {
                        "name": "$top",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "integer",
                            "default": 1
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "...",
                        "content": {
                            "application/json": {}
                        }
                    }
                }
            }
        }
    }
}

Kiota Version

1.28.0+57130b1b1db3bc5c060498682f41e20c8ae089f2

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 ```
</details>


### Other information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    CsharpPull requests that update .net codetype:bugA broken experience

    Type

    No type

    Projects

    Status

    In Progress 🚧

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions