Skip to content

fix: add relationship metadata (foreign keys and relation types) to OpenAPI schemas - #10456

Open
aaqilniz wants to merge 2 commits into
loopbackio:masterfrom
aaqilniz:fix/relation-info-in-specs
Open

aaqilniz wants to merge 2 commits into
loopbackio:masterfrom
aaqilniz:fix/relation-info-in-specs

Conversation

@aaqilniz

@aaqilniz aaqilniz commented Apr 5, 2024 •

Copy link
Copy Markdown
Contributor

This PR improves OpenAPI schema generation in @loopback/repository-json-schema and @loopback/openapi-v3 by adding x-foreign-keys and x-relation-type metadata to the x-relationships object.

Previously, parsing relationship metadata from OpenAPI specs was limited because standard outputs lacked information about specific relationship types (e.g., distinguishing between a standard hasMany and a hasManyThrough) and associated foreign keys.

Changes

  1. Vendor Extension Type (SpecificationExtension):

    • Introduced a local template-literal index signature ([key: x-${string}]: unknown) in @loopback/repository-json-schema/types.ts.
  2. Schema Building Refactor (build-schema.ts):

    • Populates x-foreign-keys and x-relation-type alongside existing relationship metadata during model schema generation.
    • Consolidated relationship iteration and cleanup logic to properly aggregate multiple relation entries without overwriting sibling definitions.
  3. OpenAPI Conversion Support (json-to-schema.ts):

    • Updated JSON-to-schema property conversion handlers to properly map and retain x-relationships vendor extensions.
  4. Testing:

    • Added and updated integration and unit tests covering hasMany, belongsTo, hasOne, and referencesMany relationship extensions.

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

👉 Check out how to submit a PR 👈

@coveralls

coveralls commented Apr 5, 2024 •

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 8657413748

Details

  • 56 of 72 (77.78%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.06%) to 55.432%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/repository-json-schema/src/build-schema.ts 49 65 75.38%
Files with Coverage Reduction New Missed Lines %
packages/openapi-v3/src/json-to-schema.ts 1 79.65%
Totals Coverage Status
Change from base Build 8646446166: 0.06%
Covered Lines: 9616
Relevant Lines: 12527

💛 - Coveralls

@aaqilniz
aaqilniz force-pushed the fix/relation-info-in-specs branch 2 times, most recently from 64e98e3 to 3c4c5b8 Compare April 12, 2024 05:25
@aaqilniz
aaqilniz marked this pull request as ready for review April 12, 2024 05:32
@aaqilniz
aaqilniz requested a review from mschnee as a code owner April 12, 2024 05:32
@aaqilniz aaqilniz changed the title fix: add information about foreign key fix: add information about foreign key and relation type Aug 16, 2024
@aaqilniz
aaqilniz force-pushed the fix/relation-info-in-specs branch from 4d13c0a to cbdd6c5 Compare August 17, 2024 03:37
@aaqilniz
aaqilniz marked this pull request as draft October 18, 2026 05:11
@aaqilniz
aaqilniz force-pushed the fix/relation-info-in-specs branch 2 times, most recently from 15e81df to 6ba0341 Compare October 30, 2026 15:53
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
@aaqilniz
aaqilniz force-pushed the fix/relation-info-in-specs branch from 6ba0341 to 9d182ad Compare October 30, 2026 16:14
@aaqilniz aaqilniz changed the title fix: add information about foreign key and relation type fix: add relationship metadata (foreign keys and relation types) to OpenAPI schemas Oct 30, 2026
@aaqilniz
aaqilniz marked this pull request as ready for review October 30, 2026 16:21
Signed-off-by: Muhammad Aaqil <aaqilcs102@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.

2 participants