CSharp - enum path parameters not generated
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 333
- Avg merge
- 16h 29m
- Merged PRs (30d)
- 116
Description
We're using Kiota to replace existing NSwag generation, and whilst it's mostly been smooth (and overall a nice improvement), we have one major blocker left.
We've found that Kiota doesn't generate the enum models for path parameters, and instead takes a string, I've done a little research and it looks like a [similar issue has been raised and fixed (in dotnet)](https://github.com/microsoft/kiota-abstractions-dotnet/pull/148) with other languages in progress.
Whilst PRs have been raised for other langs to add this for path and query params, looks like dotnet might just be query?
Is there a technical reason for this? Or is it coming soon?
ref:
https://github.com/microsoft/kiota/issues/3693
https://github.com/microsoft/kiota/issues/2490
https://github.com/microsoft/kiota-abstractions-ruby/issues/61
https://github.com/microsoft/kiota/issues/3783
https://github.com/microsoft/kiota/issues/3784
**Example:**
Generates (for both examples):
```CSHARP
/// Gets an item from the ExampleApi.example2.item.item collection
/// enum param.
/// A
public WithEnum_paramItemRequestBuilder this[string position] { get {
var urlTplParams = new Dictionary(PathParameters);
urlTplParams.Add("enum_param", position);
return new WithEnum_paramItemRequestBuilder(urlTplParams, RequestAdapter);
} }
```
Firstly, the param name being "position" rather than usign the path property name is extremely confusing as a consumer of the generated SDK.
Secondly if I change EnumParam to be a query parameter, it correctly generates an enum query param (as well as string), with either a schema model enum, or a nested enum. This is fine, and I'd be happy with this behaviour for path too, but currently this doesn't appear to be working.
```YAML
openapi: 3.0.3
info:
title: Example
description: Example
version: 1.0.0
servers:
- url: https://example.com/api
paths:
'/example1/{string_param}/{enum_param}':
post:
summary: Test enum path parameter with schema ref.
description: "Test enum path parameter with schema ref."
operationId: postPathSchemaRefTest
parameters:
- name: string_param
in: path
description: string param.
required: true
style: simple
schema:
type: string
- name: enum_param
in: path
description: enum param.
required: true
schema:
$ref: '#/components/schemas/EnumParam'
responses:
'200':
description: Success
'/example2/{string_param}/{enum_param}':
post:
summary: Test enum path parameter with inline schema.
description: "Test enum path parameter with inline schema."
operationId: postPathInlineSchemaTest
parameters:
- name: string_param
in: path
description: string param.
required: true
style: simple
schema:
type: string
- name: enum_param
in: path
description: enum param.
required: true
schema:
type: string
enum:
- hello
- kiota
- generator
responses:
'200':
description: Success
components:
schemas:
EnumParam:
type: string
enum:
- hello
- kiota
- generator
```
Contributor guide
Research direction
Start with the OpenAPI YAML example in the issue and trace how Kiota generates the two C# path-parameter indexers, comparing them with the query-parameter output described. Done means schema-ref and inline enum path parameters use generated enum types and the OpenAPI path property name rather than the confusing `position` name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100