MCPcopy
hub / github.com/rapi-doc/RapiDoc / standardizeExample

Function standardizeExample

src/utils/schema-utils.js:162–184  ·  view source on GitHub ↗
(ex)

Source from the content-addressed store, hash-verified

160 */
161
162export function standardizeExample(ex) {
163 if (typeof ex === 'object' && !Array.isArray(ex)) {
164 if (ex.value !== undefined) {
165 // Case 1: Single object with 'value' property
166 return { Example: { ...ex } };
167 }
168 // Case 2: Object where each key is an object with a 'value' property
169 const filteredEntries = Object.entries(ex).filter(([_, obj]) => obj.value !== undefined); // eslint-disable-line
170 // If no valid entries found, return JSON.stringify of the input
171 if (filteredEntries.length === 0) {
172 return undefined;
173 }
174 return Object.fromEntries(filteredEntries);
175 } if (Array.isArray(ex)) {
176 // Case 3: Array of primitive values
177 return ex.reduce((acc, value, index) => {
178 acc[`Example${index + 1}`] = { value };
179 return acc;
180 }, {});
181 }
182 // Case 4: Single primitive value
183 return ex ? { Example: { value: ex } } : undefined;
184}
185
186/**
187 * Normalize example object in the following format (List of object which is used to render example links and fill the input boxes)

Callers 5

responseTemplateMethod · 0.90
requestBodyTemplateMethod · 0.90
jsonSchemaBodyTemplateFunction · 0.90

Calls 2

filterMethod · 0.45
reduceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…