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][http] getHttpOperation can't find right contentTypes #2938

Open
msyyc opened this issue Feb 20, 2024 · 5 comments · May be fixed by Azure/typespec-azure#399
Open

[bug][http] getHttpOperation can't find right contentTypes #2938

msyyc opened this issue Feb 20, 2024 · 5 comments · May be fixed by Azure/typespec-azure#399
Assignees
Labels
bug Something isn't working triaged:core

Comments

@msyyc
Copy link

msyyc commented Feb 20, 2024

For the following tsp, getHttpOperation can't return type with right contentTypes:

import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-client-generator-core";
import "@typespec/rest";
import "@typespec/versioning";

using TypeSpec.Rest;
using TypeSpec.Http;
using TypeSpec.Versioning;
using Azure.Core;
using Azure.Core.Traits;
using Azure.ClientGenerator.Core;

@service({
    title: "Test service",
})
@versioned(Versions)
namespace Test;

enum Versions {
    @doc("2022-12-01-preview")
    @useDependency(global.Azure.Core.Versions.v1_0_Preview_2)
    v2022_12_01_preview: "2022-12-01-preview",
}

@TypeSpec.Rest.resource("deployments")
model Deployment {
    @visibility("read")
    @projectedName("java", "deploymentOrModelName")
    @key
    deploymentId: string;
}

model AudioTranscriptionOptions {
    @projectedName("csharp", "AudioData")
    file: bytes;
}

@doc("Result information for an operation that transcribed spoken audio into written text.")
model AudioTranscription {
    text: string;
}

alias MultipartFormDataRequestHeadersTraits = Azure.Core.Traits.RequestHeadersTrait<{
    @header("content-type")
    contentType: "multipart/form-data";
}>;

@actionSeparator("/")
@action("audio/transcriptions")
op getAudioTranscriptionAsPlainText is Azure.Core.Foundations.ResourceOperation<
    Deployment,
    AudioTranscriptionOptions,  // response_format must be one of: text, srt, vtt
    string,
    MultipartFormDataRequestHeadersTraits
>;

image

But for some template it can:

@actionSeparator("/")
@action("audio/transcriptions")
op getAudioTranscriptionAsResponseObject is Azure.Core.ResourceAction<
    Deployment,
    AudioTranscriptionOptions,  // response_format must be unspecified (json) or one of: json, verbose_json
    AudioTranscription,
    MultipartFormDataRequestHeadersTraits
>;

image

I guess there may be bug for specific template.

@timotheeguerin
Copy link
Member

I don't think that would be an issue with the http library, i think this is most likely the trait is not applying correctly

@timotheeguerin
Copy link
Member

timotheeguerin commented Feb 20, 2024

If you look at this playground you can see that adding other header doesn't apply
Repro

I think this is a long standing issue with trait not working correctly on Azure.Core.Foundations.ResourceOperation

And if you check the type graph the operation parameters doesn't have those properties

@markcowl markcowl added the bug Something isn't working label Feb 20, 2024
@markcowl markcowl added this to the [2024] April milestone Feb 20, 2024
@msyyc
Copy link
Author

msyyc commented Feb 21, 2024

So it seems bug of typespec-azure-core? If that, I feel OK to transfer the issue to typespec-azure repo.

@timotheeguerin
Copy link
Member

This problem is too deep into the traits making it I think impossible to fix without the complete rethinking of how traits work

@markcowl markcowl self-assigned this Apr 30, 2024
@markcowl
Copy link
Contributor

markcowl commented May 7, 2024

@markcowl linkt to trait redesign issues

@markcowl markcowl removed this from the [2024] May milestone May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triaged:core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants