Skip to content

ERA-12678: Add v2 dynamic schema endpoints to sync and async clients#37

Open
JoshuaVulcan wants to merge 4 commits intomainfrom
ERA-12678/v2-dynamic-schema
Open

ERA-12678: Add v2 dynamic schema endpoints to sync and async clients#37
JoshuaVulcan wants to merge 4 commits intomainfrom
ERA-12678/v2-dynamic-schema

Conversation

@JoshuaVulcan
Copy link
Contributor

@JoshuaVulcan JoshuaVulcan commented Feb 11, 2026

Summary

  • Adds a generic get_schema(resource_name) method and 6 convenience methods (get_users_schema, get_sources_schema, get_subjects_schema, get_choices_schema, get_spatial_features_schema, get_event_types_schema) to both ERClient (sync) and AsyncERClient (async)
  • Adds service_root_v2 property to both clients, deriving the v2.0 API root from the configured v1.0 service_root
  • Updates AsyncERClient._call to support absolute URLs (matching sync client behavior), enabling v2 endpoint calls

Test plan

  • 9 async tests covering generic schema retrieval, all 6 individual schemas, plus 404 and 403 error handling
  • 10 sync tests covering service_root_v2 derivation, generic schema retrieval, all 6 individual schemas, plus 404 and 403 error handling
  • Full test suite passes (109 tests)
  • Feature parity verified between sync and async clients

Resolves ERA-12678

ERA-12678: Adds support for retrieving JSON schemas from the v2.0 API:

Both ERClient (sync) and AsyncERClient (async):
- get_schema(resource_name): generic schema retrieval
- get_users_schema(): users schema
- get_sources_schema(): sources schema
- get_subjects_schema(): subjects schema
- get_choices_schema(): choices schema
- get_spatial_features_schema(): spatial features schema
- get_event_types_schema(): event types schema
- service_root_v2 property: derives v2.0 URL from v1.0 service_root

Also updates AsyncERClient._call to support absolute URLs, matching
the sync client behavior.

Includes 19 tests covering success, not-found, and forbidden scenarios
for both sync and async clients.

Co-authored-by: Cursor <cursoragent@cursor.com>
@JoshuaVulcan JoshuaVulcan added autoreviewing PR is currently being auto-reviewed and removed autoreviewing PR is currently being auto-reviewed labels Feb 11, 2026
…l pattern

Replace the brittle `service_root_v2` property (which uses str.replace
on '/api/v1.0') with the cleaner `_api_root(version)` + `base_url`
parameter pattern from PR #23. This adds `_api_root()`, updates
`_er_url()` to accept a `base_url` param, and threads `base_url`
through `_get`, `_post`, `_patch`, and `_call` on both sync and async
clients.

Updates get_schema() and all convenience schema methods to use
`base_url=self._api_root('v2.0')` instead of constructing full URLs
from `service_root_v2`.

Also updates tests to use `_api_root('v2.0')` instead of manual
string replace on service_root.

Co-authored-by: Cursor <cursoragent@cursor.com>
@JoshuaVulcan
Copy link
Contributor Author

V2 URL Convention Alignment

Replaced the service_root_v2 property (string replace on /api/v1.0) with the _api_root(version) + base_url parameter pattern established in PR #23.

Changes:

  • Removed service_root_v2 property from both ERClient and AsyncERClient
  • Added _api_root(version) method to both clients
  • Updated _er_url() to accept an optional base_url parameter
  • Threaded base_url through _get, _post, _patch, and _call on both sync and async clients
  • Updated get_schema() to use base_url=self._api_root('v2.0') with a relative path instead of constructing full URLs from service_root_v2
  • Updated tests to use er_client._api_root('v2.0') instead of er_client.service_root.replace('/api/v1.0', '/api/v2.0')
  • Reverted the path.startswith('http') guard in async _call() in favor of the base_url approach

This PR is now compatible with PR #23's infrastructure and will merge cleanly once #23 lands.

Co-authored-by: Cursor <cursoragent@cursor.com>
@JoshuaVulcan JoshuaVulcan requested a review from a team as a code owner February 12, 2026 01:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class client helpers to retrieve JSON Schema documents from the EarthRanger v2.0 API and introduces sync/async test coverage to validate URL construction and error handling.

Changes:

  • Add get_schema() plus convenience methods (get_users_schema(), get_sources_schema(), etc.) to both ERClient and AsyncERClient.
  • Add new sync and async test modules covering success, 404, and 403 cases for the new schema endpoints.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
erclient/client.py Introduces sync/async v2 schema retrieval methods that call _get(..., base_url=_api_root('v2.0')).
tests/sync_client/test_v2_schemas.py New sync tests for generic + convenience schema methods and v2 root URL construction.
tests/async_client/test_v2_schemas.py New async tests (httpx/respx) for generic + convenience schema methods and error cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +8 to +10
SCHEMA_NAMES = ['users', 'sources', 'subjects', 'choices', 'spatial_features', 'event_types']


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