Add new API endpoints to the OpenGov SDK from an OpenAPI specification...
Generate SDK endpoints from OpenAPI specifications following project conventions.
| Component | Location | When |
|---|---|---|
| Endpoint module | src/opengov_api/{resource}.py |
Always |
| Response models | src/opengov_api/models/{resource}.py |
If typed responses needed |
| Params model | src/opengov_api/models/params.py |
If list endpoint has filters |
| Enums | src/opengov_api/models/enums.py |
If status/type enums needed |
| Model exports | src/opengov_api/models/__init__.py |
When adding models |
| SDK exports | src/opengov_api/__init__.py |
Always |
| Tests | tests/test_{resource}.py |
Always |
| Common tests | tests/test_common_endpoints.py |
Add to parametrized lists |
| OpenAPI | SDK |
|---|---|
GET /{resource} |
list_{resource}() returning JSONAPIResponse[{Resource}Resource] |
GET /{resource}/{id} |
get_{resource}(id) returning dict[str, Any] |
POST /{resource} |
create_{resource}(data) returning dict[str, Any] |
PATCH /{resource}/{id} |
update_{resource}(id, data) returning dict[str, Any] |
DELETE /{resource}/{id} |
delete_{resource}(id) or archive_{resource}(id) |
Nested GET /{parent}/{id}/{child} |
list_{parent}_{child}(parent_id) |
Nested POST /{parent}/{id}/{child} |
add_{parent}_{child}(parent_id, data) |
| OpenAPI Parameter | SDK Param Name | Model Field |
|---|---|---|
filter[status] |
status |
filter_status |
filter[createdAt] |
created_at |
filter_created_at |
filter[isEnabled] |
is_enabled |
filter_is_enabled |
page[number] |
page_number |
page_number |
page[size] |
page_size |
page_size |
See references/patterns.md for complete code examples including:
Before completing, verify:
Schema Extraction & Validation:
required array)nullable: true → | None)Field(alias=...) with exact casingCode Generation:
@handle_request_errors decoratorwith _get_client() as client: patternJSONAPIResponse[{Resource}Resource]Field(alias="camelCase") for JSON field mappingto_query_params() methodmodel_config = {"populate_by_name": True} present in all attribute modelsIntegration:
__init__.pymodels/__init__.pytests/test_{resource}.pytest_common_endpoints.py parametrized listsVerification:
uv run pytest passesuv run pyright passes