loopbackio / loopbackio/loopback-next

getModelSchemaRef doesn't get all extended model's properties.

Aperta
#7,566 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug OpenAPI
Lingua principale
TypeScript
Stelle
5.1k
Fork
1.1k
Merge medio
2g 21h
PR unite (30g)
27

Descrizione

Steps to reproduce

I've got a controller with an endpoint which take a request body of the Foo model class.

@requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Foo),
        },
      },
    })

The model classes:

@model()
export class BarBase {
  @property()
  name: string
}

@model()
export class BarEdit extends BarBase {
  @property()
  id: number
  @property()
  delete: boolean
}

@model()
export class Foo {
  @property()
  id: number
  @property().array(BarEdit)
  bars: BarEdit[]
}

@model()
export class BarResult extends BarEdit {
  @property()
  result: string
}

Current Behaviour

When looking at the generated swagger document or calling the controller endpoint, the schema body is the following:

{
  id: number,
  bars: [
    {
      name: string
    }
  ]
}

The id and delete properties are missing.

Expected Behaviour

I expected that the controller model schema of Foo would be:

{
  id: number,
  bars: [
    {
      id: number,
      delete: boolean,
      name: string
    }
  ]
}

In the current behaviour the BarEdit model class seems to extends from the BarBase class and it has got the name property, but the id and delete property in the BarEdit model class itself disappeared. I expected the id and delete properties to be there as well, but it's not.

Also when the model class BarResult (which extends from BarEdit) is used in a controller's getModelSchemaRef it has got all the properties from all 3 model classes:

{
  id: number,
  delete: boolean,
  name: string,
  result: string
}

Additional information

A work around to this problem I've found is to create a copy of the BarBase model class and call it something for example BarBaseT and have BarEdit extends from that one instead.

Operating System Information

darwin x64 14.15.4
├── @loopback/boot@3.4.0
├── @loopback/core@2.16.0
├── @loopback/repository@3.6.0
├── @loopback/rest-explorer@3.3.0
├── @loopback/rest@9.3.0
├── @loopback/service-proxy@3.2.0
├── loopback-connector-kv-redis@3.0.3
├── loopback-connector-postgresql@5.3.0
├── loopback-connector-rest@3.7.0
npm notice 
npm notice New minor version of npm available! 7.6.1 -> 7.16.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v7.16.0
npm notice Run npm install -g npm@7.16.0 to update!
npm notice

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il problema con le definizioni dei modelli BarBase, BarEdit, BarResult e Foo e con l'uso di getModelSchemaRef nel controller mostrati nel report. Traccia lo schema generato per Foo e confrontalo con le proprietà ereditate previste; il lavoro è completato quando le proprietà id e delete di BarEdit compaiono nello schema annidato senza la soluzione alternativa.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
openapi, typescript
Ambito
api, backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.