microsoft / microsoft/kiota

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

Open
#6,836 2 comments 0 reactions 0 assignees View on GitHub
Csharp type:bug
Dominant language
C#
Stars
3.8k
Forks
333
Avg merge
16h 29m
Merged PRs (30d)
116

Description

### 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:

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

The generated C# code is just this:
``` c#
[QueryParameter("%24top")]
public int? Top { get; set; }
```

### Expected behavior

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

``` c#
[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
``` json
{
"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
```

```

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the generated C# RequestBuilderGetQueryParameters class from the supplied OpenAPI JSON and trace how the query parameter schema's default value is handled. Done means the generated nullable Top property includes the integer default of 1, with the behavior verified for the provided GET request parameter.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.