Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added an extensible API for stream schema sources #2876

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

edgarrmondragon
Copy link
Collaborator

@edgarrmondragon edgarrmondragon commented Feb 7, 2025

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 edgarrmondragon linked an issue Feb 7, 2025 that may be closed by this pull request
Copy link
Contributor

sourcery-ai bot commented Feb 7, 2025

Reviewer's Guide by Sourcery

This PR introduces an extensible API for stream schema sources by adding support for loading JSON schemas from both local files and OpenAPI specifications. The changes are implemented by creating a new module that defines a base schema source along with two subclasses (LocalSchemaSource and OpenAPISchemaSource) that handle the respective schema loading logic. Additionally, tests and sample stream implementations have been updated to utilize the new API.

Class diagram for the new schema source API

classDiagram
    class BaseSchemaSource {
      - path
      - _registry : dict<string, dict>
      + __init__(path: str | Path | Traversable)
      + get_schema(...args): dict
      + __call__(...args): dict
    }

    class LocalSchemaSource {
      + get_schema(name: str): dict
    }

    class OpenAPISchemaSource {
      + get_schema(ref: str): dict
      + spec_dict : dict  <<cached property>>
    }

    BaseSchemaSource <|-- LocalSchemaSource
    BaseSchemaSource <|-- OpenAPISchemaSource
Loading

File-Level Changes

Change Details Files
Added a new schema sources module to provide extensible API support for JSON schemas.
  • Implemented BaseSchemaSource with a unified interface for schema retrieval.
  • Created LocalSchemaSource to load schemas from local files using a registry and JSON file reading.
  • Created OpenAPISchemaSource to load and resolve schemas from an OpenAPI specification, including a cached property for processing the full spec.
  • Handled different path types and added error handling for unsupported types.
singer_sdk/schema.py
Updated tests to validate new schema source functionalities.
  • Modified tests/core/test_schema.py to replace old schema tests with tests for LocalSchemaSource and OpenAPISchemaSource.
  • Ensured that the retrieved schemas contain expected keys and properties when loaded using the new API.
  • Adjusted assertions in tests for correct type instances and schema structure.
tests/core/test_schema.py
Revised sample tap implementation to incorporate the new schema API.
  • Refactored the sample_tap_gitlab/gitlab_rest_streams.py to replace direct file path references with the use of LocalSchemaSource for loading schemas.
  • Updated stream classes to invoke the new API for obtaining their schema definitions.
samples/sample_tap_gitlab/gitlab_rest_streams.py
Augmented tests in the singer library to work with the new schema source changes.
  • Added test_simple_schema and test_schema_with_items in tests/_singerlib/test_schema.py to verify schema integrity using Schema.from_dict.
  • Ensured these tests support the new extensible schema loading approach.
tests/_singerlib/test_schema.py

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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

@edgarrmondragon edgarrmondragon self-assigned this Feb 7, 2025
@edgarrmondragon edgarrmondragon added kind/Feature New feature or request Type/Tap Singer taps labels Feb 7, 2025
Copy link

codecov bot commented Feb 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.33%. Comparing base (61a0b88) to head (282ad28).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2876   +/-   ##
=======================================
  Coverage   91.33%   91.33%           
=======================================
  Files          62       62           
  Lines        5203     5203           
  Branches      675      675           
=======================================
  Hits         4752     4752           
  Misses        319      319           
  Partials      132      132           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented Feb 7, 2025

CodSpeed Performance Report

Merging #2876 will not alter performance

Comparing 2746-feat-add-an-extensible-api-for-stream-schema-sources (282ad28) with main (61a0b88)

Summary

✅ 7 untouched benchmarks

@edgarrmondragon edgarrmondragon force-pushed the 2746-feat-add-an-extensible-api-for-stream-schema-sources branch from f5efa08 to 99e2c00 Compare February 7, 2025 19:01
@edgarrmondragon edgarrmondragon force-pushed the 2746-feat-add-an-extensible-api-for-stream-schema-sources branch from 99e2c00 to 282ad28 Compare February 7, 2025 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/Feature New feature or request Type/Tap Singer taps
Projects
Status: To Discuss
Development

Successfully merging this pull request may close these issues.

feat: Add an extensible API for stream schema sources
1 participant