Skip to content

Refreshing TypeScript clients in workspace removes (de)serializer registration #7584

@HamsterExAstris

Description

@HamsterExAstris

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

TypeScript

Describe the bug

I am trying to use the workspace feature with TypeScript clients.

The clients generated when running kiota client add work fine. The new versions after running the kiota client generate --refresh command are invalid. The refreshed clients do not register the parseNodeFactorys or the serializationWriterFactorys, which then fails to compile (and likely run but I can't get that far).

src/components/Shared/Api/ClientName/clientNameClient.ts:29:11 - error TS6133: 'backingStoreFactory' is declared but its value is never read.

29     const backingStoreFactory = requestAdapter.getBackingStoreFactory();
             ~~~~~~~~~~~~~~~~~~~

src/components/Shared/Api/ClientName/clientNameClient.ts:31:9 - error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

31     if (parseNodeFactoryRegistry.registerDefaultDeserializer) {
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/components/Shared/Api/ClientName/clientNameClient.ts:34:9 - error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

34     if (serializationWriterFactory.registerDefaultSerializer) {

The bad method looks like the following:

export function createPetStoreClient(requestAdapter: RequestAdapter) {
    if (requestAdapter === undefined) {
        throw new Error("requestAdapter cannot be undefined");
    }
    const serializationWriterFactory = requestAdapter.getSerializationWriterFactory() as SerializationWriterFactoryRegistry;
    const parseNodeFactoryRegistry = requestAdapter.getParseNodeFactory() as ParseNodeFactoryRegistry;
    const backingStoreFactory = requestAdapter.getBackingStoreFactory();
    
    if (parseNodeFactoryRegistry.registerDefaultDeserializer) {
    }
    
    if (serializationWriterFactory.registerDefaultSerializer) {
    }
    
    if (requestAdapter.baseUrl === undefined || requestAdapter.baseUrl === null || requestAdapter.baseUrl === "") {
        requestAdapter.baseUrl = "https://petstore.swagger.io/v2";
    }
    const pathParameters: Record<string, unknown> = {
        "baseurl": requestAdapter.baseUrl,
    };
    return apiClientProxifier<PetStoreClient>(requestAdapter, pathParameters, PetStoreClientNavigationMetadata, undefined);
}

Expected behavior

(De)serializer registrations similar to the following:

export function createPetStoreClient(requestAdapter: RequestAdapter) {
    if (requestAdapter === undefined) {
        throw new Error("requestAdapter cannot be undefined");
    }
    const serializationWriterFactory = requestAdapter.getSerializationWriterFactory() as SerializationWriterFactoryRegistry;
    const parseNodeFactoryRegistry = requestAdapter.getParseNodeFactory() as ParseNodeFactoryRegistry;
    const backingStoreFactory = requestAdapter.getBackingStoreFactory();
    
    if (parseNodeFactoryRegistry.registerDefaultDeserializer) {
        parseNodeFactoryRegistry.registerDefaultDeserializer(JsonParseNodeFactory, backingStoreFactory);
        parseNodeFactoryRegistry.registerDefaultDeserializer(TextParseNodeFactory, backingStoreFactory);
        parseNodeFactoryRegistry.registerDefaultDeserializer(FormParseNodeFactory, backingStoreFactory);
    }
    
    if (serializationWriterFactory.registerDefaultSerializer) {
        serializationWriterFactory.registerDefaultSerializer(JsonSerializationWriterFactory);
        serializationWriterFactory.registerDefaultSerializer(TextSerializationWriterFactory);
        serializationWriterFactory.registerDefaultSerializer(FormSerializationWriterFactory);
        serializationWriterFactory.registerDefaultSerializer(MultipartSerializationWriterFactory);
    }
    
    if (requestAdapter.baseUrl === undefined || requestAdapter.baseUrl === null || requestAdapter.baseUrl === "") {
        requestAdapter.baseUrl = "https://petstore.swagger.io/v2";
    }
    const pathParameters: Record<string, unknown> = {
        "baseurl": requestAdapter.baseUrl,
    };
    return apiClientProxifier<PetStoreClient>(requestAdapter, pathParameters, PetStoreClientNavigationMetadata, undefined);
}

How to reproduce

dotnet kiota workspace init
dotnet kiota client add -l typescript -d https://petstore.swagger.io/v2/swagger.json --client-name PetStoreClient -o ./PetStoreClient --ebc --ad:False
dotnet kiota client generate --refresh

Open API description file

https://petstore.swagger.io/v2/swagger.json

Kiota Version

1.30.0+6ccf6da832742181cba0ab02588c5795b2185e13

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

No response

Known Workarounds

No response

Configuration

  • OS: Windows 11 Enterprise
  • Architecture: x64

Debug output

Click to expand log ``` info: Kiota.Builder.KiotaBuilder[659500454] Cleaning output directory ./PetStoreClient dbug: Kiota.Builder.KiotaBuilder[1405590561] kiota version 1.30.0 dbug: Kiota.Builder.KiotaBuilder[117000264] cache file C:\Users\andre357\AppData\Local\Temp\kiota\cache\generation\3A0927DDD62CDFA9B32CCB0EBD50D7E2D1B137BBE34E6ADF312409D819A9ABC0\swagger.json is out of date, downloading from https://petstore.swagger.io/v2/swagger.json dbug: Kiota.Builder.KiotaBuilder[257770172] cache file C:\Users\andre357\AppData\Local\Temp\kiota\cache\generation\3A0927DDD62CDFA9B32CCB0EBD50D7E2D1B137BBE34E6ADF312409D819A9ABC0\swagger.json not found, downloading from https://petstore.swagger.io/v2/swagger.json info: Kiota.Builder.KiotaBuilder[1281427089] loaded description from remote source dbug: Kiota.Builder.KiotaBuilder[1605292753] step 1 - reading the stream - took 00:00:00.3073247 warn: Kiota.Builder.KiotaBuilder[534942631] OpenAPI warning: #/ - Multiple servers entries were found in the OpenAPI description. Only the first one will be used. The root URL can be set manually with the request adapter. dbug: Kiota.Builder.KiotaBuilder[1605292753] step 2 - parsing the document - took 00:00:00.1065213 dbug: Kiota.Builder.KiotaBuilder[1605292753] step 3 - updating generation configuration from kiota extension - took 00:00:00.0001026 dbug: Kiota.Builder.KiotaBuilder[1605292753] step 4 - filtering API paths with patterns - took 00:00:00.0021908 info: Kiota.Builder.KiotaBuilder[543457275] Client root URL set to https://petstore.swagger.io/v2 dbug: Kiota.Builder.KiotaBuilder[1605292753] step 5 - checking whether the output should be updated - took 00:00:00.0232272 dbug: Kiota.Builder.KiotaBuilder[1605292753] step 6 - create uri space - took 00:00:00.0036852 dbug: Kiota.Builder.KiotaBuilder[1605292753] InitializeInheritanceIndex 00:00:00.0035165 dbug: Kiota.Builder.KiotaBuilder[1605292753] CreateRequestBuilderClass 00:00:00 dbug: Kiota.Builder.KiotaBuilder[1605292753] MapTypeDefinitions 00:00:00.0053572 dbug: Kiota.Builder.KiotaBuilder[1605292753] TrimInheritedModels 00:00:00 dbug: Kiota.Builder.KiotaBuilder[1605292753] CleanUpInternalState 00:00:00 dbug: Kiota.Builder.KiotaBuilder[1605292753] step 7 - create source model - took 00:00:00.0659712 dbug: Kiota.Builder.KiotaBuilder[1306343761] 64ms: Language refinement applied dbug: Kiota.Builder.KiotaBuilder[1605292753] step 8 - refine by language - took 00:00:00.0676846 dbug: Kiota.Builder.KiotaBuilder[1605292753] step 9 - writing files - took 00:00:00.0534654 dbug: Kiota.Builder.KiotaBuilder[117000264] cache file C:\Users\andre357\AppData\Local\Temp\kiota\cache\generation\3A0927DDD62CDFA9B32CCB0EBD50D7E2D1B137BBE34E6ADF312409D819A9ABC0\swagger.json is out of date, downloading from https://petstore.swagger.io/v2/swagger.json dbug: Kiota.Builder.KiotaBuilder[257770172] cache file C:\Users\andre357\AppData\Local\Temp\kiota\cache\generation\3A0927DDD62CDFA9B32CCB0EBD50D7E2D1B137BBE34E6ADF312409D819A9ABC0\swagger.json not found, downloading from https://petstore.swagger.io/v2/swagger.json info: Kiota.Builder.KiotaBuilder[1281427089] loaded description from remote source dbug: Kiota.Builder.KiotaBuilder[1605292753] step 10 - writing lock file - took 00:00:00.0593701 Update of PetStoreClient client completed Client base url set to https://petstore.swagger.io/v2

Hint: use the info command to get the list of dependencies you need to add to your project.
Example: kiota info -a "C:\Temp\working.kiota\apimanifest.json#PetStoreClient" -l TypeScript
info: Kiota.Builder.KiotaBuilder[659500454]
Cleaning output directory ./PetStoreClient2
dbug: Kiota.Builder.KiotaBuilder[1405590561]
kiota version 1.30.0
dbug: Kiota.Builder.KiotaBuilder[117000264]
cache file C:\Users\andre357\AppData\Local\Temp\kiota\cache\generation\3A0927DDD62CDFA9B32CCB0EBD50D7E2D1B137BBE34E6ADF312409D819A9ABC0\swagger.json is out of date, downloading from https://petstore.swagger.io/v2/swagger.json
dbug: Kiota.Builder.KiotaBuilder[257770172]
cache file C:\Users\andre357\AppData\Local\Temp\kiota\cache\generation\3A0927DDD62CDFA9B32CCB0EBD50D7E2D1B137BBE34E6ADF312409D819A9ABC0\swagger.json not found, downloading from https://petstore.swagger.io/v2/swagger.json
info: Kiota.Builder.KiotaBuilder[1281427089]
loaded description from remote source
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 1 - reading the stream - took 00:00:00.0346009
warn: Kiota.Builder.KiotaBuilder[534942631]
OpenAPI warning: #/ - Multiple servers entries were found in the OpenAPI description. Only the first one will be used. The root URL can be set manually with the request adapter.
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 2 - parsing the document - took 00:00:00.0042932
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 3 - updating generation configuration from kiota extension - took 00:00:00.0000006
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 4 - filtering API paths with patterns - took 00:00:00.0074792
info: Kiota.Builder.KiotaBuilder[543457275]
Client root URL set to https://petstore.swagger.io/v2
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 5 - checking whether the output should be updated - took 00:00:00.0003471
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 6 - create uri space - took 00:00:00.0000303
dbug: Kiota.Builder.KiotaBuilder[1605292753]
InitializeInheritanceIndex 00:00:00.0000574
dbug: Kiota.Builder.KiotaBuilder[1605292753]
CreateRequestBuilderClass 00:00:00
dbug: Kiota.Builder.KiotaBuilder[1605292753]
MapTypeDefinitions 00:00:00.0002727
dbug: Kiota.Builder.KiotaBuilder[1605292753]
TrimInheritedModels 00:00:00
dbug: Kiota.Builder.KiotaBuilder[1605292753]
CleanUpInternalState 00:00:00
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 7 - create source model - took 00:00:00.0022750
dbug: Kiota.Builder.KiotaBuilder[1306343761]
2ms: Language refinement applied
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 8 - refine by language - took 00:00:00.0024923
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 9 - writing files - took 00:00:00.0077403
dbug: Kiota.Builder.KiotaBuilder[117000264]
cache file C:\Users\andre357\AppData\Local\Temp\kiota\cache\generation\3A0927DDD62CDFA9B32CCB0EBD50D7E2D1B137BBE34E6ADF312409D819A9ABC0\swagger.json is out of date, downloading from https://petstore.swagger.io/v2/swagger.json
dbug: Kiota.Builder.KiotaBuilder[257770172]
cache file C:\Users\andre357\AppData\Local\Temp\kiota\cache\generation\3A0927DDD62CDFA9B32CCB0EBD50D7E2D1B137BBE34E6ADF312409D819A9ABC0\swagger.json not found, downloading from https://petstore.swagger.io/v2/swagger.json
info: Kiota.Builder.KiotaBuilder[1281427089]
loaded description from remote source
dbug: Kiota.Builder.KiotaBuilder[1605292753]
step 10 - writing lock file - took 00:00:00.0377636
Update of PetStoreClient2 client completed
Client base url set to https://petstore.swagger.io/v2

Hint: use the info command to get the list of dependencies you need to add to your project.
Example: kiota info -a "C:\Temp\working.kiota\apimanifest.json#PetStoreClient2" -l TypeScript

</details>


### Other information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypeScriptPull requests that update Javascript codestatus:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:bugA broken experience

    Type

    No type

    Projects

    Status

    Needs Triage 🔍

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions