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)
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
-
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
-
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'].
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.
SwaggerOpenAPI specification to allow developers to specify a complex parameter type to be coerced from a stringstrong-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)
color[R]=100&color[G]=200&color[B]=150andcolor={"R":100,"G":200,"B":150}encodings (the latter is our own extension).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
Send a "filter" query as JSON-encoded value:
Sets
filterargument to{where: {name: 'Pen'}, limit: 10}.Alternative encoding:
Encode an array of strings as a comma-separated list (OUT OF SCOPE OF 4.0 GA)
Sets
tldsargument to['com', 'net', 'eu'].