MCPcopy Index your code
hub / github.com/massCodeIO/massCode / sampleFromSchema

Function sampleFromSchema

src/main/http/import/openapi.ts:270–299  ·  view source on GitHub ↗
(schema: unknown)

Source from the content-addressed store, hash-verified

268}
269
270function sampleFromSchema(schema: unknown): unknown {
271 if (!isRecord(schema))
272 return ''
273 if (schema.example !== undefined)
274 return schema.example
275 if (schema.default !== undefined)
276 return schema.default
277 if (Array.isArray(schema.enum) && schema.enum.length > 0)
278 return schema.enum[0]
279
280 if (schema.type === 'object' || isRecord(schema.properties)) {
281 const result: Record<string, unknown> = {}
282 if (isRecord(schema.properties)) {
283 for (const [key, property] of Object.entries(schema.properties)) {
284 result[key] = sampleFromSchema(property)
285 }
286 }
287 return result
288 }
289
290 if (schema.type === 'array') {
291 return [sampleFromSchema(schema.items)]
292 }
293
294 if (schema.type === 'integer' || schema.type === 'number')
295 return 0
296 if (schema.type === 'boolean')
297 return false
298 return ''
299}
300
301function parseRequestBody(
302 rawBody: unknown,

Callers 1

parseRequestBodyFunction · 0.85

Calls 1

isRecordFunction · 0.70

Tested by

no test coverage detected