Typescript: how to handle arrays or toMany relations
まだ誰も着手していません。
評価
- 難易度
- 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 の本文から書いたものです。
説明
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 はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
api-platform/create-client のほかの issue
-
[potential Security Alert] New `test-vue-app` script added in `@api-platform/client-generator@0.8.0` オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
api-platform/create-client#396 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
api-platform/create-client#397 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
api-platform/create-client#395 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
api-platform/create-client#394 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
api-platform/create-client#393 · コメント 1 件 ·
api-platform/create-client の issue をすべて見る
似ている issue
-
blocklist removal
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
MetaMask/eth-phishing-detect#296544 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
pastelsky/bundlephobia#1122 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
category/development priority/P2 scope/file-operations scope/testing type/enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100