question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Full support for Structured Values / Value Objects / Embedded

See original GitHub issue

Proposal: Support for Value Objects

I would like to suggest that full support for objects, which does / might not have an ID and (when using Doctrine) might be saved in a json field of their parent object would be implemented. I am calling these “ValueObjects” bellow and as an example of such object I would suppose there exist a class named ‘SomeStructure’ which has been marked as ‘ValueObject’.

They could be denoted by a specific Annotation / Configuration, e.g.:

/**
 * @ValueObject()
 */
class SomeStructure
{
    public $someField;
}

By full support I understand:

  • they should require no ID in any context

  • they should require no IRI in any context

  • they should require no path to resource in any context

  • possibility to define a field on ApiResource, able to accept item (one) of ‘SomeStructure’, with phpDoc @var SomeStructure $someField

  • possibility to define a field on ApiResource, able to accept collection (array) of ‘SomeStructure’, with phpDoc @var SomeStructure[] $someField

  • correct automatic normalization and denormalization of these values (without need of writing custom normalizers / decorating normalizers and without normalizer complaining about missing iri or path…)

  • possibility to define validation directly on these ValueObjects (which might be triggered by using ‘Valid’ for item and ‘All(Valid)’ for collection on their parents)

  • possibility to define normalization and validation groups

  • automatic generation of proper swagger/openApi documentation for them with examples (so that examples of them are not shown as ‘[“string”]’ in Swagger UI)

  • possibility of nesting of ValueObjects, so that one ValueObject might have another ValueObject under its field (as well as collection of ValueObject of specific type)

  • possibility of combining ApiResources and ValueObjects, so that one ValueObject might have (reference to) ApiResource under its field (as well as collection of ApiResource of specific type). It would be nice to provide options to choose whether retrieve and embed the resource or just include iri / id.

  • they should allow clean and safe use without hacks. (Currently it is possible to define class as ApiResource and forbid all operations, but this approach is not stable (easy to fail))

Notes:

I am calling them here ‘ValueObject’ but the term (and implementation) might be different. They are referred to as ‘StructuredValue’ by @teohhanhui (in https://github.com/api-platform/core/issues/181#issuecomment-122871245 ) and @Arkowsky (in https://github.com/api-platform/api-platform/issues/1105 ) and under ‘ValueObject & no identifier’ by @ogizanagi (in https://github.com/api-platform/core/issues/227 )

References:

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:25
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
soyukacommented, Feb 18, 2020

Didn’t quite got the time to finish my work on that, I hope I can open a PR soon.

3reactions
teohhanhuicommented, Jul 19, 2019

Thanks for the summary. This is definitely much needed and will fix a lot of problems, including around documenting non-resource classes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueObject - Martin Fowler
Objects that are equal due to the value of their properties, in this case their x and y coordinates, are called value objects....
Read more >
Practical PHP Patterns: Embedded Value - DZone
The Embedded Value is an understated object-relational structure pattern which maps a collaborator object's state into the table of another ...
Read more >
Query (Feature Service/Layer)—ArcGIS REST APIs
The query operation returns either a feature set, an array of feature IDs, ... the structure of the JSON geometry objects returned by...
Read more >
Specification: Embedded metric format - Amazon CloudWatch
The CloudWatch embedded metric format is a JSON specification used to instruct CloudWatch Logs to automatically extract metric values embedded in structured ......
Read more >
Classify structured data with feature columns | TensorFlow Core
Key Point: using an embedding column is best when a categorical column has many possible values. We are using one here for demonstration...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found