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

OData WebAPI, RequestBuilderGetQueryParameters Count property type has typo #4832

Closed
pschmerling opened this issue Jun 14, 2024 · 3 comments
Closed
Labels
Csharp Pull requests that update .net code Needs: Attention 👋 type:question An issue that's a question
Milestone

Comments

@pschmerling
Copy link

pschmerling commented Jun 14, 2024

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Windows executable

Client library/SDK language

Csharp

Describe the bug

I generate an SDK using kiota commandline on a .NET 8 WebAPI with OData. The resulting source code cannot be compiled because of typo in every class named RequestBuilder > RequestBuilderGetQueryParameters.
Integer or boolean properties have the type written in camel-case - which is not valid c#. For example Int instead of int, Bool instead of bool. String properties are ok.
swagger.json
Produces AdditionalMatterResponsiblesRequestBuilder.cs containing class AdditionalMatterResponsiblesRequestBuilderGetQueryParameters, which contains

/// <summary>Adds count property</summary>
[QueryParameter("%24count")]
public Bool? Count { get; set; }

/// <summary>Number of objects to skip in the current order (ex. 50)</summary>
[QueryParameter("%24skip")]
public Int? Skip { get; set; }

/// <summary>Number of objects to return. (ex. 25)</summary>
[QueryParameter("%24top")]
public Int? Top { get; set; }

I tried to find the appropriate code in the kiota-source. Please correct me if I am wrong. Is the TranslateType (src/Kiota.Builder/Writers/CSharp/CSharpConventionService.cs) method missing the two cases for "int" and "bool"?

Expected behavior

RequestBuilder > RequestBuilderGetQueryParameters. The type int and bool must be written in lower-case.

How to reproduce

kiota commandline on a .NET 8 WebAPI with OData

Open API description file

swagger.json

Kiota Version

1.15.0

@pschmerling pschmerling added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Jun 14, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Jun 14, 2024
@baywet baywet added question status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question and removed type:bug A broken experience status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Jun 17, 2024
@baywet baywet moved this from Needs Triage 🔍 to Waits for author 🔁 in Kiota Jun 17, 2024
@baywet baywet added this to the Backlog milestone Jun 17, 2024
@baywet
Copy link
Member

baywet commented Jun 17, 2024

Hi @pschmerling
Thanks for using kiota and for reaching out.
I'm not exactly sure why your description is getting generated this way, it's invalid.
"int" parameters should be "integer"
"bool" parameters should be "boolean".
Feeding the description you've provided to spectral will give many "Value is not accepted. Valid values: "array", "boolean", "integer", "number", "object", "string"" errors.
I suggest that you reach out to the owners of the library you use to generate the description.

@pschmerling
Copy link
Author

Hi @baywet
Thank you so much for your answer. You pointed me to the right direction. Because Swashbuckle for asp.net core is not able to detect the parameters of an EnabledQuery endpoint at all, I had to do this manually using an OperationFilter. I corrected the parameter-generation in this OperationFilter.

...
if (enableQueryAttribute.AllowedQueryOptions.HasFlag(AllowedQueryOptions.Count)) {
    operation.Parameters.Add(new OpenApiParameter() {
        Name = "$count",
        In = ParameterLocation.Query,
        Schema = new OpenApiSchema {
            Type = "boolean", // previously "bool"
        },
        Description = "Adds count property",
        Required = false
    });
}

if (enableQueryAttribute.AllowedQueryOptions.HasFlag(AllowedQueryOptions.Top)) {
    operation.Parameters.Add(new OpenApiParameter() {
        Name = "$top",
        In = ParameterLocation.Query,
        Schema = new OpenApiSchema {
            Type = "integer", // previously "int"
        },
        Description = "Number of objects to return. (ex. 25)",
        Required = false
    });
}

if (enableQueryAttribute.AllowedQueryOptions.HasFlag(AllowedQueryOptions.Skip)) {
    operation.Parameters.Add(new OpenApiParameter() {
        Name = "$skip",
        In = ParameterLocation.Query,
        Schema = new OpenApiSchema {
            Type = "integer", // previously "int"
        },
        Description = "Number of objects to skip in the current order (ex. 50)",
        Required = false
    });
}
...

Now the generated description is validating successfully in spectral - thank you for this hint, too.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Jun 17, 2024
@andrueastman
Copy link
Member

Thanks for confirming @pschmerling

We'll close this one for now as there's no action on our side. Feel free to re-open or create new issue in the event of anything else.

@github-project-automation github-project-automation bot moved this from Waits for author 🔁 to Done ✔️ in Kiota Jun 18, 2024
@msgraph-bot msgraph-bot bot added the Csharp Pull requests that update .net code label Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Csharp Pull requests that update .net code Needs: Attention 👋 type:question An issue that's a question
Projects
Archived in project
Development

No branches or pull requests

3 participants