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

Function extractRequestBody

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

Source from the content-addressed store, hash-verified

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

Callers 3

extract.tsFile · 0.85
streamOperationBindingsFunction · 0.85

Calls 4

declaredContentsFunction · 0.90
multipartFileInputSchemaFunction · 0.85
buildEncodingRecordFunction · 0.85
resolveMethod · 0.80

Tested by

no test coverage detected