Typescript: how to handle arrays or toMany relations
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 30/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- typescript
- Área
- tooling
Línea de trabajo
Empieza en la función generate del generador de interfaces de TypeScript e inspecciona cómo resource.fields utiliza reference, range y maxCardinality. Compara esos metadatos con la representación de Swagger del array de prueba y de la relación to-many de products, y comprueba después si doc-parser proporciona información sobre colecciones. Se considera terminado cuando el generador pueda distinguir entre campos escalares, arrays y relaciones to-many, y producir las interfaces previstas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hey,
while I was working on an Angular generator I noticed that the current implementation of the typescript interface generator does not take into account toMany relations (or simple arrays as well).
I had a look at the fields property inside resource, however I can't seem to find any difference between single fields and array fields. I hoped that the maxCardinality property would help me, but it seems properly populated only for reference types.
Here is an example of what I mean:
Resource definition
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"producerRead","userRead"})
*/
private $name;
/**
* @ApiSubresource()
* @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="producer", orphanRemoval=true)
* @Groups({"producerRead","userRead"})
*/
private $products;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Picture", cascade={"persist", "remove"})
* @Groups({"producerRead","producerWrite"})
*/
private $mainPicture;
/**
* @var array
* @Groups({"producerRead","producerWrite"})
*/
public $test;
Dump of resource.fields (part of id) inside the generate function
Field {
name: 'products',
id: 'http://localhost:8080/api/docs.jsonld#Producer/products',
range: 'http://localhost:8080/api/docs.jsonld#Product',
reference: [Resource],
required: false,
description: '',
maxCardinality: null,
deprecated: false },
Field {
name: 'name',
id: 'http://localhost:8080/api/docs.jsonld#Producer/name',
range: 'http://www.w3.org/2001/XMLSchema#string',
reference: null,
required: false,
description: '',
maxCardinality: null,
deprecated: false },
Field {
name: 'mainPicture',
id: 'http://localhost:8080/api/docs.jsonld#Producer/mainPicture',
range: 'http://localhost:8080/api/docs.jsonld#Picture',
reference: [Resource],
required: false,
description: '',
maxCardinality: 1,
deprecated: false },
Field {
name: 'test',
id: 'http://localhost:8080/api/docs.jsonld#Producer/test',
range: null,
reference: null,
required: false,
description: '',
maxCardinality: null,
deprecated: false },
In the swagger docs the property test is correctly picked up as a string array, however I can't seem to replicate the same thing for the typescript interfaces.
If we look at maxCardinality, it seems it is correct (if we assume null means 'collection') for reference fields (mainPicture is a OnetoOne and products is a ToMany), however this is not the case for name (string) and test (string array).
I'm asking here because there might be another field that helps me find out if I'm dealing with a collection or not and I'm missing it, but this issue might be related to doc-parser as well.
I'll gladly create a PR for the typescript generator if we find out how to fix this. Thanks!
- Lenguaje dominante
- TypeScript
- Estrellas
- 376
- Forks
- 132
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de api-platform/create-client
-
[potential Security Alert] New `test-vue-app` script added in `@api-platform/client-generator@0.8.0` Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
api-platform/create-client#396 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 38/100
api-platform/create-client#397 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
api-platform/create-client#395 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
api-platform/create-client#394 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
api-platform/create-client#393 · 1 comentario ·
Todos los issues de api-platform/create-client
Issues similares
-
VerificationGate: ATTRIBUTION quote guard never matches a normal quotation (\b around the quote) Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
danielmiessler/LifeOS#2234 ·
-
T: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
-
Mend: dependency security vulnerability untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100