How to use openapi-schemas - 3 common examples

To help you get started, we’ve selected a few openapi-schemas 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 APIDevTools / swagger-parser / lib / validators / schema.js View on Github external
function initializeZSchema () {
  // HACK: Delete the OpenAPI schema IDs because ZSchema can't resolve them
  delete openapi.v2.id;
  delete openapi.v3.id;

  // The OpenAPI 3.0 schema uses "uri-reference" formats.
  // Assume that any non-whitespace string is valid.
  ZSchema.registerFormat("uri-reference", (value) => value.trim().length > 0);

  // Configure ZSchema
  return new ZSchema({
    breakOnFirstError: true,
    noExtraKeywords: true,
    ignoreUnknownFormats: false,
    reportPathAsArray: true
  });
}
github APIDevTools / swagger-parser / lib / validators / schema.js View on Github external
function validateSchema (api) {
  // Choose the appropriate schema (Swagger or OpenAPI)
  let schema = api.swagger ? openapi.v2 : openapi.v3;

  // Validate against the schema
  let isValid = zSchema.validate(api, schema);

  if (!isValid) {
    let err = zSchema.getLastError();
    let message = "Swagger schema validation failed. \n" + formatZSchemaError(err.details);
    throw ono.syntax(err, { details: err.details }, message);
  }
}
github APIDevTools / swagger-parser / lib / validators / schema.js View on Github external
function initializeZSchema () {
  // HACK: Delete the OpenAPI schema IDs because ZSchema can't resolve them
  delete openapi.v2.id;
  delete openapi.v3.id;

  // The OpenAPI 3.0 schema uses "uri-reference" formats.
  // Assume that any non-whitespace string is valid.
  ZSchema.registerFormat("uri-reference", (value) => value.trim().length > 0);

  // Configure ZSchema
  return new ZSchema({
    breakOnFirstError: true,
    noExtraKeywords: true,
    ignoreUnknownFormats: false,
    reportPathAsArray: true
  });
}

openapi-schemas

JSON Schemas for every version of the OpenAPI Specification

MIT
Latest version published 4 years ago

Package Health Score

47 / 100
Full package analysis