Skip to content

Commit 1ba6b9f

Browse files
docs(http-server-js): Add JSDoc for server emitter APIs [skip chg] (#12250)
JavaScript server emitter consumers lack API guidance on how `$onEmit`, `$lib`, and emitter options fit together. Document their roles, option defaults, generated-output ownership, dry-run behavior, and service/error limitations without changing emission behavior. Preserves the existing deprecated testing-library guidance and leaves generated helpers untouched. Tracked in #12228.
1 parent 63e9bcd commit 1ba6b9f

2 files changed

Lines changed: 40 additions & 7 deletions

File tree

‎packages/http-server-js/src/index.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ import { emitHttp } from "./http/index.js";
1717

1818
export { $lib } from "./lib.js";
1919

20+
/**
21+
* TypeSpec emitter entry point that generates TypeScript server bindings for a single service.
22+
*
23+
* Replaces `src/generated` beneath the emitter output directory with server, model, and
24+
* serialization modules. In a compiler dry run, builds the module tree without deleting or
25+
* writing files. A program without a service produces a warning and no output; HTTP service
26+
* errors disable HTTP bindings but do not stop model emission.
27+
*
28+
* @param context - Compiler-provided program, emitter options, and output directory.
29+
* @throws If the program defines multiple services or encounters an unsupported emission
30+
* feature. File-writing and formatting failures also reject the returned promise.
31+
*/
2032
export async function $onEmit(context: EmitContext<JsEmitterOptions>) {
2133
const jsCtx = await createInitialContext(context.program, context.options);
2234

‎packages/http-server-js/src/lib.ts‎

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,41 @@
44
import type { JSONSchemaType } from "@typespec/compiler";
55
import { createTypeSpecLibrary, paramMessage } from "@typespec/compiler";
66

7+
/**
8+
* Configures the server bindings generated by the `$onEmit` entry point.
9+
*
10+
* Supply these options under `@typespec/http-server-js` in `tspconfig.yaml`.
11+
* The emitter option schema registered by {@link $lib} defaults all boolean options
12+
* to `false` and `datetime` to `"temporal-polyfill"`.
13+
*/
714
export interface JsEmitterOptions {
8-
/** If set to `true`, the emitter will generate a router that exposes an Express.js middleware function in addition to the ordinary Node.js HTTP server router.
9-
10-
If this option is not set to `true`, the `expressMiddleware` property will not be present on the generated router. */
15+
/**
16+
* Generates an Express.js middleware adapter in addition to the Node.js HTTP server router.
17+
* When disabled, the generated router has no `expressMiddleware` property.
18+
* @default false
19+
*/
1120
express?: boolean;
1221

13-
/** By default, the emitter will create interfaces that represent all models in the service namespace. If this option is set
14-
to `true`, the emitter will only emit those types that are reachable from an HTTP operation. */
22+
/**
23+
* Limits generated types to those reachable from HTTP operations. By default, types in
24+
* the service namespace and its nested namespaces are also included.
25+
* @default false
26+
*/
1527
"omit-unreachable-types": boolean;
16-
/** If set to `true`, the emitter will not format the generated code using Prettier. */
28+
/**
29+
* Skips Prettier formatting of generated source files.
30+
* @default false
31+
*/
1732
"no-format": boolean;
1833

1934
/**
20-
* The type of datetime models to use for TypeSpecs DateTime and Duration types.
35+
* Selects the JavaScript representation of TypeSpec date, time, and duration scalars.
2136
*
2237
* Options:
2338
* - `temporal-polyfill`: (Default) Uses the Temporal API from the `temporal-polyfill` package.
2439
* - `temporal`: Uses the native Temporal API, requires that your target environment supports it. This will become the default setting in the future.
2540
* - `date-duration`: Uses the built-in `Date` and a custom `Duration` type. Not recommended.
41+
* @default "temporal-polyfill"
2642
*/
2743
datetime?: "temporal-polyfill" | "temporal" | "date-duration";
2844
}
@@ -61,6 +77,11 @@ const EmitterOptionsSchema: JSONSchemaType<JsEmitterOptions> = {
6177
required: [],
6278
};
6379

80+
/**
81+
* TypeSpec library definition registering the server emitter's option schema, defaults,
82+
* diagnostics, and dry-run support. Re-exported from the package entry point for the
83+
* compiler to discover; `$onEmit` performs code generation.
84+
*/
6485
export const $lib = createTypeSpecLibrary({
6586
name: "@typespec/http-server-js",
6687
capabilities: {

0 commit comments

Comments
 (0)