1

I faced the problem with generating React components with api-platform-generate-crud.
Model has property that is object email. I have serializer that make my email object a string. API endpoint is serving string.

It works for GET & POST.
When I try to generate React components error message is

    TypeError: Cannot read property '0' of undefined

Looking deeper into it, looks like that generator still see my email as object not a string.

Any idea how I can force API to 'see' email property as string not object ?

2
  • Can you post your entity definition and the custom normalizer you use if any? Commented May 15, 2017 at 11:33
  • 1. Partial entity 2. Normalizer Commented May 15, 2017 at 11:35

1 Answer 1

2

The data model you define is authoritative. Types in the Hydra documentation reflect the ones in PHP classes. Here, the email property is of type object. If you set the related data as a string somewhere, you don't respect this contract anymore. The Hydra documentation is not in sync with the returned data.

You can change the type of the email property in the Hydra documentation by decorating the api_platform.hydra.normalizer.documentation service.

But I would recommend to keep the PHP classes' structure of your entities as close as possible of the structure exposed through the API. Your classes should reflect the output of the API. You can use custom data providers to deal with more complex data structure (ex: ORM entities) before hydrating the structure to expose.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.