sdk icon indicating copy to clipboard operation
sdk copied to clipboard

feat: Added an extensible API for stream schema sources

Open edgarrmondragon opened this issue 10 months ago • 6 comments

Summary by Sourcery

Introduce an extensible API for stream schema sources.

New Features:

  • Add LocalSchemaSource to load schemas from local files.
  • Add OpenAPISchemaSource to load schemas from OpenAPI specs.

Tests:

  • Add tests for LocalSchemaSource and OpenAPISchemaSource.

📚 Documentation preview 📚: https://meltano-sdk--2876.org.readthedocs.build/en/2876/

edgarrmondragon avatar Feb 07 '25 18:02 edgarrmondragon

Reviewer's Guide

This PR adds a pluggable schema source API by defining a BaseSchemaSource with Local and OpenAPI implementations, updates existing taps and tests to consume the new API, and includes necessary test fixtures.

Class diagram for the new extensible schema source API

classDiagram
    class BaseSchemaSource {
        - _registry: dict[str, dict]
        + __init__()
        + get_schema(*args, **kwargs) dict
        + __call__(*args, **kwargs) dict
    }
    class LocalSchemaSource {
        - path: Path | Traversable
        + __init__(path)
        + get_schema(name: str) dict
    }
    class OpenAPISchemaSource {
        - path: str | Path | Traversable
        + __init__(path)
        + spec_dict: dict (cached_property)
        + get_schema(ref: str) dict
    }
    BaseSchemaSource <|-- LocalSchemaSource
    BaseSchemaSource <|-- OpenAPISchemaSource

Class diagram for updated stream schema usage in sample_tap_gitlab

classDiagram
    class ProjectsStream {
        + schema: dict
    }
    class ReleasesStream {
        + schema: dict
    }
    class IssuesStream {
        + schema: dict
    }
    class CommitsStream {
        + schema: dict
    }
    class EpicsStream {
        + schema: dict
    }
    class EpicIssuesStream {
        + schema: dict
    }
    note for ProjectsStream "schema now set via LocalSchemaSource('projects')"
    note for ReleasesStream "schema now set via LocalSchemaSource('releases')"
    note for IssuesStream "schema now set via LocalSchemaSource('issues')"
    note for CommitsStream "schema now set via LocalSchemaSource('commits')"
    note for EpicsStream "schema now set via LocalSchemaSource('epics')"
    note for EpicIssuesStream "schema now set via LocalSchemaSource('epic_issues')"

File-Level Changes

Change Details Files
Introduce extensible schema source API
  • Add BaseSchemaSource abstraction with registry and call hook
  • Implement LocalSchemaSource loading JSON files lazily
  • Implement OpenAPISchemaSource fetching spec and resolving references
singer_sdk/schema.py
Update sample GitLab tap to use LocalSchemaSource
  • Import and instantiate LocalSchemaSource as LOCAL_SCHEMAS
  • Replace schema_filepath assignments with schema = LOCAL_SCHEMAS(...) calls
samples/sample_tap_gitlab/gitlab_rest_streams.py
Refactor tests to cover new schema sources
  • Remove legacy Schema.from_dict tests from core tests and add Local/OpenAPI source tests
  • Relocate simple_schema and schema_with_items tests to singerlib tests and update imports
tests/core/test_schema.py
tests/singerlib/test_schema.py
Add test fixtures for schemas
  • Provide an OpenAPI spec fixture (openapi.json)
  • Provide a local JSON schema fixture (user.json)
tests/fixtures/openapi.json
tests/fixtures/schemas/user.json

Possibly linked issues

  • #0: PR adds API and local/OpenAPI sources for issue's schema source feature request.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it. You can also reply to a review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Feb 07 '25 18:02 sourcery-ai[bot]

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 92.30%. Comparing base (bb957f0) to head (4692d5a). :warning: Report is 43 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2876   +/-   ##
=======================================
  Coverage   92.30%   92.30%           
=======================================
  Files          63       63           
  Lines        5343     5343           
  Branches      677      677           
=======================================
  Hits         4932     4932           
  Misses        290      290           
  Partials      121      121           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Feb 07 '25 18:02 codecov[bot]

CodSpeed Performance Report

Merging #2876 will not alter performance

Comparing 2746-feat-add-an-extensible-api-for-stream-schema-sources (4692d5a) with main (1495d93)

Summary

✅ 8 untouched benchmarks

codspeed-hq[bot] avatar Feb 07 '25 19:02 codspeed-hq[bot]

I agree with this, especially if it opens the door to graphql subscriptions

peterclemenko avatar Feb 23 '25 15:02 peterclemenko

I agree with this, especially if it opens the door to graphql subscriptions

Can you say more about that? How do you think this could make it easier to subscribe to live updates?

edgarrmondragon avatar Feb 23 '25 16:02 edgarrmondragon

I agree with this, especially if it opens the door to graphql subscriptions

Can you say more about that? How do you think this could make it easier to subscribe to live updates?

I might be misinterpreting the intention of this pull, nevermind.

peterclemenko avatar Feb 25 '25 13:02 peterclemenko

@sourcery-ai review

edgarrmondragon avatar Jul 01 '25 00:07 edgarrmondragon