Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Jul 19, 2024
1 parent 589201b commit fc1679d
Show file tree
Hide file tree
Showing 13 changed files with 597 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Release Doctor
on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
Expand Down
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 12
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/open-transit%2Fopen-transit-d7feb31fedeae9f0af2581bf85d95d374eb2eee635e6823975bc4f419bd8e492.yml
configured_endpoints: 13
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/open-transit%2Fopen-transit-6c051801071707e025c582891048beeb3c06d10d13c852f8401a71604b81ac5d.yml
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ It is generated with [Stainless](https://www.stainlessapi.com/).

## Documentation

The REST API documentation can be found [on developer.onebusaway.org](https://developer.onebusaway.org). The full API of this library can be found in [api.md](api.md).
The REST API documentation can be found on [developer.onebusaway.org](https://developer.onebusaway.org). The full API of this library can be found in [api.md](api.md).

## Installation

Expand Down Expand Up @@ -277,6 +277,12 @@ client = OnebusawaySDK(
)
```

You can also customize the client on a per-request basis by using `with_options()`:

```python
client.with_options(http_client=DefaultHttpxClient(...))
```

### Managing HTTP resources

By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.
Expand Down
12 changes: 12 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,15 @@ from onebusaway.types import TripDetailRetrieveResponse
Methods:

- <code title="get /api/where/trip-details/{tripID}.json">client.trip_details.<a href="./src/onebusaway/resources/trip_details.py">retrieve</a>(trip_id, \*\*<a href="src/onebusaway/types/trip_detail_retrieve_params.py">params</a>) -> <a href="./src/onebusaway/types/trip_detail_retrieve_response.py">TripDetailRetrieveResponse</a></code>

# TripForVehicle

Types:

```python
from onebusaway.types import TripForVehicleRetrieveResponse
```

Methods:

- <code title="get /api/where/trip-for-vehicle/{vehicleID}.json">client.trip_for_vehicle.<a href="./src/onebusaway/resources/trip_for_vehicle.py">retrieve</a>(vehicle_id, \*\*<a href="src/onebusaway/types/trip_for_vehicle_retrieve_params.py">params</a>) -> <a href="./src/onebusaway/types/trip_for_vehicle_retrieve_response.py">TripForVehicleRetrieveResponse</a></code>
12 changes: 6 additions & 6 deletions src/onebusaway/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,9 +879,9 @@ def __exit__(
def _prepare_options(
self,
options: FinalRequestOptions, # noqa: ARG002
) -> None:
) -> FinalRequestOptions:
"""Hook for mutating the given options"""
return None
return options

def _prepare_request(
self,
Expand Down Expand Up @@ -961,7 +961,7 @@ def _request(
input_options = model_copy(options)

cast_to = self._maybe_override_cast_to(cast_to, options)
self._prepare_options(options)
options = self._prepare_options(options)

retries = self._remaining_retries(remaining_retries, options)
request = self._build_request(options)
Expand Down Expand Up @@ -1442,9 +1442,9 @@ async def __aexit__(
async def _prepare_options(
self,
options: FinalRequestOptions, # noqa: ARG002
) -> None:
) -> FinalRequestOptions:
"""Hook for mutating the given options"""
return None
return options

async def _prepare_request(
self,
Expand Down Expand Up @@ -1529,7 +1529,7 @@ async def _request(
input_options = model_copy(options)

cast_to = self._maybe_override_cast_to(cast_to, options)
await self._prepare_options(options)
options = await self._prepare_options(options)

retries = self._remaining_retries(remaining_retries, options)
request = self._build_request(options)
Expand Down
8 changes: 8 additions & 0 deletions src/onebusaway/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class OnebusawaySDK(SyncAPIClient):
trip: resources.TripResource
trips_for_location: resources.TripsForLocationResource
trip_details: resources.TripDetailsResource
trip_for_vehicle: resources.TripForVehicleResource
with_raw_response: OnebusawaySDKWithRawResponse
with_streaming_response: OnebusawaySDKWithStreamedResponse

Expand Down Expand Up @@ -125,6 +126,7 @@ def __init__(
self.trip = resources.TripResource(self)
self.trips_for_location = resources.TripsForLocationResource(self)
self.trip_details = resources.TripDetailsResource(self)
self.trip_for_vehicle = resources.TripForVehicleResource(self)
self.with_raw_response = OnebusawaySDKWithRawResponse(self)
self.with_streaming_response = OnebusawaySDKWithStreamedResponse(self)

Expand Down Expand Up @@ -253,6 +255,7 @@ class AsyncOnebusawaySDK(AsyncAPIClient):
trip: resources.AsyncTripResource
trips_for_location: resources.AsyncTripsForLocationResource
trip_details: resources.AsyncTripDetailsResource
trip_for_vehicle: resources.AsyncTripForVehicleResource
with_raw_response: AsyncOnebusawaySDKWithRawResponse
with_streaming_response: AsyncOnebusawaySDKWithStreamedResponse

Expand Down Expand Up @@ -321,6 +324,7 @@ def __init__(
self.trip = resources.AsyncTripResource(self)
self.trips_for_location = resources.AsyncTripsForLocationResource(self)
self.trip_details = resources.AsyncTripDetailsResource(self)
self.trip_for_vehicle = resources.AsyncTripForVehicleResource(self)
self.with_raw_response = AsyncOnebusawaySDKWithRawResponse(self)
self.with_streaming_response = AsyncOnebusawaySDKWithStreamedResponse(self)

Expand Down Expand Up @@ -452,6 +456,7 @@ def __init__(self, client: OnebusawaySDK) -> None:
self.trip = resources.TripResourceWithRawResponse(client.trip)
self.trips_for_location = resources.TripsForLocationResourceWithRawResponse(client.trips_for_location)
self.trip_details = resources.TripDetailsResourceWithRawResponse(client.trip_details)
self.trip_for_vehicle = resources.TripForVehicleResourceWithRawResponse(client.trip_for_vehicle)


class AsyncOnebusawaySDKWithRawResponse:
Expand All @@ -471,6 +476,7 @@ def __init__(self, client: AsyncOnebusawaySDK) -> None:
self.trip = resources.AsyncTripResourceWithRawResponse(client.trip)
self.trips_for_location = resources.AsyncTripsForLocationResourceWithRawResponse(client.trips_for_location)
self.trip_details = resources.AsyncTripDetailsResourceWithRawResponse(client.trip_details)
self.trip_for_vehicle = resources.AsyncTripForVehicleResourceWithRawResponse(client.trip_for_vehicle)


class OnebusawaySDKWithStreamedResponse:
Expand All @@ -490,6 +496,7 @@ def __init__(self, client: OnebusawaySDK) -> None:
self.trip = resources.TripResourceWithStreamingResponse(client.trip)
self.trips_for_location = resources.TripsForLocationResourceWithStreamingResponse(client.trips_for_location)
self.trip_details = resources.TripDetailsResourceWithStreamingResponse(client.trip_details)
self.trip_for_vehicle = resources.TripForVehicleResourceWithStreamingResponse(client.trip_for_vehicle)


class AsyncOnebusawaySDKWithStreamedResponse:
Expand All @@ -513,6 +520,7 @@ def __init__(self, client: AsyncOnebusawaySDK) -> None:
client.trips_for_location
)
self.trip_details = resources.AsyncTripDetailsResourceWithStreamingResponse(client.trip_details)
self.trip_for_vehicle = resources.AsyncTripForVehicleResourceWithStreamingResponse(client.trip_for_vehicle)


Client = OnebusawaySDK
Expand Down
6 changes: 3 additions & 3 deletions src/onebusaway/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ def get_model_fields(model: type[pydantic.BaseModel]) -> dict[str, FieldInfo]:
return model.__fields__ # type: ignore


def model_copy(model: _ModelT) -> _ModelT:
def model_copy(model: _ModelT, *, deep: bool = False) -> _ModelT:
if PYDANTIC_V2:
return model.model_copy()
return model.copy() # type: ignore
return model.model_copy(deep=deep)
return model.copy(deep=deep) # type: ignore


def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
Expand Down
14 changes: 14 additions & 0 deletions src/onebusaway/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
StopsForRouteResourceWithStreamingResponse,
AsyncStopsForRouteResourceWithStreamingResponse,
)
from .trip_for_vehicle import (
TripForVehicleResource,
AsyncTripForVehicleResource,
TripForVehicleResourceWithRawResponse,
AsyncTripForVehicleResourceWithRawResponse,
TripForVehicleResourceWithStreamingResponse,
AsyncTripForVehicleResourceWithStreamingResponse,
)
from .stops_for_location import (
StopsForLocationResource,
AsyncStopsForLocationResource,
Expand Down Expand Up @@ -156,4 +164,10 @@
"AsyncTripDetailsResourceWithRawResponse",
"TripDetailsResourceWithStreamingResponse",
"AsyncTripDetailsResourceWithStreamingResponse",
"TripForVehicleResource",
"AsyncTripForVehicleResource",
"TripForVehicleResourceWithRawResponse",
"AsyncTripForVehicleResourceWithRawResponse",
"TripForVehicleResourceWithStreamingResponse",
"AsyncTripForVehicleResourceWithStreamingResponse",
]
200 changes: 200 additions & 0 deletions src/onebusaway/resources/trip_for_vehicle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

import httpx

from ..types import trip_for_vehicle_retrieve_params
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from .._utils import (
maybe_transform,
async_maybe_transform,
)
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import (
to_raw_response_wrapper,
to_streamed_response_wrapper,
async_to_raw_response_wrapper,
async_to_streamed_response_wrapper,
)
from .._base_client import make_request_options
from ..types.trip_for_vehicle_retrieve_response import TripForVehicleRetrieveResponse

__all__ = ["TripForVehicleResource", "AsyncTripForVehicleResource"]


class TripForVehicleResource(SyncAPIResource):
@cached_property
def with_raw_response(self) -> TripForVehicleResourceWithRawResponse:
return TripForVehicleResourceWithRawResponse(self)

@cached_property
def with_streaming_response(self) -> TripForVehicleResourceWithStreamingResponse:
return TripForVehicleResourceWithStreamingResponse(self)

def retrieve(
self,
vehicle_id: str,
*,
include_schedule: bool | NotGiven = NOT_GIVEN,
include_status: bool | NotGiven = NOT_GIVEN,
include_trip: bool | NotGiven = NOT_GIVEN,
time: int | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> TripForVehicleRetrieveResponse:
"""
Retrieve trip for a specific vehicle
Args:
include_schedule: Determines whether full <schedule/> element is included in the <tripDetails/>
section. Defaults to false.
include_status: Determines whether the full <status/> element is included in the <tripDetails/>
section. Defaults to true.
include_trip: Determines whether full <trip/> element is included in the <references/>
section. Defaults to false.
time: Time parameter to query the system at a specific time (optional).
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not vehicle_id:
raise ValueError(f"Expected a non-empty value for `vehicle_id` but received {vehicle_id!r}")
return self._get(
f"/api/where/trip-for-vehicle/vehicleID.json",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"include_schedule": include_schedule,
"include_status": include_status,
"include_trip": include_trip,
"time": time,
},
trip_for_vehicle_retrieve_params.TripForVehicleRetrieveParams,
),
),
cast_to=TripForVehicleRetrieveResponse,
)


class AsyncTripForVehicleResource(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncTripForVehicleResourceWithRawResponse:
return AsyncTripForVehicleResourceWithRawResponse(self)

@cached_property
def with_streaming_response(self) -> AsyncTripForVehicleResourceWithStreamingResponse:
return AsyncTripForVehicleResourceWithStreamingResponse(self)

async def retrieve(
self,
vehicle_id: str,
*,
include_schedule: bool | NotGiven = NOT_GIVEN,
include_status: bool | NotGiven = NOT_GIVEN,
include_trip: bool | NotGiven = NOT_GIVEN,
time: int | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> TripForVehicleRetrieveResponse:
"""
Retrieve trip for a specific vehicle
Args:
include_schedule: Determines whether full <schedule/> element is included in the <tripDetails/>
section. Defaults to false.
include_status: Determines whether the full <status/> element is included in the <tripDetails/>
section. Defaults to true.
include_trip: Determines whether full <trip/> element is included in the <references/>
section. Defaults to false.
time: Time parameter to query the system at a specific time (optional).
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not vehicle_id:
raise ValueError(f"Expected a non-empty value for `vehicle_id` but received {vehicle_id!r}")
return await self._get(
f"/api/where/trip-for-vehicle/vehicleID.json",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=await async_maybe_transform(
{
"include_schedule": include_schedule,
"include_status": include_status,
"include_trip": include_trip,
"time": time,
},
trip_for_vehicle_retrieve_params.TripForVehicleRetrieveParams,
),
),
cast_to=TripForVehicleRetrieveResponse,
)


class TripForVehicleResourceWithRawResponse:
def __init__(self, trip_for_vehicle: TripForVehicleResource) -> None:
self._trip_for_vehicle = trip_for_vehicle

self.retrieve = to_raw_response_wrapper(
trip_for_vehicle.retrieve,
)


class AsyncTripForVehicleResourceWithRawResponse:
def __init__(self, trip_for_vehicle: AsyncTripForVehicleResource) -> None:
self._trip_for_vehicle = trip_for_vehicle

self.retrieve = async_to_raw_response_wrapper(
trip_for_vehicle.retrieve,
)


class TripForVehicleResourceWithStreamingResponse:
def __init__(self, trip_for_vehicle: TripForVehicleResource) -> None:
self._trip_for_vehicle = trip_for_vehicle

self.retrieve = to_streamed_response_wrapper(
trip_for_vehicle.retrieve,
)


class AsyncTripForVehicleResourceWithStreamingResponse:
def __init__(self, trip_for_vehicle: AsyncTripForVehicleResource) -> None:
self._trip_for_vehicle = trip_for_vehicle

self.retrieve = async_to_streamed_response_wrapper(
trip_for_vehicle.retrieve,
)
Loading

0 comments on commit fc1679d

Please sign in to comment.