Skip to content

add v2 event type schema and updates endpoints#25

Open
JoshuaVulcan wants to merge 4 commits intomainfrom
ERA-12658/v2-event-type-schema-updates
Open

add v2 event type schema and updates endpoints#25
JoshuaVulcan wants to merge 4 commits intomainfrom
ERA-12658/v2-event-type-schema-updates

Conversation

@JoshuaVulcan
Copy link
Copy Markdown
Contributor

@JoshuaVulcan JoshuaVulcan commented Feb 10, 2026

Summary

  • Adds _v2_url() helper to both ERClient and AsyncERClient that constructs URLs against the v2.0 API root
  • Adds three new methods to both sync and async clients:
    • get_event_type_schema(value, pre_render=False) -- single event type schema via eventtypes/{value}/schema
    • get_event_type_updates(value) -- revision history via eventtypes/{value}/updates
    • get_event_type_schemas(pre_render=False) -- bulk schema list via eventtypes/schemas
  • Teaches AsyncERClient._call() to skip _er_url() when the path is already an absolute URL
  • 8 new tests covering success, pre_render param, 404, and timeout scenarios

Test plan

  • all 98 tests pass (90 existing + 8 new)

Resolves ERA-12658

Adds _v2_url() helper to both ERClient and AsyncERClient, which
constructs URLs against the v2.0 API root by swapping the version
segment in service_root.

New methods on both clients:
- get_event_type_schema(value, pre_render) -- single event type schema
- get_event_type_updates(value) -- revision history for an event type
- get_event_type_schemas(pre_render) -- bulk schema list

Also teaches AsyncERClient._call() to skip _er_url() when the path
is already an absolute URL, enabling the v2 methods to pass full URLs.

ERA-12658

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
Replace the brittle `_v2_url()` regex-based v2 URL construction 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.

Reverts the `path.startswith('http')` guard in async `_call()` in favor
of the `base_url` approach which is explicit and non-magical.

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

V2 URL Convention Alignment

Replaced the _v2_url() regex-based v2 URL construction with the _api_root(version) + base_url parameter pattern established in PR #23.

Changes:

  • Removed _v2_url() from both ERClient and AsyncERClient
  • Added _api_root(version) method to both clients (strips /api/vX.Y from service_root and rebuilds as {base}/api/{version})
  • 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_event_type_schema(), get_event_type_updates(), get_event_type_schemas() to use base_url=self._api_root('v2.0') instead of constructing full URLs via _v2_url()
  • Reverted the path.startswith('http') guard in async _call() — the base_url approach is explicit and non-magical

Tests are unchanged since the resulting URLs are identical. This PR is now compatible with PR #23's infrastructure and will merge cleanly once #23 lands.

Copy link
Copy Markdown
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

This PR adds support for three new v2 API endpoints related to event type schemas and updates. The implementation introduces a new _api_root() helper method in both sync and async clients to construct URLs against different API versions, and adds methods to fetch event type schemas (single and bulk) and revision history.

Changes:

  • Adds _api_root() helper to construct versioned API URLs (v1.0, v2.0, etc.)
  • Implements three new methods: get_event_type_schema(), get_event_type_updates(), and get_event_type_schemas() in both sync and async clients
  • Updates _er_url(), _get(), _post(), _patch(), and _call() methods to accept optional base_url parameter for API versioning
  • Adds comprehensive test coverage (8 tests) for async client implementations

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
erclient/client.py Adds _api_root() helper and three new v2 API methods to both ERClient and AsyncERClient classes; updates internal HTTP methods to support custom base URLs
tests/async_client/test_get_event_type_schema.py Comprehensive test suite (8 tests) covering success, error, parameter, and timeout scenarios for the new async client methods

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

Comment on lines +610 to +644
def get_event_type_schema(self, event_type_value, pre_render=False):
"""
Get the schema for a single event type (v2 API).

:param event_type_value: The event type 'value' identifier (e.g. 'rainfall_rep')
:param pre_render: If True, return the pre-rendered schema
"""
return self._get(
f'eventtypes/{event_type_value}/schema',
base_url=self._api_root('v2.0'),
params={'pre_render': pre_render},
)

def get_event_type_updates(self, event_type_value):
"""
Get the revision history for a single event type (v2 API).

:param event_type_value: The event type 'value' identifier
"""
return self._get(
f'eventtypes/{event_type_value}/updates',
base_url=self._api_root('v2.0'),
)

def get_event_type_schemas(self, pre_render=False):
"""
Get schemas for all event types in bulk (v2 API).

:param pre_render: If True, return pre-rendered schemas
"""
return self._get(
'eventtypes/schemas',
base_url=self._api_root('v2.0'),
params={'pre_render': pre_render},
)
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

The new sync client methods get_event_type_schema, get_event_type_updates, and get_event_type_schemas lack test coverage. While there are 8 comprehensive tests for the async versions of these methods, there are no corresponding tests for the sync client. The repository shows a pattern of comprehensive testing for the async client but lacks tests for the sync client entirely. Consider adding test coverage for the sync client methods to match the async client test coverage.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +2
import re

Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

The re module is imported but never used in this test file. Consider removing this unused import.

Suggested change
import re

Copilot uses AI. Check for mistakes.
return_value=httpx.Response(httpx.codes.OK, json={"data": schema_response})
)
result = await er_client.get_event_type_schema("rainfall_rep", pre_render=True)
assert route.called
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

Variable result is not used.

Suggested change
assert route.called
assert route.called
assert result == schema_response

Copilot uses AI. Check for mistakes.
route = respx_mock.get("/eventtypes/schemas").mock(
return_value=httpx.Response(httpx.codes.OK, json=schemas_bulk_response)
)
result = await er_client.get_event_type_schemas(pre_render=True)
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

Variable result is not used.

Suggested change
result = await er_client.get_event_type_schemas(pre_render=True)
await er_client.get_event_type_schemas(pre_render=True)

Copilot uses AI. Check for mistakes.
Co-authored-by: Cursor <cursoragent@cursor.com>
@JoshuaVulcan JoshuaVulcan requested a review from a team as a code owner February 12, 2026 01:33
Comment on lines +658 to +692
def get_event_type_schema(self, event_type_value, pre_render=False):
"""
Get the schema for a single event type (v2 API).

:param event_type_value: The event type 'value' identifier (e.g. 'rainfall_rep')
:param pre_render: If True, return the pre-rendered schema
"""
return self._get(
f'eventtypes/{event_type_value}/schema',
base_url=self._api_root('v2.0'),
params={'pre_render': pre_render},
)

def get_event_type_updates(self, event_type_value):
"""
Get the revision history for a single event type (v2 API).

:param event_type_value: The event type 'value' identifier
"""
return self._get(
f'eventtypes/{event_type_value}/updates',
base_url=self._api_root('v2.0'),
)

def get_event_type_schemas(self, pre_render=False):
"""
Get schemas for all event types in bulk (v2 API).

:param pre_render: If True, return pre-rendered schemas
"""
return self._get(
'eventtypes/schemas',
base_url=self._api_root('v2.0'),
params={'pre_render': pre_render},
)
Copy link
Copy Markdown
Contributor

@chrisdoehring chrisdoehring Mar 13, 2026

Choose a reason for hiding this comment

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

Is this indicative of v1 EOL?
And you might want to use the VERSION_2_0 constant for these.

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.

3 participants