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

adds kiota client edit command #4294

Merged
merged 15 commits into from
Mar 7, 2024
Merged

adds kiota client edit command #4294

merged 15 commits into from
Mar 7, 2024

Conversation

baywet
Copy link
Member

@baywet baywet commented Mar 5, 2024

fixes #3356

@baywet baywet self-assigned this Mar 5, 2024
@sebastienlevert
Copy link
Contributor

sebastienlevert commented Mar 6, 2024

When editing a client, the subsequent run loses some parameters. For instance, using the following :

dotnet run --project ~/src/microsoft/kiota/src/kiota/kiota.csproj -- client add --openapi https://raw.githubusercontent.com/sebastienlevert/jsonplaceholder-api/main/openapi.yaml --client-name "PostsClient2" --language csharp --namespace-name "KiotaPosts.Client" --output ./dotnet/generated/posts2

My PostsClient2.cs file looks like this:

// <auto-generated/>
using KiotaPosts.Client.Posts;
using Microsoft.Kiota.Abstractions.Extensions;
using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Serialization.Form;
using Microsoft.Kiota.Serialization.Json;
using Microsoft.Kiota.Serialization.Multipart;
using Microsoft.Kiota.Serialization.Text;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System;
namespace KiotaPosts.Client {
    /// <summary>
    /// The main entry point of the SDK, exposes the configuration and the fluent API.
    /// </summary>
    public class PostsClient2 : BaseRequestBuilder {
        /// <summary>The posts property</summary>
        public PostsRequestBuilder Posts { get =>
            new PostsRequestBuilder(PathParameters, RequestAdapter);
        }
        /// <summary>
        /// Instantiates a new <see cref="PostsClient2"/> and sets the default values.
        /// </summary>
        /// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
        public PostsClient2(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary<string, object>()) {
            ApiClientBuilder.RegisterDefaultSerializer<JsonSerializationWriterFactory>();
            ApiClientBuilder.RegisterDefaultSerializer<TextSerializationWriterFactory>();
            ApiClientBuilder.RegisterDefaultSerializer<FormSerializationWriterFactory>();
            ApiClientBuilder.RegisterDefaultSerializer<MultipartSerializationWriterFactory>();
            ApiClientBuilder.RegisterDefaultDeserializer<JsonParseNodeFactory>();
            ApiClientBuilder.RegisterDefaultDeserializer<TextParseNodeFactory>();
            ApiClientBuilder.RegisterDefaultDeserializer<FormParseNodeFactory>();
            if (string.IsNullOrEmpty(RequestAdapter.BaseUrl)) {
                RequestAdapter.BaseUrl = "https://jsonplaceholder.typicode.com";
            }
            PathParameters.TryAdd("baseurl", RequestAdapter.BaseUrl);
        }
    }
}

When running then this:

dotnet run --project ~/src/microsoft/kiota/src/kiota/kiota.csproj
 -- client edit --client-name "PostsClient2" --language csharp --namespace-name "KiotaPosts.Client.Edit" --output ./dotnet/generated/posts2

My PostsClient2.cs looks like this:

// <auto-generated/>
using KiotaPosts.Client.Edit.Posts;
using Microsoft.Kiota.Abstractions.Extensions;
using Microsoft.Kiota.Abstractions;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System;
namespace KiotaPosts.Client.Edit {
    /// <summary>
    /// The main entry point of the SDK, exposes the configuration and the fluent API.
    /// </summary>
    public class PostsClient2 : BaseRequestBuilder {
        /// <summary>The posts property</summary>
        public PostsRequestBuilder Posts { get =>
            new PostsRequestBuilder(PathParameters, RequestAdapter);
        }
        /// <summary>
        /// Instantiates a new <see cref="PostsClient2"/> and sets the default values.
        /// </summary>
        /// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
        public PostsClient2(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary<string, object>()) {
            if (string.IsNullOrEmpty(RequestAdapter.BaseUrl)) {
                RequestAdapter.BaseUrl = "https://jsonplaceholder.typicode.com";
            }
            PathParameters.TryAdd("baseurl", RequestAdapter.BaseUrl);
        }
    }
}

And I now get serializers registrations error:

