microsoft / microsoft/typespec

[Bug]: Using HttpPart results in error in emitter-server-js

Open
#6,787 1 comment 0 reactions 1 assignee Claimed by @witemple-msft View on GitHub
bug emitter:service:js triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

### Describe the bug

```tsp
import "@typespec/http";

using Http;

@error
model Error {
code: T;
message: string;
details?: Record;
timestamp: utcDateTime;
}

/**
* Standard success response
*/
model Result {
code: T;
message: string;
details?: Record;
timestamp: utcDateTime;
}

model AttachmentError is Error<"invalid-attachment" | "empty-attachment">;
model AttachmentResult is Result<"added-attachment">;

interface x {
@route("{id}/addAttachment") @post addAttachment(@path id: string, @header contentType: "multipart/form-data",
@multipartBody body: {
recepientRequestId: HttpPart;
name: HttpPart;
type: HttpPart;
data: HttpPart;
},) : AttachmentError | AttachmentResult;
}
```

![Image](https://github.com/user-attachments/assets/88e23489-c091-45d0-b5ac-29f246e5a30a)

The above when using a HttpPart results in
```
Emitter "@typespec/http-server-js" crashed! This is a bug.
Please file an issue at https://github.com/microsoft/typespec/issues

Error: UNREACHABLE: HttpPart must have a Model argument
at emitWellKnownModel (file:///C:/r/prod/pserv/PServAgentService/node_modules/@typespec/http-server-js/dist/src/common/model.js:105:23)
at emitTypeReference (file:///C:/r/prod/pserv/PServAgentService/node_modules/@typespec/http-server-js/dist/src/common/reference.js:55:24)
at emitModel (file:///C:/r/prod/pserv/PServAgentService/node_modules/@typespec/http-server-js/dist/src/common/model.js:47:31)
at emitModel.next ()
at emitDeclaration (file:///C:/r/prod/pserv/PServAgentService/node_modules/@typespec/http-server-js/dist/src/common/declaration.js:21:20)
at emitDeclaration.next ()
at completePendingDeclarations (file:///C:/r/prod/pserv/PServAgentService/node_modules/@typespec/http-server-js/dist/src/ctx.js:111:28)
at emitRawServerOperation (file:///C:/r/prod/pserv/PServAgentService/node_modules/@typespec/http-server-js/dist/src/http/server/index.js:67:5)
at emitRawServerOperation.next ()
at emitRawServer (file:///C:/r/prod/pserv/PServAgentService/node_modules/@typespec/http-server-js/dist/src/http/server/index.js:44:16)

--------------------------------------------------
Library Version 0.58.0-alpha.11
TypeSpec Compiler Version 0.67.2
--------------------------------------------------
```
### Reproduction

Run the sample provided above in the description

### Checklist

- [x] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [x] Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- [x] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/Microsoft/typespec/discussions).
- [x] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.