MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / extractRequestBody

Function extractRequestBody

packages/plugins/openapi/src/sdk/extract.ts:126–156  ·  view source on GitHub ↗
(
  operation: OperationObject,
  r: DocResolver,
)

Source from the content-addressed store, hash-verified

124};
125
126const extractRequestBody = (
127 operation: OperationObject,
128 r: DocResolver,
129): OperationRequestBody | undefined => {
130 if (!operation.requestBody) return undefined;
131
132 const body = r.resolve<RequestBodyObject>(operation.requestBody);
133 if (!body) return undefined;
134
135 const contents = declaredContents(body.content).map(({ mediaType, media }) =>
136 MediaBinding.make({
137 contentType: mediaType,
138 schema: Option.fromNullishOr(media.schema),
139 encoding: Option.fromNullishOr(
140 buildEncodingRecord((media as { encoding?: Record<string, unknown> }).encoding),
141 ),
142 }),
143 );
144 if (contents.length === 0) return undefined;
145
146 // Default = first declared (spec author's preferred order). Callers can
147 // override at invoke time with a `contentType` arg.
148 const defaultContent = contents[0]!;
149
150 return OperationRequestBody.make({
151 required: body.required === true,
152 contentType: defaultContent.contentType,
153 schema: defaultContent.schema,
154 contents: Option.some(contents),
155 });
156};
157
158// ---------------------------------------------------------------------------
159// Response schema extraction

Callers 3

extract.tsFile · 0.85
streamOperationBindingsFunction · 0.85

Calls 3

declaredContentsFunction · 0.90
buildEncodingRecordFunction · 0.85
resolveMethod · 0.80

Tested by

no test coverage detected