ERROR: Content type application/json does not have a factory registered to be parsed
   at Microsoft.Kiota.Abstractions.Serialization.ParseNodeFactoryRegistry.GetRootParseNode(String contentType, Stream content)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.GetRootParseNode(HttpResponseMessage response, CancellationToken cancellationToken)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendCollectionAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendCollectionAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
   at KiotaPosts.Client.Edit.Posts.PostsRequestBuilder.GetAsync(Action`1 requestConfiguration, CancellationToken cancellationToken) in /home/slevert/src/temp/kiota/kiota-config/dotnet/generated/posts/Posts/PostsRequestBuilder.cs:line 62
   at Program.<Main>$(String[] args) in /home/slevert/src/temp/kiota/kiota-config/dotnet/Program.cs:line 17

@sebastienlevert
Copy link
Contributor

sebastienlevert commented Mar 6, 2024

When using the same name of the client in different casing, it works. Should we consider this a "good thing" or a "bad thing"? I don't know what the implications could be but it feels a little bit scary IMO.

{
  "version": "1.0.0",
  "clients": {
    "PostsClient": {
      "descriptionLocation": "https://raw.githubusercontent.com/sebastienlevert/jsonplaceholder-api/main/openapi.yaml",
      "language": "CSharp",
      "structuredMimeTypes": [
        "application/json",
        "text/plain;q=0.9",
        "application/x-www-form-urlencoded;q=0.2",
        "multipart/form-data;q=0.1"
      ],
      "includePatterns": [],
      "excludePatterns": [],
      "outputPath": "./dotnet/generated/posts",
      "clientNamespaceName": "KiotaPosts.Client.Edit2",
      "usesBackingStore": false,
      "includeAdditionalData": true,
      "excludeBackwardCompatible": false,
      "disabledValidationRules": []
    },
    "postsClient": {
      "descriptionLocation": "https://raw.githubusercontent.com/sebastienlevert/jsonplaceholder-api/main/openapi.yaml",
      "language": "TypeScript",
      "structuredMimeTypes": [
        "application/json",
        "text/plain;q=0.9",
        "application/x-www-form-urlencoded;q=0.2",
        "multipart/form-data;q=0.1"
      ],
      "includePatterns": [],
      "excludePatterns": [],
      "outputPath": "./typescript/generated/posts",
      "clientNamespaceName": "ApiSdk",
      "usesBackingStore": false,
      "includeAdditionalData": true,
      "excludeBackwardCompatible": false,
      "disabledValidationRules": []
    }
  }
}

Same thing for files in the clients folder with the cached OpenAPI descriptions. I think this will blow up on Windows. (I'm on WSL right now)

image

The apimanifest.json file is all mixed up and considers both as the same (when mixing cases). So when adding a new one with the same name but different casing it doesn't add it to the apimanifest.yml file and when removing it, it removes the wrong one.

@sebastienlevert
Copy link
Contributor

When removing a client, we do not remove the cached yaml file for the client in the .kiota folder.

I ran this and the information and generated output was removed, but not the clients content for this client:

dotnet run --project ~/src/microsoft/kiota/src/kiota/kiota.csproj -- client remove --client-name "PostsClient2" --clean-output

image

@sebastienlevert
Copy link
Contributor

When running the remove command, we should output some sort of confirmation that the client was removed? Right it just silently returns. Add, edit and generate are a lot more verbose.

image

Base automatically changed from feature/generate-client to main March 6, 2024 09:49
baywet added 8 commits March 6, 2024 08:03
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
@baywet
Copy link
Member Author

baywet commented Mar 6, 2024

Thanks for all the great feedback Seb!

The api dependencies with difference casing issue will be fixed once this is merged and the dependency is updated in kiota.
microsoft/OpenApi.ApiManifest#78

@baywet baywet force-pushed the feature/edit-client branch from 7f785d0 to 7c97dc9 Compare March 6, 2024 16:09
@baywet
Copy link
Member Author

baywet commented Mar 6, 2024

for the directory removal, I'll only be able to remove /clients, not .kiota. This is because it's where we're placing the log file, and it's in use.

@baywet baywet marked this pull request as ready for review March 6, 2024 17:06
@baywet baywet requested a review from a team as a code owner March 6, 2024 17:06
- updates changelog for one twelve release
@baywet baywet enabled auto-merge March 7, 2024 13:55
Copy link

sonarqubecloud bot commented Mar 7, 2024

@baywet baywet merged commit 1735a2f into main Mar 7, 2024
193 checks passed
@baywet baywet deleted the feature/edit-client branch March 7, 2024 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Kiota.Config for managing multiple API dependencies in a project.
3 participants