[Bug]: http-server-js: kebab case model properties not emitted as valid JS code in JSON serializer
Describe the bug
When using kebab case properties, like
model CommonHeaders {
@header `content-length`: uint64;
}
emitToJson fails to produce the toJsonObject method with valid JavaScript -- prettier fails here:
https://github.com/microsoft/typespec/blob/main/packages/http-server-js/src/write.ts#L82
This is because emitToJson emits properties as is here
https://github.com/microsoft/typespec/blob/main/packages/http-server-js/src/common/serialization/json.ts#L188
May suggest wrapping the properties in "
Reproduction
import "@typespec/http";
using TypeSpec.Http;
model Widget {
id: int32;
`parent-id`: int32; // <--
name: string;
}
model WidgetResponse {
...Http.OkResponse;
...Http.Body<Widget>;
}
@service(#{ title: "Widgets", version: "1" })
@server("https://widgets.com", "foo")
@route("/widgets/")
namespace Foo {
@get
op getWidget(@path id: int32): WidgetResponse;
}
Checklist
- [x] Follow our Code of Conduct
- [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.
- [x] The provided reproduction is a minimal reproducible example of the bug.
Actually, there is probably a second bug here -- entries marked as @header shouldn't be included in the serialization here, right?
@tjb1982 I'm going to put up a PR that addresses the naming issue alone and close this issue. The problem with metadata like headers nested within the body depends on an extensive rework that's tracked in https://github.com/microsoft/typespec/issues/6934. Basically the current implementation treats all data sources in the request/response separately (headers, query, body, etc.) and when they're mixed together the serializer just fails at handling all that correctly, so I think I need to refactor the handling logic there to parse/serialize everything in a single pass rather than try to do it piecemeal like I'm doing now.