microsoft / kiota

OpenAPI based HTTP Client code generator
https://aka.ms/kiota/docs
MIT License
2.98k stars 208 forks source link

Broken output after converting to workspace in vscode #5782

Open erwinkramer opened 1 day ago

erwinkramer commented 1 day ago

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

Csharp

Describe the bug

I had a lock file like this, generated by the CLI tool:

{
  "descriptionHash": "A8B3FF4FA538A2BB028EFB20C76C6CF203DF1A960CE76CF3AF6519312C4D211D046AE60754840416BF67F8B7AF6BEE0693E9628FB6C06139021D9CE60F82B1EB",
  "descriptionLocation": "../../../specs-downstream/github-api.json",
  "lockFileVersion": "1.0.0",
  "kiotaVersion": "1.20.0",
  "clientClassName": "GitHubClient",
  "typeAccessModifier": "Public",
  "clientNamespaceName": "DownstreamClients.GitHub",
  "language": "CSharp",
  "usesBackingStore": false,
  "excludeBackwardCompatible": false,
  "includeAdditionalData": true,
  "disableSSLValidation": false,
  "serializers": [
    "Microsoft.Kiota.Serialization.Json.JsonSerializationWriterFactory",
    "Microsoft.Kiota.Serialization.Text.TextSerializationWriterFactory",
    "Microsoft.Kiota.Serialization.Form.FormSerializationWriterFactory",
    "Microsoft.Kiota.Serialization.Multipart.MultipartSerializationWriterFactory"
  ],
  "deserializers": [
    "Microsoft.Kiota.Serialization.Json.JsonParseNodeFactory",
    "Microsoft.Kiota.Serialization.Text.TextParseNodeFactory",
    "Microsoft.Kiota.Serialization.Form.FormParseNodeFactory"
  ],
  "structuredMimeTypes": [
    "application/json",
    "text/plain;q=0.9",
    "application/x-www-form-urlencoded;q=0.2",
    "multipart/form-data;q=0.1"
  ],
  "includePatterns": [
    "/repos/{owner}/{repo}/releases/*"
  ],
  "excludePatterns": [],
  "disabledValidationRules": []
}

Then i decided to remove the CLI tool and go with the VSCode extension. This resulted in the extention asking me if i want to convert to a workspace-based Kiota setup, fine, i press OK. This results into the following workspace:

{
  "version": "1.0.0",
  "clients": {
    "GitHubClient": {
      "language": "CSharp",
      "typeAccessModifier": "Public",
      "structuredMimeTypes": [
        "application/json",
        "text/plain;q=0.9",
        "application/x-www-form-urlencoded;q=0.2",
        "multipart/form-data;q=0.1"
      ],
      "clientNamespaceName": "DownstreamClients.GitHub",
      "usesBackingStore": false,
      "includeAdditionalData": true,
      "excludeBackwardCompatible": false,
      "disabledValidationRules": [],
      "descriptionLocation": "./specs-downstream/github-api.json",
      "includePatterns": [
        "/repos/{owner}/{repo}/releases/*"
      ],
      "excludePatterns": [],
      "outputPath": "./bank-api-minimal/DownstreamClients/GitHub"
    }
  },
  "plugins": {}
}

Now i re-generate the client-code by pressing "Re-generate" in the workspace.json.

At this point, my client differs, the following lines are removed in my client:

  ApiClientBuilder.RegisterDefaultSerializer<JsonSerializationWriterFactory>();
  ApiClientBuilder.RegisterDefaultSerializer<TextSerializationWriterFactory>();
  ApiClientBuilder.RegisterDefaultSerializer<FormSerializationWriterFactory>();
  ApiClientBuilder.RegisterDefaultSerializer<MultipartSerializationWriterFactory>();
  ApiClientBuilder.RegisterDefaultDeserializer<JsonParseNodeFactory>();
  ApiClientBuilder.RegisterDefaultDeserializer<TextParseNodeFactory>();
  ApiClientBuilder.RegisterDefaultDeserializer<FormParseNodeFactory>();

And results in the error at runtime (compiles just fine):

An exception of type 'System.InvalidOperationException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'Content type application/json does not have a factory registered to be parsed'

which makes sense considering there was an addition (which Kiota decided it needed while using the CLI) in the lock file which didn't get ported over to the workspace:

 "serializers": [
    "Microsoft.Kiota.Serialization.Json.JsonSerializationWriterFactory",
    "Microsoft.Kiota.Serialization.Text.TextSerializationWriterFactory",
    "Microsoft.Kiota.Serialization.Form.FormSerializationWriterFactory",
    "Microsoft.Kiota.Serialization.Multipart.MultipartSerializationWriterFactory"
  ],
  "deserializers": [
    "Microsoft.Kiota.Serialization.Json.JsonParseNodeFactory",
    "Microsoft.Kiota.Serialization.Text.TextParseNodeFactory",
    "Microsoft.Kiota.Serialization.Form.FormParseNodeFactory"
  ],

Expected behavior

Should be a working and smooth transition.

How to reproduce

Working setup is at https://github.com/erwinkramer/bank-api?tab=readme-ov-file#bank-api

Open API description file

No response

Kiota Version

1.20.0+81bdb1bf13383a749f794d47926d09733d2d7be1

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

No response

Known Workarounds

No response

Configuration

Debug output

No response

Other information

No response

baywet commented 9 hours ago

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

This is by design, we want to make the clients more portable with this iteration. What's odd for you in terms of experience, is that there's no documentation on the migration process and the vscode experience is providing the new workspace system while the CLI is still using the lock experience. We're working on planning, to official bump the version to a v2 and clean this up.

Trying using DefaultRequestAdapter from Microsoft.Kiota.Bundle instead that should get your application working again.

Let us know if you have any additional comments or questions.