Skip to content

Complex OpenAPI Validations with @property #1624

@virkt25

Description

@virkt25

Description / Steps to reproduce / Feature proposal

LoopBack's @requestBody decorator is supposed to be capable of validation complex OpenAPI Schemas such as:

{
  type: string,
  minLength: 10,
  format: 'email'
}

This only works when this schema is passed to the spec via the @model decorator (top-down approach) ... vs. the more common route / CLI recommended path of using the @property decorator.

If you add validation properties such as minLength, format, etc. to a property using the @property decorator the validation properties don't even show up in /openapi.json and as such are never validated against the requestBody since those validations aren't a part of the schema.

Current Behavior

  • Can't add validation properties using the @property decorator.

Expected Behavior

  • Should be able to add model validation properties to a property via the @property decorator.

Acceptance Criteria

  • @property() decorator should accept additional validation properties as per the OpenAPI Spec and add them to the schema of the Model (should show in /openapi.json) - see Refactor metaToJsonProperty to accept AJV keywords #2685
  • Incoming @requestBody() should honour validation properties added via @property decorator.
  • Confirm @model() also works in preserving the validation properties
  • Update any relevant docs (if needed)
  • Tests

See Reporting Issues for more tips on writing good issues

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions