MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / cloneSpecObject

Function cloneSpecObject

packages/cli/generators/openapi/utils.js:196–217  ·  view source on GitHub ↗

* Clone an OpenAPI spec. When a `$ref` is encountered, we store it as `x-$ref` * and keep the stringified original value as `x-$original-value`. These * metadata allows us to access the original object after `$ref` is resolved * and dereferenced by the parser. * * @param {*} spec An OpenAPI spe

(spec)

Source from the content-addressed store, hash-verified

194 * @param {*} spec An OpenAPI spec object
195 */
196function cloneSpecObject(spec) {
197 return _.cloneDeepWith(spec, item => {
198 /**
199 * A yaml object below produces `null` for `servers.url`
200 * ```yaml
201 * servers:
202 * - url:
203 * description: null url for testing
204 * ```
205 */
206 if (item != null && item.$ref) {
207 const copy = _.cloneDeep(item);
208 return {
209 ...copy,
210 // Store the original item in `x-$original`
211 'x-$original-value': json5.stringify(item, null, 2),
212 // Keep `$ref` as `x-$ref` as `$ref` will be removed during dereferencing
213 'x-$ref': item.$ref,
214 };
215 }
216 });
217}
218
219/**
220 * Print an OpenAPI spec object as JavaScript object literal. The original value

Callers 1

loadSpecFunction · 0.85

Calls 1

cloneDeepMethod · 0.80

Tested by

no test coverage detected