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

[Bug]: The clientOption stub generated by StubLibraryPlugin for versioned cannot compile #4690

Closed
4 tasks done
chunyu3 opened this issue Oct 11, 2024 · 1 comment · Fixed by #4691
Closed
4 tasks done
Assignees
Labels
bug Something isn't working emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Comments

@chunyu3
Copy link
Contributor

chunyu3 commented Oct 11, 2024

Describe the bug

When generate stub library for a versioned service, the clientOptions class stub cannot compile because the LastestVersion private field is not generated which is used in public constructor.

generated stub:

namespace Server.Path.Multiple
{
    public partial class MultipleClientOptions : ClientPipelineOptions
    {

        public MultipleClientOptions(ServiceVersion version = LatestVersion) => throw null;

        public enum ServiceVersion
        {
            /// <summary> Version 1.0. </summary>
            V1_0 = 1
        }
    }
}

expected:

namespace Server.Path.Multiple
{
    public partial class MultipleClientOptions : ClientPipelineOptions
    {
        private const ServiceVersion LatestVersion = ServiceVersion.V1_0;

        public MultipleClientOptions(ServiceVersion version = LatestVersion) => throw null;

        public enum ServiceVersion
        {
            /// <summary> Version 1.0. </summary>
            V1_0 = 1
        }
    }
}

Reproduction

Define a versioned service, and then generate stub library for it.

you can use the cadl-ranch test project [http-server-path-multiple ] (https://github.com/Azure/cadl-ranch/tree/main/packages/cadl-ranch-specs/http/server/path/multiple)

Checklist

@chunyu3 chunyu3 added the bug Something isn't working label Oct 11, 2024
@chunyu3 chunyu3 self-assigned this Oct 11, 2024
@chunyu3 chunyu3 added emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp and removed needs-area labels Oct 11, 2024
@chunyu3
Copy link
Contributor Author

chunyu3 commented Oct 16, 2024

Change the solution to not generate the public constructor for clientOptions, like

namespace Server.Path.Multiple
{
    public partial class MultipleClientOptions : ClientPipelineOptions
    {
    }
}

github-merge-queue bot pushed a commit that referenced this issue Oct 17, 2024
Fix #3986
Fix #4673
Fix #4690

- support api-version is a path parameter. We will add a `_apiVersion`
field in the client, and will use `_apiVersion` field in
`CreateXXXMessage`
- When the type of api-version is Enum, we will convert it to string
- Not to generate constructor for `ClientOptionsProvider` in
`stubLibraryVistor`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant