Skip to content

resolves Azure/data-api-builder#2462 - #3860

Open
terdskadoosh wants to merge 2 commits into
Azure:mainfrom
terdskadoosh:fix-issue-2462
Open

terdskadoosh wants to merge 2 commits into
Azure:mainfrom
terdskadoosh:fix-issue-2462

Conversation

@terdskadoosh

Copy link
Copy Markdown

Why make this change?

  • Resolves [Enh]: OpenAPI does not show multiple data sources #2462 — When a runtime configuration contains entities mapped to multiple data sources, the OpenAPI/Swagger generation previously only used metadata from the default data source. As a result, entities backed by non-default data sources were omitted from the generated OpenAPI document and Swagger UI only showed types from the first configuration.
  • This change ensures the OpenAPI document includes schemas and paths for entities from all configured data sources, preventing incomplete API documentation for multi-datasource setups.
  • Related discussion: [Enh]: OpenAPI does not show multiple data sources #2462

What is this change?

  • Summary

    • Resolve each entity's metadata provider from the entity-to-data-source mapping in the runtime configuration instead of assuming the default data source contains every entity.
    • Iterate runtimeConfig.Entities (the configured entities) when building OpenAPI paths and component schemas, and for each entity resolve the correct ISqlMetadataProvider via the metadata provider factory.
    • Skip entities gracefully when an entity is not present in its resolved metadata provider, and log a helpful warning/error.
    • Reuse tags from the global tags dictionary to avoid duplicate groups in Swagger UI.
    • Update BuildPaths and CreateComponentSchemas to accept RuntimeConfig instead of relying on the default data source name, and add a helper to resolve the proper metadata provider for each entity.
  • Files changed (key)

    • src/Core/Services/OpenAPI/OpenApiDocumentor.cs
      • Added GetEntityMetadataProvider(RuntimeConfig runtimeConfig, string entityName)
      • BuildPaths and CreateComponentSchemas now accept RuntimeConfig and use per-entity metadata resolution
      • Added logging for entities that cannot be resolved in their configured data source
    • src/Service.Tests/UnitTests/OpenApiDocumentorUnitTests.cs
      • Added CreateDocument_UsesEntitySpecificDataSourceMetadataForSchemas
      • Added test helpers to mock per-datasource metadata providers for Book and Review entities
  • Behavior change

    • OpenAPI schemas and paths will now include entities mapped to non-default data sources when those entities exist in their configured data source metadata.
    • Entities missing from their resolved metadata provider are excluded with a log message instead of silently producing incorrect docs.

How was this tested?

  • Integration Tests
  • Unit Tests

Unit test added:

  • CreateDocument_UsesEntitySpecificDataSourceMetadataForSchemas (OpenApiDocumentorUnitTests)
    • Sets up a RuntimeConfig with two data sources and two entities mapped to different data sources (Book -> books-ds, Review -> reviews-ds).
    • Mocks per-datasource ISqlMetadataProvider instances with distinct schema shapes.
    • Calls documentor.CreateDocument() and asserts the generated OpenAPI JSON contains:
      • components.schemas.Book with expected properties (e.g., title)
      • components.schemas.Review with expected properties (e.g., review_id, content)

Notes:

  • No integration tests included in this PR; recommend running the full test suite or an end-to-end test against a multi-datasource runtime config for additional verification.

Sample Request(s)

Example: Verify OpenAPI JSON contains schemas for entities that belong to different datasources.

  1. Start Data API Builder with a runtime config where:

    • Book -> data source books-ds
    • Review -> data source reviews-ds
  2. Fetch the OpenAPI JSON:

    • curl -sS -H "Accept: application/json" http://localhost:<port>/openapi.json

Expected (excerpt):

{
  "components": {
    "schemas": {
      "Book": { /* schema with properties such as "title" */ },
      "Review": { /* schema with properties such as "review_id", "content" */ }
    }
  }
}

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@terdskadoosh

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Non-strict mode generates unresolved schema references, and the new test loses its data-source mappings during setup.

2 open findings
What changed in this PR

Addresses #2462 by generating DAB OpenAPI documentation using each entity’s configured data source rather than only the default source.

Changes:

  • Resolve entity-specific metadata for schemas and paths.
  • Skip missing metadata with diagnostic logging.
  • Add a two-data-source schema test.
File Description
src/​Service.Tests/​UnitTests/​OpenApiDocumentorUnitTests.cs Adds multi-data-source schema coverage and metadata helpers.
src/​Core/​Services/​OpenAPI/​OpenApiDocumentor.cs Uses per-entity metadata when generating schemas and paths.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Core/Services/OpenAPI/OpenApiDocumentor.cs Outdated
Comment on lines +279 to +280
RuntimeConfigProvider configProvider = TestHelper.GenerateInMemoryRuntimeConfigProvider(config);
RuntimeConfig loadedConfig = configProvider.GetConfig();
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@terdskadoosh

Copy link
Copy Markdown
Author

For some reason the original commit is from my work profile and not my personal.

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.

[Enh]: OpenAPI does not show multiple data sources

3 participants