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

all languages | Generating enums from query parameter #2490

Closed
sirmrowa opened this issue Mar 30, 2023 · 7 comments · Fixed by #3477
Closed

all languages | Generating enums from query parameter #2490

sirmrowa opened this issue Mar 30, 2023 · 7 comments · Fixed by #3477
Assignees
Labels
enhancement New feature or request generator Issues or improvements relater to generation capabilities. WIP
Milestone

Comments

@sirmrowa
Copy link

sirmrowa commented Mar 30, 2023

When the query parameter is defined as an enum, no code for this enum is generated.

OpenApi spec:

openapi: 3.0.3
info:
    title: TestApi
    version: 1.0.0
  
paths:
    /users:
        get:
            parameters:
                - name: type
                  in: query
                  schema:
                    type: string
                    enum: [TYPE1, TYPE2]
            responses:
                '204':
                    description: No content

Generates:

public class UsersRequestBuilderGetQueryParameters {
   public string? Type { get; set; }
}

where Type should be enum instead of string

@baywet baywet self-assigned this Mar 30, 2023
@baywet baywet added enhancement New feature or request generator Issues or improvements relater to generation capabilities. and removed Needs: Triage 🔍 labels Mar 30, 2023
@baywet baywet added this to Kiota Mar 30, 2023
@github-project-automation github-project-automation bot moved this to Todo in Kiota Mar 30, 2023
@baywet baywet added this to the Kiota v2 milestone Mar 30, 2023
@baywet
Copy link
Member

baywet commented Mar 30, 2023

Thanks for reporting this. It was a design decision at the time since serializing enums comes with constraints (as seen in #2488 )
This is something we'd need to address for version 2 of kiota since it'd be a binary breaking change in the case of C#

@sirmrowa
Copy link
Author

@baywet Thanks for Your answer. Enums with constraints are another big story, but simple serializing works perfectly when an enum is part of a request/response object. Maybe this could be done in this release?

@baywet
Copy link
Member

baywet commented Mar 31, 2023

We can't as it'd be a binary breaking change.

Imagine somebody has the existing following code based on a client the generated with kiota

var result = await client.Path1.Path2.GetAsync(x => x.QueryParameters.Param1 = "value1");

If we switch the generation to enums, they'll have to update their code to when they refresh their client. Which violates our support policy.

var result = await client.Path1.Path2.GetAsync(x => x.QueryParameters.Param1 = EnumType.Value1);

The reason that support constraint is so people can update kiota's minor and patch versions trusting it won't break their clients and code.
I hope this additional context helps set the frame.

@sirmrowa
Copy link
Author

@baywet You are right. This is a breaking change for already generated code.

@baywet baywet changed the title CSharp | Generating enums from query parameter all languages | Generating enums from query parameter Jul 19, 2023
@baywet
Copy link
Member

baywet commented Jul 19, 2023

note additional information for implementation can be found in #2306

@baywet
Copy link
Member

baywet commented Sep 27, 2023

Now that we've introduced a pattern where we could project both without leading to a breaking change (using obsolete annotations) in #2952, we should reconsider this one for 1.8

@baywet
Copy link
Member

baywet commented Oct 12, 2023

addressed with #3477

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request generator Issues or improvements relater to generation capabilities. WIP
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants