@@ -61,6 +61,7 @@ import { extractParamsFromPath } from "./utils.js";
6161
6262export const namespace = "TypeSpec.Http" ;
6363
64+ /** {@inheritDoc HeaderDecorator } */
6465export const $header : HeaderDecorator = (
6566 context : DecoratorContext ,
6667 entity : ModelProperty ,
@@ -86,14 +87,23 @@ export const $header: HeaderDecorator = (
8687 context . program . stateMap ( HttpStateKeys . header ) . set ( entity , options ) ;
8788} ;
8889
90+ /**
91+ * Reads the header's wire name and explicitly configured serialization options.
92+ * Returns `undefined` at runtime for a type without `@header`.
93+ */
8994export function getHeaderFieldOptions ( program : Program , entity : Type ) : HeaderFieldOptions {
9095 return program . stateMap ( HttpStateKeys . header ) . get ( entity ) ;
9196}
9297
98+ /**
99+ * Reads the explicit or kebab-case default header name.
100+ * Returns `undefined` at runtime when the type is not marked `@header`.
101+ */
93102export function getHeaderFieldName ( program : Program , entity : Type ) : string {
94103 return getHeaderFieldOptions ( program , entity ) ?. name ;
95104}
96105
106+ /** Tests whether the type has been marked as an HTTP header with `@header`. */
97107export function isHeader ( program : Program , entity : Type ) {
98108 return program . stateMap ( HttpStateKeys . header ) . has ( entity ) ;
99109}
@@ -143,6 +153,7 @@ const [getQueryOptions, setQueryOptions] = useStateMap<
143153 ModelProperty ,
144154 QueryOptions & { name : string }
145155> ( HttpStateKeys . query ) ;
156+ /** {@inheritDoc QueryDecorator } */
146157export const $query : QueryDecorator = (
147158 context : DecoratorContext ,
148159 entity : ModelProperty ,
@@ -173,6 +184,10 @@ export function resolveQueryOptionsWithDefaults(
173184 } ;
174185}
175186
187+ /**
188+ * Reads `@query` options, resolving the wire name and defaulting `explode` to false.
189+ * Returns `undefined` when the type is not a query parameter.
190+ */
176191export function getQueryParamOptions (
177192 program : Program ,
178193 entity : Type ,
@@ -182,10 +197,12 @@ export function getQueryParamOptions(
182197 return { type : "query" , ...resolveQueryOptionsWithDefaults ( userOptions ) } ;
183198}
184199
200+ /** Reads the query wire name, or `undefined` when `@query` has not been applied. */
185201export function getQueryParamName ( program : Program , entity : Type ) : string | undefined {
186202 return getQueryParamOptions ( program , entity ) ?. name ;
187203}
188204
205+ /** Tests for explicit `@query` metadata; does not infer parameters from a URI template. */
189206export function isQueryParam ( program : Program , entity : Type ) {
190207 return program . stateMap ( HttpStateKeys . query ) . has ( entity ) ;
191208}
@@ -194,6 +211,7 @@ const [getPathOptions, setPathOptions] = useStateMap<ModelProperty, PathOptions
194211 HttpStateKeys . path ,
195212) ;
196213
214+ /** {@inheritDoc PathDecorator } */
197215export const $path : PathDecorator = (
198216 context : DecoratorContext ,
199217 entity : ModelProperty ,
@@ -228,6 +246,10 @@ export function resolvePathOptionsWithDefaults(
228246 } ;
229247}
230248
249+ /**
250+ * Reads `@path` options with defaults: simple style, no explode, and no reserved characters.
251+ * Returns `undefined` without `@path`; URI-template inference happens during operation resolution.
252+ */
231253export function getPathParamOptions (
232254 program : Program ,
233255 entity : Type ,
@@ -237,52 +259,63 @@ export function getPathParamOptions(
237259 return { type : "path" , ...resolvePathOptionsWithDefaults ( userOptions ) } ;
238260}
239261
262+ /** Reads the path wire name, or `undefined` when `@path` has not been applied. */
240263export function getPathParamName ( program : Program , entity : Type ) : string | undefined {
241264 return getPathOptions ( program , entity as any ) ?. name ;
242265}
243266
267+ /** Tests for explicit `@path` metadata; does not infer parameters from a URI template. */
244268export function isPathParam ( program : Program , entity : Type ) {
245269 return program . stateMap ( HttpStateKeys . path ) . has ( entity ) ;
246270}
247271
272+ /** {@inheritDoc BodyDecorator } */
248273export const $body : BodyDecorator = ( context : DecoratorContext , entity : ModelProperty ) => {
249274 context . program . stateSet ( HttpStateKeys . body ) . add ( entity ) ;
250275} ;
251276
277+ /** {@inheritDoc BodyRootDecorator } */
252278export const $bodyRoot : BodyRootDecorator = ( context : DecoratorContext , entity : ModelProperty ) => {
253279 context . program . stateSet ( HttpStateKeys . bodyRoot ) . add ( entity ) ;
254280} ;
255281
282+ /** {@inheritDoc BodyIgnoreDecorator } */
256283export const $bodyIgnore : BodyIgnoreDecorator = (
257284 context : DecoratorContext ,
258285 entity : ModelProperty ,
259286) => {
260287 context . program . stateSet ( HttpStateKeys . bodyIgnore ) . add ( entity ) ;
261288} ;
262289
290+ /** Tests whether the property's type was selected as the complete body by `@body`. */
263291export function isBody ( program : Program , entity : Type ) : boolean {
264292 return program . stateSet ( HttpStateKeys . body ) . has ( entity ) ;
265293}
266294
295+ /** Tests whether `@bodyRoot` selects this property for body and nested metadata resolution. */
267296export function isBodyRoot ( program : Program , entity : ModelProperty ) : boolean {
268297 return program . stateSet ( HttpStateKeys . bodyRoot ) . has ( entity ) ;
269298}
270299
300+ /** Tests whether `@bodyIgnore` excludes this property from the HTTP body. */
271301export function isBodyIgnore ( program : Program , entity : ModelProperty ) : boolean {
272302 return program . stateSet ( HttpStateKeys . bodyIgnore ) . has ( entity ) ;
273303}
274304
305+ /** {@inheritDoc MultipartBodyDecorator } */
275306export const $multipartBody : MultipartBodyDecorator = (
276307 context : DecoratorContext ,
277308 entity : ModelProperty ,
278309) => {
279310 context . program . stateSet ( HttpStateKeys . multipartBody ) . add ( entity ) ;
280311} ;
281312
313+ /** Tests whether `@multipartBody` selects this property as a multipart payload. */
282314export function isMultipartBodyProperty ( program : Program , entity : Type ) : boolean {
283315 return program . stateSet ( HttpStateKeys . multipartBody ) . has ( entity ) ;
284316}
285317
318+ /** {@inheritDoc StatusCodeDecorator } */
286319export const $statusCode : StatusCodeDecorator = (
287320 context : DecoratorContext ,
288321 entity : ModelProperty ,
@@ -297,21 +330,31 @@ export function setStatusCode(program: Program, entity: Model | ModelProperty, c
297330 program . stateMap ( HttpStateKeys . statusCode ) . set ( entity , codes ) ;
298331}
299332
333+ /** Tests whether `@statusCode` marks the property as response status metadata. */
300334export function isStatusCode ( program : Program , entity : Type ) {
301335 return program . stateSet ( HttpStateKeys . statusCode ) . has ( entity ) ;
302336}
303337
338+ /**
339+ * Extracts status codes or inclusive ranges from a property's type and constraints.
340+ * Returns validation diagnostics alongside any successfully extracted entries.
341+ */
304342export function getStatusCodesWithDiagnostics (
305343 program : Program ,
306344 type : ModelProperty ,
307345) : [ HttpStatusCodes , readonly Diagnostic [ ] ] {
308346 return getStatusCodesFromType ( program , type , type ) ;
309347}
310348
349+ /** Extracts status entries from a property, discarding validation diagnostics. */
311350export function getStatusCodes ( program : Program , entity : ModelProperty ) : HttpStatusCodes {
312351 return ignoreDiagnostics ( getStatusCodesWithDiagnostics ( program , entity ) ) ;
313352}
314353
354+ /**
355+ * Gets a built-in description for a status code or its HTTP status class.
356+ * Returns `undefined` for unrecognized values, including the `"*"` default response.
357+ */
315358// Reference: https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
316359export function getStatusCodeDescription ( statusCode : number | "*" | HttpStatusCodeRange | string ) {
317360 if ( typeof statusCode === "object" ) {
@@ -389,6 +432,10 @@ function validateVerbUniqueOnNode(context: DecoratorContext, type: Operation) {
389432 return true ;
390433}
391434
435+ /**
436+ * Reads the method assigned by an HTTP verb decorator, or `undefined` when none is set.
437+ * Does not perform the body-based method inference used by operation resolution.
438+ */
392439export function getOperationVerb ( program : Program , entity : Type ) : HttpVerb | undefined {
393440 return program . stateMap ( HttpStateKeys . verbs ) . get ( entity ) ;
394441}
@@ -399,10 +446,15 @@ function createVerbDecorator(verb: HttpVerb) {
399446 } ;
400447}
401448
449+ /** {@inheritDoc GetDecorator } */
402450export const $get : GetDecorator = createVerbDecorator ( "get" ) ;
451+ /** {@inheritDoc PutDecorator } */
403452export const $put : PutDecorator = createVerbDecorator ( "put" ) ;
453+ /** {@inheritDoc PostDecorator } */
404454export const $post : PostDecorator = createVerbDecorator ( "post" ) ;
455+ /** {@inheritDoc DeleteDecorator } */
405456export const $delete : DeleteDecorator = createVerbDecorator ( "delete" ) ;
457+ /** {@inheritDoc HeadDecorator } */
406458export const $head : HeadDecorator = createVerbDecorator ( "head" ) ;
407459
408460const _patch = createVerbDecorator ( "patch" ) ;
@@ -448,6 +500,7 @@ function isOriginalDecoratorApplication(context: DecoratorContext, entity: Opera
448500 return true ;
449501}
450502
503+ /** {@inheritDoc PatchDecorator } */
451504export const $patch : PatchDecorator = (
452505 context : DecoratorContext ,
453506 entity : Operation ,
@@ -484,9 +537,13 @@ export function getPatchOptions(program: Program, operation: Operation): PatchOp
484537
485538const VERB_DECORATORS = [ $get , $head , $post , $put , $patch , $delete ] ;
486539
540+ /** A server endpoint declared by `@server`, including its template parameter definitions. */
487541export interface HttpServer {
542+ /** Server URL template, with `{name}` placeholders for server parameters. */
488543 url : string ;
544+ /** Human-readable endpoint description, when supplied. */
489545 description ?: string ;
546+ /** Declared parameter properties keyed by their template names. */
490547 parameters : Map < string , ModelProperty > ;
491548}
492549
@@ -526,10 +583,18 @@ export const $server: ServerDecorator = (
526583 servers . push ( { url, description, parameters : parameterMap } ) ;
527584} ;
528585
586+ /**
587+ * Reads servers declared directly on a namespace, in decorator application order.
588+ * Returns `undefined` when none are declared; does not search parent namespaces.
589+ */
529590export function getServers ( program : Program , type : Namespace ) : HttpServer [ ] | undefined {
530591 return program . stateMap ( HttpStateKeys . servers ) . get ( type ) ;
531592}
532593
594+ /**
595+ * Applies `@useAuth`, interpreting unions as alternatives and tuples as combined schemes.
596+ * Reports invalid authentication definitions before recording any extracted requirements.
597+ */
533598export function $useAuth (
534599 context : DecoratorContext ,
535600 entity : Namespace | Interface | Operation ,
@@ -543,6 +608,10 @@ export function $useAuth(
543608 }
544609}
545610
611+ /**
612+ * Stores extracted authentication directly on the target, replacing any previous value.
613+ * Inheritance from containing interfaces or namespaces is resolved when querying an operation.
614+ */
546615export function setAuthentication (
547616 program : Program ,
548617 entity : Namespace | Interface | Operation ,
@@ -704,6 +773,10 @@ function extractOAuth2Auth(modelType: Model, data: any): HttpAuth {
704773 } ;
705774}
706775
776+ /**
777+ * Reads authentication stored directly on the target, or `undefined` when absent.
778+ * Use {@link getAuthenticationForOperation} to include containing-interface and namespace defaults.
779+ */
707780export function getAuthentication (
708781 program : Program ,
709782 entity : Namespace | Interface | Operation ,
0 commit comments