Model discovery should populate `jsonSchema.maxLength` alongside `length` to support strict-mode validation

Ouverte
#11,869 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
68/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
node.js, typescript
Domaine
backend, database

Piste de recherche

Start by locating LoopBack's model discovery code and the tests for discovered string column metadata; the issue does not name specific files. Trace where the existing length property is populated and check how schema validation reads jsonSchema.maxLength. Update discovery so both values are represented, then verify tests cover overlong strings being rejected before database insertion.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

When discovering models from a database (e.g., MySQL), column length is represented by length property:

@property({
  type: 'string',
  length: 100,
})
name: string;

However, the validation layer does not evaluate the top-level length property. This causes issues depending on the database SQL mode:

Non-strict mode: Strings exceeding the limit are silently truncated by the database without any application-level error.

Strict mode: Instead of a clean validation error handled by LoopBack, the app will return an Internal Server Error.

Expected Behavior:

Model discovery should populate both the length property (for schema metadata) and set jsonSchema.maxLength for application-level validation (when the database is in strict mode). This allows LoopBack's schema validation to catch length violations and return proper validation errors before hitting a strict-mode database.

Proposed Solution:

Update model discovery to ensure that discovered string column lengths populate jsonSchema.maxLength while keeping the existing length property intact.

@property({
  type: 'string',
  jsonSchema: {
      maxLength: 100,
  },
  length: 100,
})
name: string;
Langage dominant
TypeScript
Étoiles
5.1k
Forks
1.1k
Merge moyen
1 j 19 h
PR mergées (30 j)
47

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de loopbackio/loopback-next

Toutes les issues de loopbackio/loopback-next

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.