neomerx / json-api

Framework agnostic JSON API (jsonapi.org) implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Media type matching with dynamic properties

lindyhopchris opened this issue · comments

Using the media type classes for content negotiation. Given this scenario:

POST /api/v1/users HTTP/1.1
Host: localhost:8000
Accept: application/vnd.api+json
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="user"; filename="user.xml"
Content-Type: text/xml
------WebKitFormBoundary7MA4YWxkTrZu0gW--

It's not possible to match the content type using MediaType::equalsTo() or MediaType::matches() because both use MediaType::isMediaParametersEqual()... for which there's no way to specify that you don't care what the boundary parameter value is... i.e. you cannot specify wildcard parameter values.

I'm not quite sure how to implement it, but do you think there's a way of allow wildcard parameter values when comparing the parameters?

OK, I'll try to find something about how to deal with it either in JSON API spec or a web spec.

Btw, I've just pre-released v3 of the library. Support JSON API 1.1, better-designed and performance testing shows improvement 2,3 - 5,4 X. Placed in develop.

@neomerx nice! I'm still stuck a little bit behind but hoping to catch up to your latest version sometime soon.

Added support for * in parameters to matchesTo method in v3. It's now possible

$type1 = new MediaType('multipart', 'form-data', ['boundary' => '*']);
$type2 = new MediaType('multipart', 'form-data', ['boundary' => '----WebKitFormBoundaryAAA']);

self::assertTrue($type2->matchesTo($type1));

Full test code here.

Great! Now I just need to upgrade to v3! Thanks for adding it in.

released as v3.0.0-rc.2

@lindyhopchris Don't hesitate to ask migration questions 😉

released as v3.0.0