Skip to content

[hsjs/http-specs] Unspeakable status code property causes problems for HSJS #6884

Closed
@witemple-msft

Description

@witemple-msft

In http-specs/specs/response/status-code-range we use _ to denote the status code of responses. This is a problem for HSJS because a property named _ is treated as "unspeakable" because it contains no text segments, only characters that it considers "separators." We produce the following error by design:

node_modules/@typespec/http-specs/specs/response/status-code-range/main.tsp:74:3 - error @typespec/http-server-js/unspeakable-status-code: Status code property '_' is unspeakable and does not have an exact value. Provide an exact status code value or rename the property.
> 74 |   _: int32;
     |   ^

These are status code ranges:

  @minValue(400)
  @maxValue(499)
  @statusCode
  _: int32;

HSJS relies on the presence of the status code property, because otherwise it does not know what status code to return, and if it's unspeakable, we drop it from the representation of the model, creating a conflict. I chose to remove these _ properties from models because I thought it was a bad experience for a user to have to return something like { _: 200, data } for a successful response, when the only options are { data } or an error.

We have some options:

  1. Put a name on this status code property (code) and live with the HSJS limitation that operative properties like status code have to be named.
  2. Don't drop "unspeakable" properties in HSJS, but this has consequences for developers who will have to specify these "pure metadata" properties that have strange names.
  3. Only drop "unspeakable" properties if they are literal-valued, which would a breakage point if someone changes a status code property from @statusCode _: 400 to @minValue(400) @maxvalue(499) _: int32.
  4. Change the HSJS business logic strategy fundamentally so that metadata is extracted into a separate strongly-typed object from the body data, and require the developer to return both the metadata object and the body data object separately in a wrapped data structure.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions