Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router: coercion of complex parameters from string sources #100

Closed
4 tasks done
bajtos opened this issue Mar 29, 2017 · 12 comments
Closed
4 tasks done

Router: coercion of complex parameters from string sources #100

bajtos opened this issue Mar 29, 2017 · 12 comments
Assignees
Labels
feature REST Issues related to @loopback/rest package and REST transport in general Validation

Comments

@bajtos
Copy link
Member

bajtos commented Mar 29, 2017

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'].

@bajtos
Copy link
Member Author

bajtos commented Apr 11, 2017

If we decide to use ajv for validations, then we should be able to leverage their type coercion - see https://github.com/epoberezkin/ajv#coercing-data-types

@bajtos bajtos changed the title Router: coercion of stringly-typed parameters Router: coercion of complex stringly-typed parameters Jul 13, 2017
@bajtos bajtos changed the title Router: coercion of complex stringly-typed parameters Router: coercion of complex parameters from string sources Jul 13, 2017
@dhmlau dhmlau added the Core-GA label Sep 6, 2017
@dhmlau
Copy link
Member

dhmlau commented Sep 6, 2017

Need that for REST enablement

@bajtos
Copy link
Member Author

bajtos commented Nov 2, 2017

I think this is a super-set of #394 (Filter in query of type object treated as string).

@bajtos
Copy link
Member Author

bajtos commented Nov 2, 2017

This is also related to our planned upgrade to OpenaAPI Spec v3, see #182

@bajtos bajtos added Validation and removed DP3 labels May 28, 2018
@bajtos bajtos added REST Issues related to @loopback/rest package and REST transport in general and removed epic.routing labels Jun 21, 2018
@virkt25
Copy link
Contributor

virkt25 commented Aug 9, 2018

Discussion:
From @raymondfeng -- For GA we must support coercion and validation of JSON Objects / Arrays.

@bajtos
Copy link
Member Author

bajtos commented Aug 13, 2018

Let's make this a P1 then.

@bajtos bajtos added the p1 label Aug 13, 2018
@bajtos
Copy link
Member Author

bajtos commented Aug 13, 2018

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).

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

@bajtos
Copy link
Member Author

bajtos commented Aug 13, 2018

This story needs a new estimate based on the updated description.

@dhmlau
Copy link
Member

dhmlau commented Aug 13, 2018

@virkt25 , do we have enough details for estimation this week?

@bajtos
Copy link
Member Author

bajtos commented Sep 25, 2018

Done 🎉

@bajtos bajtos closed this as completed Sep 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature REST Issues related to @loopback/rest package and REST transport in general Validation
Projects
None yet
Development

No branches or pull requests

9 participants