Skip to content

CSharp - enum path parameters not generated #4340

@HaydnDias

Description

@HaydnDias

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) 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:
#3693
#2490
microsoft/kiota-abstractions-ruby#61
#3783
#3784

Example:

Generates (for both examples):

/// <summary>Gets an item from the ExampleApi.example2.item.item collection</summary>
/// <param name="position">enum param.</param>
/// <returns>A <see cref="WithEnum_paramItemRequestBuilder"/></returns>
public WithEnum_paramItemRequestBuilder this[string position] { get {
    var urlTplParams = new Dictionary<string, object>(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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    generatorIssues or improvements relater to generation capabilities.help wantedIssue caused by core project dependency modules or librarytype:bugA broken experience

    Type

    No type

    Projects

    Status

    New📃

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions