feat: Added an extensible API for stream schema sources
Summary by Sourcery
Introduce an extensible API for stream schema sources.
New Features:
- Add
LocalSchemaSourceto load schemas from local files. - Add
OpenAPISchemaSourceto load schemas from OpenAPI specs.
Tests:
- Add tests for
LocalSchemaSourceandOpenAPISchemaSource.
📚 Documentation preview 📚: https://meltano-sdk--2876.org.readthedocs.build/en/2876/
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 |
|
singer_sdk/schema.py |
| Update sample GitLab tap to use LocalSchemaSource |
|
samples/sample_tap_gitlab/gitlab_rest_streams.py |
| Refactor tests to cover new schema sources |
|
tests/core/test_schema.pytests/singerlib/test_schema.py |
| Add test fixtures for schemas |
|
tests/fixtures/openapi.jsontests/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 reviewon 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 issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon 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 dismisson 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 reviewto 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.
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.
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
I agree with this, especially if it opens the door to graphql subscriptions
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 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.
@sourcery-ai review