Skip to content

Router: coercion of complex parameters from string sources #100

@bajtos

Description

@bajtos

In loopback/strong-remoting 3.x, we allow remote methods to accept parameters of complex types and have the runtime to convert string inputs (e.g. in a query string or formdata) to such complex type.

  • consider whether we want to implement this feature in loopback-next too
  • figure how to extend SwaggerOpenAPI specification to allow developers to specify a complex parameter type to be coerced from a string
  • implement the proposal

strong-remoting 3.x has pretty extensive test suite that we can reuse here - see strong-remoting:test/rest-coercion/

Acceptance criteria (Scope for 4.0 GA)

  • Support "type: object" only
  • Leverage OpenAPI spec parameter "style: deepObject"
  • For deepObject parameters, support both color[R]=100&color[G]=200&color[B]=150 and color={"R":100,"G":200,"B":150} encodings (the latter is our own extension).
  • Test + Docs

Everything else (other styles than deepObject, array values, etc.) is out of scope of GA.

The spec: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#parameterObject

Examples

  1. Send a "filter" query as JSON-encoded value:

    GET /api/products?filter={"where":{"name":"Pen"},"limit":10}
    

    Sets filter argument to {where: {name: 'Pen'}, limit: 10}.

    Alternative encoding:

    GET /api/products?filter[where][name]=Pen&filter[limit]=10
    
  2. Encode an array of strings as a comma-separated list (OUT OF SCOPE OF 4.0 GA)

    GET /api/domains?tlds=com,net,eu
    

    Sets tlds argument to ['com', 'net', 'eu'].

Metadata

Metadata

Assignees

Labels

RESTIssues related to @loopback/rest package and REST transport in generalValidationfeature

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions