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

Wrong Record type generated in Typescript client #5027

Closed
ThisIsDemetrio opened this issue Jul 26, 2024 · 6 comments
Closed

Wrong Record type generated in Typescript client #5027

ThisIsDemetrio opened this issue Jul 26, 2024 · 6 comments
Labels
Status: No Recent Activity status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question TypeScript Pull requests that update Javascript code

Comments

@ThisIsDemetrio
Copy link

ThisIsDemetrio commented Jul 26, 2024

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Linux executable

Client library/SDK language

TypeScript

Describe the bug

Hi there. I'm having an issue generating a Typescript client from an OpenAPI v3 definition because properties with that includes the following schema:

{
    "openapi": "3.0.3",
    "info": { ... },
    "paths": {
        "/api/dict": {
            "get": {
                ...
                "responses": {
                    "200": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "additionalProperties": false,
                                    "properties": {
                                        "data": {
                                            "additionalProperties": {
                                                "type": "string"
                                            },
                                            "type": "object"
                                        }
                                    },
                                    "type": "object"
                                }
                            }
                        },
                        ...
                    },
                  ...

Generates a client with the following interface for the GET:

export interface DictGetResponse extends Parsable {
    /**
     * The data property
     */
    data?: DictGetResponse_data;
}
export interface DictGetResponse_data extends Parsable {
}

The problem here is that I cannot use the DictGetResponse_data as intended, which means that the object data might include any type of property with value string, like the following:

const example: DictGetResponse = {
  data: {
    something: 'something', // <-- Object literal may only specify known properties, and 'something' does not exist in type 'DictGetResponse_data'.
  },
}

Expected behavior

I'm expecting to have the Typescript definition with something like this:

export interface DictGetResponse extends Parsable {
    /**
     * The data property
     */
    data?: DictGetResponse_data;
}
export interface DictGetResponse_data extends Parsable {
    /**
     * Because of the "additionalProperties": { "type": "string" }
     */
    [key: string]: string;
}

How to reproduce

Simply run the kiota generate script with the JSON passed below.

Open API description file

simple-client.json

This JSON file contains a definition which it can be used to reproduce the issue.

Kiota Version

1.16.0

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

No response

Configuration

Ubuntu 22.04

Debug output

Click to expand log ```

dbug: Kiota.Builder.KiotaBuilder[0]
kiota version 1.16.0
info: Kiota.Builder.KiotaBuilder[0]
loaded description from local source
dbug: Kiota.Builder.KiotaBuilder[0]
step 1 - reading the stream - took 00:00:00.0065043
warn: Kiota.Builder.KiotaBuilder[0]
OpenAPI warning: #/ - A servers entry (v3) or host + basePath + schemes properties (v2) was not present in the OpenAPI description. The root URL will need to be set manually with the request adapter.
dbug: Kiota.Builder.KiotaBuilder[0]
step 2 - parsing the document - took 00:00:00.1028318
dbug: Kiota.Builder.KiotaBuilder[0]
step 3 - updating generation configuration from kiota extension - took 00:00:00.0001083
dbug: Kiota.Builder.KiotaBuilder[0]
step 4 - filtering API paths with patterns - took 00:00:00.0037455
warn: Kiota.Builder.KiotaBuilder[0]
No server url found in the OpenAPI document. The base url will need to be set when using the client.
dbug: Kiota.Builder.KiotaBuilder[0]
step 5 - checking whether the output should be updated - took 00:00:00.0238744
dbug: Kiota.Builder.KiotaBuilder[0]
step 6 - create uri space - took 00:00:00.0037604
dbug: Kiota.Builder.KiotaBuilder[0]
InitializeInheritanceIndex 00:00:00.0030867
dbug: Kiota.Builder.KiotaBuilder[0]
CreateRequestBuilderClass 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
MapTypeDefinitions 00:00:00.0035410
dbug: Kiota.Builder.KiotaBuilder[0]
TrimInheritedModels 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
CleanUpInternalState 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
step 7 - create source model - took 00:00:00.0525411
dbug: Kiota.Builder.KiotaBuilder[0]
43ms: Language refinement applied
dbug: Kiota.Builder.KiotaBuilder[0]
step 8 - refine by language - took 00:00:00.0444799
dbug: Kiota.Builder.KiotaBuilder[0]
step 9 - writing files - took 00:00:00.0289156
info: Kiota.Builder.KiotaBuilder[0]
loaded description from local source
dbug: Kiota.Builder.KiotaBuilder[0]
step 10 - writing lock file - took 00:00:00.0086584
Generation completed successfully
dbug: Kiota.Builder.KiotaBuilder[0]
Api manifest path: /home/demetrio/mia/console-sdk/packages/console-client/apimanifest.json

</details>


### Other information

_No response_
@ThisIsDemetrio ThisIsDemetrio added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Jul 26, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Jul 26, 2024
@msgraph-bot msgraph-bot bot added the TypeScript Pull requests that update Javascript code label Jul 26, 2024
@ThisIsDemetrio ThisIsDemetrio changed the title Wrong of Record type in Typescript client Wrong Record type generated in Typescript client Jul 26, 2024
@baywet
Copy link
Member

baywet commented Jul 26, 2024

Hi @ThisIsDemetrio
Thanks for using kiota and for reaching out.
This is a limitation today see #62
What's interesting though is that your model should implement AdditionalDataHolder. Did you disable it through the CLI switch while generating?

@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 and removed type:bug A broken experience status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Jul 26, 2024
@baywet baywet moved this from Needs Triage 🔍 to Waits for author 🔁 in Kiota Jul 26, 2024
@ThisIsDemetrio
Copy link
Author

Hi @ThisIsDemetrio
Thanks for using kiota and for reaching out.
This is a limitation today see #62
What's interesting though is that your model should implement AdditionalDataHolder. Did you disable it through the CLI switch while generating?

Hi @baywet! Thank you for your reply.

Thanks as well for finding out the issue related to this. I tried a little search, but probably I should had dig more.

Regarding the AdditionalDataHolder.. yes, I intentionally disabled during the experiments that I included here.

We have a project that it is using Kiota with the additionalData, but this caused some confusion since we expected to use it for additional properties to the schema but it actually created a new property that we aren't actually using.

Anyway, I'm following the issue you linked hoping for a quick implementation that we can use in our project. Thanks again!

@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 Jul 26, 2024
@baywet
Copy link
Member

baywet commented Jul 29, 2024

Thank you for the additional information here .
This issue i linked will most likely take a while to be addressed since it requires work to be finished in an upstream dependency before we can do anything in kiota itself.
I'm curious as to why you disabled the additional data holder generation in the code initially, besides maybe a lack of understanding of what it was supposed to be used for?
Using the additional data holder, are you able to get the payload you expect?

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Jul 29, 2024
@ThisIsDemetrio
Copy link
Author

Thank you for the additional information here . This issue i linked will most likely take a while to be addressed since it requires work to be finished in an upstream dependency before we can do anything in kiota itself. I'm curious as to why you disabled the additional data holder generation in the code initially, besides maybe a lack of understanding of what it was supposed to be used for? Using the additional data holder, are you able to get the payload you expect?

Yes, please just considering that as a tentative to understand its usage and to simplify the code pasted when opening the issue.

I've in plan to do additional test regarding Kiota. Am I supposed to expect that the additionalData property attached will include the properties that should be at the root of the object itself?

@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 Jul 29, 2024
@baywet
Copy link
Member

baywet commented Jul 29, 2024

I've in plan to do additional test regarding Kiota. Am I supposed to expect that the additionalData property attached will include the properties that should be at the root of the object itself?

Correct.

Let us know if you have further questions or if we can close the issue.

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Jul 29, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@github-project-automation github-project-automation bot moved this from Waits for author 🔁 to Done ✔️ in Kiota Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: No Recent Activity status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question TypeScript Pull requests that update Javascript code
Projects
Archived in project
Development

No branches or pull requests

2 participants