Skip to content

feat(cli): set jsonSchema.maxLength when discovering string models - #11896

Open
officialasishkumar wants to merge 1 commit into
loopbackio:masterfrom
officialasishkumar:feat/discover-json-schema-max-length
Open

officialasishkumar wants to merge 1 commit into
loopbackio:masterfrom
officialasishkumar:feat/discover-json-schema-max-length

Conversation

@officialasishkumar

Copy link
Copy Markdown

Fixes #11869

lb4 discover only emitted the column length as the length property, which is not evaluated by request validation. Over-long values were therefore truncated silently (non-strict SQL mode) or caused an internal server error (strict mode).

Discovered string properties with a positive integer length now also get jsonSchema: {maxLength: <length>}; length is kept. An existing jsonSchema is preserved and non-string properties are untouched.

Checklist

  • DCO (Developer Certificate of Origin) signed in all commits
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

`lb4 discover` copied the column length into the `length` property only.
That property is metadata for the connectors and is not evaluated by
request validation, so over-long values were silently truncated by
databases in non-strict mode and surfaced as internal server errors in
strict mode.

Mirror the discovered length of `string` properties into
`jsonSchema.maxLength` (keeping `length` untouched) so that LoopBack
rejects such input with a validation error. An existing `jsonSchema`
(for example the enum values) is preserved. Non-string properties are
not affected.

Fixes loopbackio#11869

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant