How to use the @loopback/core.MetadataInspector.getAllParameterMetadata function in @loopback/core

To help you get started, we’ve selected a few @loopback/core 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 strongloop / loopback-next / packages / openapi-v3 / src / controller-spec.ts View on Github external
*   }
       * ```
       */
      operationSpec.parameters = params
        .filter(p => p != null)
        .map(p => {
          // Per OpenAPI spec, `required` must be `true` for path parameters
          if (p.in === 'path') {
            p.required = true;
          }
          return p;
        });
    }

    debug('  processing requestBody for method %s', op);
    let requestBodies = MetadataInspector.getAllParameterMetadata<
      RequestBodyObject
    >(OAI3Keys.REQUEST_BODY_KEY, constructor.prototype, op);

    if (requestBodies != null)
      requestBodies = requestBodies.filter(p => p != null);
    let requestBody: RequestBodyObject;

    if (requestBodies) {
      if (requestBodies.length > 1)
        throw new Error(
          'An operation should only have one parameter decorated by @requestBody',
        );

      requestBody = requestBodies[0];
      debug('  requestBody for method %s: %j', op, requestBody);
      if (requestBody) {
github strongloop / loopback-next / packages / openapi-v3 / src / controller-spec.ts View on Github external
debug('  spec responses for method %s: %o', op, operationSpec.responses);

    for (const code in operationSpec.responses) {
      const responseObject: ResponseObject | ReferenceObject =
        operationSpec.responses[code];
      if (isReferenceObject(responseObject)) continue;
      const content = responseObject.content ?? {};
      for (const c in content) {
        debug('  processing response code %s with content-type %', code, c);
        processSchemaExtensions(spec, content[c].schema);
      }
    }

    debug('  processing parameters for method %s', op);
    let params = MetadataInspector.getAllParameterMetadata(
      OAI3Keys.PARAMETERS_KEY,
      constructor.prototype,
      op,
    );

    debug('  parameters for method %s: %j', op, params);
    if (params != null) {
      params = DecoratorFactory.cloneDeep(params);
      /**
       * If a controller method uses dependency injection, the parameters
       * might be sparse. For example,
       * ```ts
       * class MyController {
       *   greet(
       *     @inject('prefix') prefix: string,
       *     @param.query.string('name) name: string) {