Skip to content

fix(openapi3): resolve "Duplicate type name" error for named union with bytes in multipart body#10046

Merged
baywet merged 3 commits intomainfrom
copilot/fix-openapi-emitter-union-bytes
Mar 16, 2026
Merged

fix(openapi3): resolve "Duplicate type name" error for named union with bytes in multipart body#10046
baywet merged 3 commits intomainfrom
copilot/fix-openapi-emitter-union-bytes

Conversation

Copy link
Contributor

Copilot AI commented Mar 16, 2026

  • Analyze root cause of "Duplicate type name" error for multipart union with bytes
  • Fix addUsagesInOperation in visibility-usage.ts to traverse multipart body part types
  • Add test case for union with bytes in multipart body
  • Add changelog entry
  • Build and test changes (all 2482 tests pass)
  • Apply prettier formatting
Original prompt

This section details on the original issue you should resolve

<issue_title>OpenAPI emitter fails on union with bytes for multipart</issue_title>
<issue_description>The following definition

import "@typespec/http";
using Http;

union CreateVideoMultipartBodyInputReference {
  bytes,
  ImageRefParam,
}
union ImageRefParam {
  {
    @maxLength(20971520)
    image_url: url,
  },
  {
    file_id: string,
  },
}
model CreateVideoMultipartBody {

  input_reference?: HttpPart<CreateVideoMultipartBodyInputReference>;
}

op createVideo(
  @header
  contentType: "multipart/form-data",

  @multipartBody
  body: CreateVideoMultipartBody,
): void;

Fails with this error message : Duplicate type name: 'CreateVideoMultipartBodyInputReference'. Check @FriendlyName decorators and overlap with types in TypeSpec or service namespace.

Interestingly, if we replace bytes by string or something else, the emission starts working. I'd expect it to work with bytes as well.
</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

…n multipart body

Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:openapi3 Issues for @typespec/openapi3 emitter label Mar 16, 2026
Copilot AI changed the title [WIP] Fix OpenAPI emitter fails on union with bytes for multipart fix(openapi3): resolve "Duplicate type name" error for named union with bytes in multipart body Mar 16, 2026
Copilot AI requested a review from baywet March 16, 2026 19:42
@baywet baywet marked this pull request as ready for review March 16, 2026 19:55
@baywet baywet enabled auto-merge March 16, 2026 19:55
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 16, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/openapi3@10046

commit: 7019add

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@baywet
Copy link
Member

baywet commented Mar 16, 2026

@copilot run the formatting command, commit the changed files, do nothing else

Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 16, 2026

@copilot run the formatting command, commit the changed files, do nothing else

Done in 7019add.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • telemetry.astro.build
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/typespec/typespec/website/node_modules/.bin/../astro/astro.js build sh n-sc�� ebsite/src/conte--llmstxt sbuild/linux-x64--output-dir tools/pnpm/10.30../../website/src/content/docs/docs/emitters/openapi3/reference ental ture n/node sh tobu�� son cut t/node_modules/.bin/tspd --no-emit bash dist/node-gyp-bidoc sh (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from baywet March 16, 2026 20:58
@baywet baywet added this pull request to the merge queue Mar 16, 2026
Merged via the queue into main with commit fd31020 Mar 16, 2026
25 checks passed
@baywet baywet deleted the copilot/fix-openapi-emitter-union-bytes branch March 16, 2026 21:46
Copilot AI added a commit that referenced this pull request Mar 16, 2026
…th bytes in multipart body (#10046)

- [x] Analyze root cause of "Duplicate type name" error for multipart
union with bytes
- [x] Fix `addUsagesInOperation` in `visibility-usage.ts` to traverse
multipart body part types
- [x] Add test case for union with bytes in multipart body
- [x] Add changelog entry
- [x] Build and test changes (all 2482 tests pass)
- [x] Apply prettier formatting

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>OpenAPI emitter fails on union with bytes for
multipart</issue_title>
> <issue_description>The following definition
> 
> ```tsp
> import "@typespec/http";
> using Http;
> 
> union CreateVideoMultipartBodyInputReference {
>   bytes,
>   ImageRefParam,
> }
> union ImageRefParam {
>   {
>     @maxlength(20971520)
>     image_url: url,
>   },
>   {
>     file_id: string,
>   },
> }
> model CreateVideoMultipartBody {
> 
>   input_reference?: HttpPart<CreateVideoMultipartBodyInputReference>;
> }
> 
> op createVideo(
>   @Header
>   contentType: "multipart/form-data",
> 
>   @multipartBody
>   body: CreateVideoMultipartBody,
> ): void;
> ```
> 
> Fails with this error message : Duplicate type name:
'CreateVideoMultipartBodyInputReference'. Check @FriendlyName decorators
and overlap with types in TypeSpec or service namespace.
> 
> Interestingly, if we replace bytes by string or something else, the
emission starts working. I'd expect it to work with bytes as well.
> </issue_description>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> </comments>
> 


</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #10045

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 Send tasks to Copilot coding agent from
[Slack](https://gh.io/cca-slack-docs) and
[Teams](https://gh.io/cca-teams-docs) to turn conversations into code.
Copilot posts an update in your thread when it's finished.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:openapi3 Issues for @typespec/openapi3 emitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI emitter fails on union with bytes for multipart

4 participants