loopbackio / loopbackio/loopback-next
@property.array ignores json schema definition
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 5.1k
- Forks
- 1.1k
- Ø Merge
- 2 T. 21 Std.
- Gemergte PRs (30 T.)
- 27
Beschreibung
### Describe the bug
I was attempting to use the property array decorator alongside the jsonschema definition to ensure at least one item existed in the array at request time via validation within `@requestBody`
However when using the `@property.array` decorator it seems to just drop all the `jsonSchema` fields and ignore them
I've made a repro here.
https://codesandbox.io/p/sandbox/infallible-scott-64xtwg?welcome=true
Run this request
```
curl -X 'POST' \
'https://64xtwg-3000.csb.app/ping' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"subModel": [
{
"childProperty": [
]
}
]
}'
```
This line here https://github.com/loopbackio/loopback-next/blob/master/packages/repository-json-schema/src/build-schema.ts#L269C46-L269C46 seems to be the culprit. If i change that to `result = Object.assign({}, meta.jsonSchema, { type: 'array', items: propDef })` it appears to work as expected (throw a 422 error)
### Logs
_No response_
### Additional information
_No response_
### Reproduction
https://codesandbox.io/p/sandbox/infallible-scott-64xtwg?welcome=true
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie bei packages/repository-json-schema/src/build-schema.ts ungefähr bei Zeile 269 und reproduzieren Sie das Verhalten mit der verknüpften CodeSandbox oder der curl-Anfrage. Prüfen Sie, wie @property.array seine Array-Metadaten mit der jsonSchema-Definition kombiniert; abgeschlossen ist die Aufgabe, wenn das Schema die Definition beibehält und die Anfrage mit leerem childProperty einen 422-Validierungsfehler erzeugt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- api
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 48/100