Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function main() {
const openApiText = await readFile('openapi.yml', 'utf-8');
const apiData = prepareApiData(
(await resolveRefs(yaml.safeLoad(openApiText))).resolved
);
await mkdir('./dist').catch(() => {});
await writeFile(
'./dist/index.d.ts',
`///
///
import {CancelToken} from 'axios';
${Object.keys(apiData)
.map(o => printApiTypes(o, apiData[o]))
.join('\n\n')}
${printTypes()}
export interface Bridges {
/** Speak a sentence to the bridge */
speakSentence(id: string, sentence: string, options?: SpeakSentenceOptions, cancelToken?: CancelToken): Promise;
async function main() {
const openApiText = await readFile('openapi.yml', 'utf-8');
const openapi = (await resolveRefs(yaml.safeLoad(openApiText))).resolved;
const apiData = prepareApiData(openapi);
await writeFile(
'./lib/api-data.js',
`// Generated automatically. Don't edit this file.
import * as Joi from 'joi';
export default {
name: '${pack.name}',
version: '${pack.version || openapi.info.version}',
objects: {
${Object.keys(apiData)
.map(o => printApiObject(o, apiData[o]))
.join(',\n')}
}
};`,
'utf-8'
includeInvalid: true,
loaderOptions: {
processContent: function (res, callback) {
callback(undefined, YAML.safeLoad(res.text));
}
}
};
if (!cacheEntry.resolved) {
// For Swagger 1.2, we have to create real JSON References
if (swaggerVersion === '1.2') {
jsonRefsOptions.refPreProcessor = swagger1RefPreProcesor;
}
// Resolve references
JsonRefs.resolveRefs(apiDOrSO, jsonRefsOptions)
.then(function (results) {
removeCirculars(results.resolved);
// Fix circular references
_.each(results.refs, function (refDetails, refPtr) {
if (refDetails.circular) {
_.set(results.resolved, JsonRefs.pathFromPtr(refPtr), {});
}
});
cacheEntry.referencesMetadata = results.refs;
cacheEntry.resolved = results.resolved;
cacheEntry.resolvedId = SparkMD5.hash(JSON.stringify(results.resolved));
callback();
})
.then(function (remoteResults) {
// Resolve local references (Remote references should had already been resolved)
cOptions.jsonRefs.filter = 'local';
return JsonRefs.resolveRefs(remoteResults.resolved || cOptions.definition, cOptions.jsonRefs)
.then(function (results) {
_.each(remoteResults.refs, function (refDetails, refPtr) {
results.refs[refPtr] = refDetails;
});
return {
// The original OpenAPI definition
definition: _.isString(cOptions.definition) ? remoteResults.value : cOptions.definition,
// The original OpenAPI definition with its remote references resolved
definitionRemotesResolved: remoteResults.resolved,
// The original OpenAPI definition with all its references resolved
definitionFullyResolved: results.resolved,
// Merge the local reference details with the remote reference details
refs: results.refs
}
});
private render(): void {
if (!this.connected || this._store === undefined) {
return;
}
if (this.editor === undefined || this.editor === null) {
this.editor = document.createElement('json-forms') as JsonFormsElement;
this.appendChild(this.editor);
}
JsonRefs.resolveRefs(getSchema(this._store.getState()))
.then(
resolvedSchema => {
this.editor.setInnerComponent(
TreeRenderer,
{
uischema: getUiSchema(this._store.getState()),
schema: resolvedSchema.resolved,
filterPredicate: this._filterPredicate,
labelProvider: this._labelProvider,
imageProvider: this._imageProvider
});
this.editor.store = this._store;
const exportButton = document.getElementById('export-data-button') as HTMLButtonElement;
if (exportButton !== null) {
const exportDialog = createExportDataDialog();
const blueprintDefinitions = exports.getBlueprintDefinitions(model)
const blueprintHandlers = exports.getBlueprintHandlers(model)
_.forEach(actions, (pathAndMethod, action) => {
if (model.blueprint[action]) {
if (!_.has(pathDefs, pathAndMethod)) {
_.set(pathDefs, pathAndMethod, blueprintDefinitions[action])
}
if (!_.has(pathDefs, pathAndMethod.concat('__handler__'))) {
_.set(pathDefs, pathAndMethod.concat('__handler__'), blueprintHandlers[action])
}
}
})
}
})
const definitionResolved = (await resolve(definition)).resolved
return new Swagger(definitionResolved)
}
getSpec () {
let promise
if (typeof SWAGGER_RENDERER.spec === 'string') {
promise = fetch(SWAGGER_RENDERER.spec, {credentials: 'include'})
.then((response) => response.json())
.then((spec) => resolve(spec))
} else {
promise = resolve(SWAGGER_RENDERER.spec)
}
promise
.then((result) => result.resolved)
.then((spec) => {
_.forEach(spec.paths, (operations, path) => {
_.forEach(operations, (operation, method) => {
operation.path = path
operation.method = method
})
})
return spec
})
.then((spec) => {
debug('spec', spec)
Dispatcher.dispatch({
function getSchemaAsJSON() {
if (resolvedSwaggerSpec) {
return Promise.resolve(resolvedSwaggerSpec);
}
const content = getSchema();
const options = {
includeInvalid: true,
loaderOptions: {
processContent(processedContent, callback) {
callback(null, YAML.safeLoad(processedContent.text));
},
},
};
return jsonRefs.resolveRefs(content, options).then(results => {
resolvedSwaggerSpec = results.resolved;
return resolvedSwaggerSpec;
});
}
registerResource(
name: string,
resource: Object,
resolveReferences = false
): Object {
const oldResource = this.resourceMap[name];
if (resolveReferences) {
const resourcePromise = JsonRefs.resolveRefs(resource, {
includeInvalid: true
});
resourcePromise.then(result => {
this.resourceMap[name] = result.resolved;
});
} else {
this.resourceMap[name] = resource;
}
return oldResource;
}