Comments (8)
Can you please post some code to illustrate how to get the error? I do not quite get how you succeed with crashing it 😄 Thanks
from json-api.
I've modified the existing testIntegrationWithEncodingParameters. The crashed will be caused if the result of get Includes isn't "escaped" by iterableToArray.
Attention the assert in the withIncludedPaths prevents it with tests. It only throws when the assert is removed.:
public function testCombination()
{
$profileUrl1 = 'http://example1.com/foo';
$profileUrl2 = 'http://example2.com/boo';
$queryParameters = [
BaseQueryParser::PARAM_FIELDS => [
'comments' => Comment::LINK_AUTHOR.', '.Comment::ATTRIBUTE_BODY.' ',
'people' => Author::ATTRIBUTE_FIRST_NAME,
],
BaseQueryParser::PARAM_SORT => '-created,title,+updated',
BaseQueryParser::PARAM_INCLUDE => Comment::LINK_AUTHOR.', '.
Comment::LINK_AUTHOR.'.'.Author::LINK_COMMENTS,
BaseQueryParser::PARAM_PROFILE => urlencode(implode(' ', [$profileUrl1, $profileUrl2])),
];
$parser = new BaseQueryParser($queryParameters);
//
// Now the main purpose of the test. Will it work with EncodingParameters?
//
// firstly setup some data
$author = Author::instance(9, 'Dan', 'Gebhardt');
$comments = [
Comment::instance(5, 'First!', $author),
Comment::instance(12, 'I like XML better', $author),
];
$author->{Author::LINK_COMMENTS} = $comments;
// and encode with params taken from the parser
$actual = Encoder::instance(
[
Author::class => AuthorSchema::class,
Comment::class => CommentSchema::class,
]
)
->withIncludedPaths($parser->getIncludes())
->encodeData($comments);
}
from json-api.
Thanks. I'll have a look this weekend.
from json-api.
I am in doubt. The parser actually parses inputs paths and returns them 'parsed'. However, withIncludedPaths
expects a list of dot-separated paths. And each of them is right and some sort of adapter is needed. Technically, the solution is simple and instead of
->withIncludedPaths($parser->getIncludes())
it is required to
->withIncludedPaths($this->iterableKeys($parser->getIncludes()))
where
private function iterableKeys(iterable $iterable): iterable {
foreach ($iterable as $key => $value) {
yield $key;
}
}
What are you thoughts on this?
from json-api.
Thanks for your response. Now I'm confused. I don't understand why you put iterableToArray() as parameter in the test, but above you explain it should be iterableKeys?
Also isn't it the sence of a parser to prepare the parameter for later usage in the fetching and rendering of the output? Where do someone need additional data of the getInclude method?
In general it would be helpful to have more documentation. PhpDoc and wiki entries.
Is it ok for you, if I write some PhpDoc?
How to help you with the wiki? It couldn't be cloned
from json-api.
Sorry for confusion
I needed paths like post.comments.author
to be split into ['post', 'comments', 'author']
so I could build database/ORM quires and load those relationships. Thus, the parser
seemed to be a perfect candidate to do such parsing and have the parsed result as an array/Generator. However, I bumped the same problem as you, the Encoder
wanted paths dot-separated because it needed to know which paths to follow and in what order (1 post
, 2 post.comments
and 3 post.comments.author
in this case). So I decided to return both forms.
return [
'post.comments.author' => ['post', 'comments', 'author'],
];
Though in a form of a Generator
. Sorry, for being a bit complicated.
That is why taking keys works in this case. Technically, they are the same values as in the parser input though they are validated and guaranteed to have expected format, no trailing spaces and etc.
AFAIK, the Wiki can be edited by any logged-in Github user. Git repo is also available https://github.com/neomerx/json-api.wiki.git If you have any issues with the edit please post changes here and I will move them.
from json-api.
Thanks. I think it would be better to move the compatibility note to https://github.com/neomerx/json-api/wiki/Parsing-API-Parameters#query-parameters and rather than referring to 'tests' and provide a usage sample.
from json-api.
Released in 4.0.1
from json-api.
Related Issues (20)
- Include related resource into output in its entirety? HOT 11
- Include array of `Identifier`s HOT 5
- What's happened to include relationships in schema `getRelationships` method HOT 40
- Relationship data is parsed even if parser is not parsing the data HOT 13
- EncoderPropertiesTrait::withIncludePaths only works with arrays HOT 1
- subUrl property is private - BaseSchema HOT 6
- [Question] How to exclude relationships on collections by default? HOT 9
- Catch exceptions from json_encode HOT 7
- Fetch a link from an existing Element HOT 2
- How to encode custom array NOT LARAVEL MODEL INSTANCE HOT 4
- How to create nested relationships HOT 3
- sparse fields filter relationships HOT 3
- Member names are converted to kebab-case HOT 1
- stricter typing with psalm
- Relationship data generator is invoked more than once if data is empty HOT 16
- Support interface/superclass based mapping in SchemaContainer HOT 1
- How can I fix incorrect links in my `included` compound document section? HOT 1
- Problem with PHP version 8.1
- accept same type on Encoder::instance
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-api.