Skip to content

Commit

Permalink
detect cookie parameters as metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
su8ru committed Oct 16, 2024
1 parent 1682f66 commit b9656c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion packages/http/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
isBody,
isBodyIgnore,
isBodyRoot,
isCookieParam,
isHeader,
isMultipartBodyProperty,
isPathParam,
Expand Down Expand Up @@ -219,11 +220,12 @@ export function resolveRequestVisibility(

/**
* Determines if a property is metadata. A property is defined to be
* metadata if it is marked `@header`, `@query`, `@path`, or `@statusCode`.
* metadata if it is marked `@header`, `@cookie`, `@query`, `@path`, or `@statusCode`.
*/
export function isMetadata(program: Program, property: ModelProperty) {
return (
isHeader(program, property) ||
isCookieParam(program, property) ||
isQueryParam(program, property) ||
isPathParam(program, property) ||
isStatusCode(program, property)
Expand Down
18 changes: 10 additions & 8 deletions packages/http/src/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "@typespec/compiler";
import { DuplicateTracker } from "@typespec/compiler/utils";
import { getContentTypes } from "./content-types.js";
import { isHeader, isPathParam, isQueryParam, isStatusCode } from "./decorators.js";
import { isCookieParam, isHeader, isPathParam, isQueryParam, isStatusCode } from "./decorators.js";
import {
GetHttpPropertyOptions,
HeaderProperty,
Expand Down Expand Up @@ -259,13 +259,15 @@ function validateBodyProperty(
modelProperty: (prop) => {
const kind = isHeader(program, prop)
? "header"
: (usedIn === "request" || usedIn === "multipart") && isQueryParam(program, prop)
? "query"
: usedIn === "request" && isPathParam(program, prop)
? "path"
: usedIn === "response" && isStatusCode(program, prop)
? "statusCode"
: undefined;
: usedIn === "request" && isCookieParam(program, prop)
? "cookie"
: (usedIn === "request" || usedIn === "multipart") && isQueryParam(program, prop)
? "query"
: usedIn === "request" && isPathParam(program, prop)
? "path"
: usedIn === "response" && isStatusCode(program, prop)
? "statusCode"
: undefined;

if (kind) {
diagnostics.add(
Expand Down

0 comments on commit b9656c3

Please sign in to comment.