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

openapi from odata error #5247

Closed
marcioatws opened this issue Aug 18, 2024 · 3 comments · Fixed by #5248
Closed

openapi from odata error #5247

marcioatws opened this issue Aug 18, 2024 · 3 comments · Fixed by #5248
Assignees
Labels
type:bug A broken experience TypeScript Pull requests that update Javascript code
Milestone

Comments

@marcioatws
Copy link

I generated the openapi spec from an odata application and the typescript client in kiota didn't work with the url parentheses. for example, for the url http://aaaa.bbb/entities({id}) in the model, a method called entitiesWithId(type | undefined) was generated and when used it causes an error that entitiesWithId is not a function. i can generate some code for error reproduction if need it.

Another situation is that using the "strict" option in the typescript settings, the following error message is generated in all models:

src/app/models/contratoAggregate/index.ts:125:95 - error TS2345: Argument of type '(writer: SerializationWriter, contrato?: Partial | undefined) => void' is not assignable to parameter of type 'ModelSerializerFunction'.
Types of parameters 'contrato' and 'value' are incompatible.
Type 'Partial | null | undefined' is not assignable to type 'Partial | undefined'.
Type 'null' is not assignable to type 'Partial | undefined'.

writer.writeCollectionOfObjectValues<Contrato>("value", contratoCollectionResponse.value, serializeContrato);
@baywet
Copy link
Member

baywet commented Aug 19, 2024

Hi @marcioatws
Thank you for using kiota and for reaching out.

For the parameter type this was introduced by microsoft/kiota-typescript#1248 and needs the corresponding generator changes to function properly #5163. You can use the latest preview release and re-generate the client.

For the non-existent function, can you provide a repro description please?

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question labels Aug 19, 2024
@marcioatws
Copy link
Author

sry for late response.

Repo for error: https:/marcioatws/kiota-odata-error
Kiota version: 1.17.0+1eb16cd65853c17179e2dde3ae6098135deacf55

I will try to summarize the issue again.

Sample Backend Controller:

app.MapGet("/products/{id:int}", (int id) =>
{
    var product = products.FirstOrDefault(p => p.Id == id);
    return product is not null ? Results.Ok(product) : Results.NotFound();
});

// url format in odata spec 
app.MapGet("/products({id:int})", (int id) =>
{
    var product = products.FirstOrDefault(p => p.Id == id);
    return product is not null ? Results.Ok(product) : Results.NotFound();
});

Client Generation Command:

kiota generate --clean-output --exclude-backward-compatible --language typescript --openapi "xxx" --output "xxx"

TypeScript Client Output:

image

export interface ApiClient extends BaseRequestBuilder<ApiClient> {
    /**
     * The products property
     */
    get products(): ProductsRequestBuilder;
    /**
     * Builds and executes requests for operations under /products({id})
     * @param id The path parameter: id
     * @returns {ProductsWithIdRequestBuilder}
     */
     productsWithId(id: number | undefined) : ProductsWithIdRequestBuilder;
}

However, calling productsWithId results in a "not a function" error.

sorry for my english, it's not my language.

@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 Status: No Recent Activity labels Aug 26, 2024
@baywet baywet transferred this issue from microsoft/kiota-typescript Aug 26, 2024
@baywet baywet self-assigned this Aug 26, 2024
@baywet baywet added type:bug A broken experience TypeScript Pull requests that update Javascript code and removed Needs: Attention 👋 type:question An issue that's a question labels Aug 26, 2024
@baywet baywet added this to the Kiota v1.18 milestone Aug 26, 2024
@baywet
Copy link
Member

baywet commented Aug 26, 2024

Thank you for the additional information.
I have transferred the issue to the main repository since it's a generation issue.
I have authored #5248 to address the issue.
Once the pull request is merged, you'll need to regenerate the client from the upcoming preview (Thursday) or build kiota locally.
Additionally, here is a patch file that illustrates the changes on the client.
patchfile.patch
Let us know if you have any additional comments or questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug A broken experience TypeScript Pull requests that update Javascript code
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants