Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSharp - enum path parameters not generated #4340

Open
HaydnDias opened this issue Mar 14, 2024 · 3 comments
Open

CSharp - enum path parameters not generated #4340

HaydnDias opened this issue Mar 14, 2024 · 3 comments
Labels
generator Issues or improvements relater to generation capabilities. help wanted Issue caused by core project dependency modules or library type:bug A broken experience
Milestone

Comments

@HaydnDias
Copy link

HaydnDias commented Mar 14, 2024

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
#3785
#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
@andrueastman
Copy link
Member

Thanks for raising this @HaydnDias

Looks like the type handler was updated only to expect primitives in the path and not enums when the backward compatible changes were made.

var type = parameter switch

@baywet Any chance you can confirm if there is/was any reason to not include enums?

@andrueastman andrueastman added type:bug A broken experience generator Issues or improvements relater to generation capabilities. labels Mar 18, 2024
@andrueastman andrueastman added this to the Backlog milestone Mar 18, 2024
@baywet
Copy link
Member

baywet commented Mar 18, 2024

@andrueastman this was probably an oversight from my end.
Since we already have a backward compatibility mechanism for the other non string types, I'd go ahead and add the enum types in here as well.
@HaydnDias is this something you're willing to submit a pull request for?

@HaydnDias
Copy link
Author

@baywet @andrueastman , thanks both for looking, unfortuantely I don't have the capacity to raise a PR for this atm and have a workaround to unblock me for my current workstream due to the urgency, once I have a bit more time soon though I'm happy to come back and take a look if the issue is still open.

@baywet baywet added the help wanted Issue caused by core project dependency modules or library label Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator Issues or improvements relater to generation capabilities. help wanted Issue caused by core project dependency modules or library type:bug A broken experience
Projects
Status: Todo 📃
Development

No branches or pull requests

3 participants