How to use the express-openapi-validate/dist/schema-utils.resolveReference function in express-openapi-validate

To help you get started, we’ve selected a few express-openapi-validate 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 hevans90 / oa3-api-defender / src / request-parser.ts View on Github external
Object.keys(requestSchema.properties).forEach(prop => {
            const ref = resolveReference(
              document,
              (requestSchema as any).properties[prop],
            );
            const ex = this.generateExampleValue(ref);
            reqBody[prop] = ex ? ex : undefined;
          });
          debug(`Generated Body: ${JSON.stringify(reqBody, null, 2)}`);
github hevans90 / oa3-api-defender / src / request-parser.ts View on Github external
path: string,
    opConfig: OperationConfig,
    document: OpenApiDocument,
  ): Object {
    const reqBody = {};

    if (opConfig.config.requestBody) {
      debug(
        `Attempting to generate requestBody for: ${opConfig.operation.toUpperCase()} ${path}...`,
      );

      let requestSchema: SchemaObject | ReferenceObject | undefined =
        opConfig.config.requestBody.content['application/json'].schema;

      if (requestSchema) {
        requestSchema = resolveReference(document, requestSchema);

        if (requestSchema.properties) {
          Object.keys(requestSchema.properties).forEach(prop => {
            const ref = resolveReference(
              document,
              (requestSchema as any).properties[prop],
            );
            const ex = this.generateExampleValue(ref);
            reqBody[prop] = ex ? ex : undefined;
          });
          debug(`Generated Body: ${JSON.stringify(reqBody, null, 2)}`);
        }
      }
    }

    return reqBody;

express-openapi-validate

Express middleware to validate request based on an OpenAPI 3 document

Apache-2.0
Latest version published 4 years ago

Package Health Score

50 / 100
Full package analysis