Skip to content

[Bug][http-client-js]: the mfd part serialization is problematic #6848

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

Open
4 tasks done
qiaozha opened this issue Apr 3, 2025 · 5 comments
Open
4 tasks done

[Bug][http-client-js]: the mfd part serialization is problematic #6848

qiaozha opened this issue Apr 3, 2025 · 5 comments
Assignees
Labels
bug Something isn't working emitter:client:js Issue for the JS client emitter: @typespec/http-client-js

Comments

@qiaozha
Copy link
Member

qiaozha commented Apr 3, 2025

Describe the bug

in todoApp, we have mfd operations

model FileAttachmentMultipartRequest {
  contents: HttpPart<File>;
}
    @post
    op createFileAttachment(
      @header contentType: "multipart/form-data",
      @path itemId: TodoItem.id,
      @multipartBody body: FileAttachmentMultipartRequest,
    ): WithStandardErrors<NoContentResponse | NotFoundErrorResponse>;

which the operation inline serialization logic should be enough

export async function createFileAttachment(
  client: AttachmentsClientContext,
  itemId: number,
  body: FileAttachmentMultipartRequest,
  options?: CreateFileAttachmentOptions,): Promise<void> {
  const path = parse("/items/{itemId}/attachments").expand({
    "itemId": itemId
  });
  const httpRequestOptions = {
    headers: {
      "content-type": options?.contentType ?? "multipart/form-data"
    },body: [createFilePartDescriptor("contents", body.contents)], // this should be enough
  };
  const response = await client.pathUnchecked(path).post(httpRequestOptions)

  if (typeof options?.operationOptions?.onResponse === "function") {
    options?.operationOptions?.onResponse(response);
  }
  ;if (+response.status === 204 && !response.body) {
    return;
  }throw createRestError(response);
};

but we also generate the serialization for the models as the following, which is wrong.

export function jsonFileAttachmentMultipartRequestToApplicationTransform(
  input_?: any,): FileAttachmentMultipartRequest {
  if(!input_) {
    return input_ as any;
  }
    return {
     "contents": jsonFileToApplicationTransform(input_.contents)
  }!;
}

Reproduction

https://github.com/allenjzhang/typespec-e2e-demo/tree/main/todoApp/spec

Checklist

@qiaozha qiaozha added the bug Something isn't working label Apr 3, 2025
@qiaozha qiaozha added the emitter:client:js Issue for the JS client emitter: @typespec/http-client-js label Apr 3, 2025
@qiaozha qiaozha added the 1_0_E2E label Apr 3, 2025
@joheredi
Copy link
Member

joheredi commented Apr 3, 2025

This shouldn't really impact the client, I agree we probably don't want to generate jsonFileAttachmentMultipartRequestToApplicationTransform if it is not used but the operations doesn't seem to use it

@joheredi joheredi removed the 1_0_E2E label Apr 3, 2025
@qiaozha qiaozha self-assigned this Apr 18, 2025
@qiaozha qiaozha assigned timovv and unassigned qiaozha Apr 29, 2025
@qiaozha
Copy link
Member Author

qiaozha commented Apr 29, 2025

@timovv the generated serializer is failing the compile in this case, therefore, we still need to fix it.

@timovv
Copy link
Member

timovv commented May 6, 2025

I tested this on my local with the todo spec and TypeSpec 1.0.0-rc.1 the other day. This particular serializer appears to be compiling (although there seems to be an unrelated issue to do with visibility in another serializer...). What's the exact error that's showing up here? I agree that we shouldn't generate the helper if it's not actually being used, but don't think that this is a super high priority if it's not affecting compilation or the public API surface.

@qiaozha
Copy link
Member Author

qiaozha commented May 7, 2025

Currently the generation is blocked by this #6847 I can't repro this issue. But it's affecting the compilation.

Image

@timovv
Copy link
Member

timovv commented May 7, 2025

Those errors should be fixed by #7194. But even so, there's still compiled output despite the error diagnostics and when I looked at that the helper didn't have any error.

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:js Issue for the JS client emitter: @typespec/http-client-js
Projects
None yet
Development

No branches or pull requests

3 participants