How to use the swagger-parser.bundle function in swagger-parser

To help you get started, we’ve selected a few swagger-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github teamdigitale / io-functions / api / generate_models.ts View on Github external
async function generateApi(
  e: nunjucks.Environment,
  specFileName: string,
  root: string
): Promise<void> {
  const api: Spec = await SwaggerParser.bundle(`api/${specFileName}.yaml`);

  const specCode = `
    /* tslint:disable:object-literal-sort-keys */
    /* tslint:disable:no-duplicate-string */

    // DO NOT EDIT
    // auto-generated by generated_model.ts from ${specFileName}.yaml

    export const specs = ${JSON.stringify(api)};
  `;
  await fs.writeFile(
    `${root}/${specFileName}.ts`,
    prettier.format(specCode, {
      parser: "typescript"
    })
  );
github BlueOakJS / blueoak-server / services / swagger.js View on Github external
async.eachSeries(files, function parseSwagger(file, swagCallback) {
        var handlerName = path.basename(file); //use the swagger filename as our handler module id
        handlerName = handlerName.substring(0, handlerName.lastIndexOf('.')); //strip extensions

        var derefPromise = parser.validate(file);
        parser.bundle(file)
            .then(function (bundledApi) {
                specs.bundled[handlerName] = bundledApi;
                return derefPromise;
            })
            .then(function (dereferencedApi) {
                specs.dereferenced[handlerName] = dereferencedApi;
                if (polymorphicValidation !== 'off') {
                    preparePathsForPolymorphicValidation(dereferencedApi.paths, responseModelValidationLevel);
                }
                prepareDefinitionsForPolymorphicValidation(dereferencedApi.definitions);
                specs.names.push(handlerName);
                return swagCallback();
            })
            .catch(function (error) {
                // don't generate an error if it was a non-Swagger Spec JSON file
                var swagErr = error;
github EricHenry / swagger-data-gen / src / sdg.js View on Github external
run(config = {}) {
    let configFormatters = (config.formatters ? config.formatters : DEFAULT_RUN_CONFIG.formatters);
    let configMiddleware = (config.middleware ? config.middleware : DEFAULT_RUN_CONFIG.middleware);

    // apply any registered formatters
    this._formatters = configure(this._formatters, configFormatters);
    this._formatters.forEach(({ formatName, callback }) => jsf.format(formatName, callback));

    return SwaggerParser.bundle(this._pathToFile)
      .then(api => {
        this._middleware = configure(this._middleware, configMiddleware);

        let modifiedApi = Object.assign({}, api);
        this._middleware.forEach(func => modifiedApi = func(modifiedApi));
        return modifiedApi;
      })
      .then(api => SwaggerParser.dereference(api))
      .then(api => this._parsedFile = api)
      .catch((err) => { throw new Error(`Error has occured when trying to bundle and dereference the OpenAPI / Swagger object. \n Error: ${err}`); });
  }
github EricHenry / swagger-data-gen / src / SwaggerDataGen.ts View on Github external
export function build(swaggerSchema: string | Swagger, config: BuildOptions = {}): Promise<Swagger> {
  const { formatters, middleware } = config;
  const configurationF = (formatters ? formatters : DEFAULT_CONFIG_FORMATTER);
  const configurationM = (middleware ? middleware : DEFAULT_CONFIG_MIDDLEWARE);

  // create a registered array of formatters based on the configuration
  const _formatters = configure(CORE_FORMATTERS, configurationF);

  // apply any registered formatters
  _formatters.forEach(({ formatName, callback }) => jsf.format(formatName, callback));

  return SwaggerParser.bundle(swaggerSchema)
    .then((api: Swagger) => {
      // create a registered array of middleware based on the configuration
      const _middleware = configure(CORE_MIDDLEWARE, configurationM);
      let modifiedApi = Object.assign({}, api);

      //apply any registered middleware
      _middleware.forEach(m => modifiedApi = m(modifiedApi));
      return modifiedApi;
    })
    .then((api: Swagger) => SwaggerParser.dereference(api))
    .catch((err: Error) => {
      throw new Error(`Error has occured when trying to bundle and dereference the OpenAPI / Swagger object. \n Error: ${err}`);
    });
}
github anttiviljami / openapi-client-axios / src / typegen / typegen.ts View on Github external
export async function generateTypesForDocument(definition: Document | string) {
  const api = new OpenAPIClientAxios({ definition });
  await api.init();

  const processor = new WriteProcessor({ indentSize: 2, indentChar: ' ' });
  const resolver = new ReferenceResolver();
  const convertor = new SchemaConvertor(processor);

  const rootSchema = await SwaggerParser.bundle(definition);
  resolver.registerSchema(parseSchema(rootSchema));

  const generator = new DtsGenerator(resolver, convertor);
  const schemaTypes = await generator.generate();
  const exportedTypes = convertor.getExports();
  const operationTypings = generateOperationMethodTypings(api, exportedTypes);

  const imports = [
    'import {',
    '  OpenAPIClient,',
    '  Parameters,',
    '  UnknownParamsObject,',
    '  OperationResponse,',
    '  AxiosRequestConfig,',
    `} from 'openapi-client-axios';`,
  ].join('\n');
github zalando-incubator / hexo-theme-doc / lib / nodejs / swagger / swagger.js View on Github external
_bundle (schema){
    return SwaggerParser.bundle(schema, this.options);
  }
github Sujimoshi / swagger-definer / src / swagger.ts View on Github external
validate(): Promise<Spec> {
    return bundle(this.toJSON())
  }