Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Typescript: how to handle arrays or toMany relations

オープン
#129 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
30/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
typescript
領域
tooling

調査の方向性

TypeScript インターフェースジェネレーターの generate 関数から始め、resource.fields が reference、range、maxCardinality をどのように使用しているかを調べます。そのメタデータを、テスト配列と products の to-many リレーションの Swagger 表現と比較し、次に doc-parser がコレクション情報を提供しているか確認します。ジェネレーターがスカラー フィールド、配列、to-many リレーションを区別し、意図したインターフェースを生成できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

enhancement TypeScript

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!

主要言語
TypeScript
スター
376
フォーク
132
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

api-platform/create-client のほかの issue

api-platform/create-client の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。