persona-community-5/.pnpm-store/v3/files/1d/749bc6a4fa8f0143da619028a104ca34335c48b61583d44a77ab72f3b65ab85b1e8dd99783ac72c958195fc37185ad1f4f31f31ee9a67beaeb373e5aca6fbf
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

46 lines
1.7 KiB
Plaintext

import { escapePointer } from "@redocly/openapi-core/lib/ref-utils.js";
import ts from "typescript";
import { addJSDocComment, tsModifiers, tsPropertyIndex, UNKNOWN } from "../lib/ts.js";
import { getEntries } from "../lib/utils.js";
import type { HeaderObject, TransformNodeOptions } from "../types.js";
import transformMediaTypeObject from "./media-type-object.js";
import transformSchemaObject from "./schema-object.js";
/**
* Transform HeaderObject nodes (4.8.21)
* @see https://spec.openapis.org/oas/v3.1.0#header-object
*/
export default function transformHeaderObject(headerObject: HeaderObject, options: TransformNodeOptions): ts.TypeNode {
if (headerObject.schema) {
return transformSchemaObject(headerObject.schema, options);
}
if (headerObject.content) {
const type: ts.TypeElement[] = [];
for (const [contentType, mediaTypeObject] of getEntries(headerObject.content ?? {}, options.ctx)) {
const nextPath = `${options.path ?? "#"}/${escapePointer(contentType)}`;
const mediaType =
"$ref" in mediaTypeObject
? transformSchemaObject(mediaTypeObject, {
...options,
path: nextPath,
})
: transformMediaTypeObject(mediaTypeObject, {
...options,
path: nextPath,
});
const property = ts.factory.createPropertySignature(
/* modifiers */ tsModifiers({ readonly: options.ctx.immutable }),
/* name */ tsPropertyIndex(contentType),
/* questionToken */ undefined,
/* type */ mediaType,
);
addJSDocComment(mediaTypeObject, property);
type.push(property);
}
return ts.factory.createTypeLiteralNode(type);
}
return UNKNOWN;
}