Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function moveDefinition(spec: any, newSchemaKey: string, path: string): any {
// copy the definition to components.schemas root
const defSchema = dot.get(spec, path);
dot.set(spec, `components.schemas.${newSchemaKey}`, defSchema);
// delete the definition at current path
dot.delete(spec, path);
const newRef = `#/components/schemas/${newSchemaKey}`;
return updateRefs(spec, `#/${path.split('.').join('/')}`, newRef);
}
// current schema was the last reference in the other schema referencing it, then remove also that schema
dot.delete(spec as any, referencedByPath);
} else {
// or, update the referencing schema removing the current schema:
// remove the entry from the referencedBy array in occurrences table
_.remove(referencedBy[referencedByKey].referencedBy, v => v === referencedByPath);
// update occurrence to save in occurrences table
const updatedOccurrence = {
count: referencedBy[referencedByKey].count - 1,
referencedBy: referencedBy[referencedByKey].referencedBy
};
dot.set(occurrences['schemas'] as any, referencedByKey, updatedOccurrence);
}
}
// finally, delete the current schema with count === 0
dot.delete(spec as any, pathToDelete);
}
return spec;
}
function rebaseOASDefinition(fullSpec: any, schemaKey: string, schema: any, path: string, definitionsPath: string[]): any {
if (schema.definitions) {
for (const defKey in schema.definitions) {
// current recursive definition path chain
const chain = [...definitionsPath, defKey];
const newPath = `${path}.definitions.${defKey}`;
const definition = dot.get(fullSpec, newPath);
fullSpec = rebaseOASDefinition(fullSpec, defKey, definition, newPath, chain);
const newSchemaName = `${chain.join('_')}`;
// move to components/schemas and get a new ref related to the new path
fullSpec = moveDefinition(fullSpec, newSchemaName, newPath);
}
dot.delete(fullSpec, `${path}.definitions`);
}
return fullSpec;
}
return obj => {
for (const searchPath of pathsToSearch) {
if (dotProp.has(obj.config, searchPath)) {
const fromVal = dotProp.get(obj.config, searchPath);
const toVal = toValue ? toValue(fromVal) : fromVal;
log.warn("project", deprecationMessage(obj, target, searchPath, fromVal, toVal));
dotProp.set(obj.config, target, toVal);
dotProp.delete(obj.config, searchPath);
}
}
return obj;
};
}
delete(key) {
const data = this.data
DotProp.delete(data, key)
this.data = data
}
clear() {
function deleteUnreferencedParameters(occurrences: any, spec: OpenAPIV3.Document): OpenAPIV3.Document {
const toDelete = Object.keys(_.pickBy(occurrences['parameters'], value => value.count === 0));
for (const paramName of toDelete) {
dot.delete(spec as any, `components.parameters.${paramName}`);
}
return spec;
}
arrify(key).forEach(key => {
dotProp.delete(this.fields, key);
});
}
delete(key) {
const config = this.all;
dotProp.delete(config, key);
this.all = config;
}
remove(key) {
const config = this.getConfig()
dotProp.delete(config, key)
fs.writeJsonSync(this.configFile, config, {spaces: 4})
}
}
State.prototype.del = function (key) {
dotProp.delete(this.__ImmutableState__, key)
this.listeners(this.get())
}