Skip to content

Commit

Permalink
Bumps the Python types from the OpenAPI schema (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgomes authored Jan 16, 2025
1 parent b14cfa8 commit 2dbcfa6
Show file tree
Hide file tree
Showing 12 changed files with 2,567 additions and 1,406 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ $ make record

This will record new cassettes for the tests. Make sure to commit these cassettes along with your changes.

### Updating the schema

In order to update the Python data types from the OpenAPI schema, you need to:

```
$ mkdir neon_client/
$ make schema
# Now, take `neon_client/schema.py` and replace `neon_api/schema.py` with it.
# Now, run:
$ make test
# You may have to run `make record` to update the fixtures.
```

## License & Copyright

[Apache 2.0 Licensed](./LICENSE).
36 changes: 1 addition & 35 deletions neon_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def project(self, project_id: str) -> t.Dict[str, t.Any]:

return self._request("GET", r_path)

@returns_model(schema.ConnectionUri)
@returns_model(schema.ConnectionURIResponse)
def connection_uri(
self,
project_id: str,
Expand Down Expand Up @@ -797,37 +797,3 @@ def operation(self, project_id: str, operation_id: str) -> t.Dict[str, t.Any]:
return self._request(
"GET", f"projects/{ project_id }/operations/{ operation_id }"
)

@returns_model(schema.ProjectsConsumptionResponse)
def consumption(
self,
*,
cursor: str = None,
limit: int = None,
from_date: datetime = None,
to_date: datetime = None,
) -> t.Dict[str, t.Any]:
"""Experimental — get a list of consumption metrics for all projects.
:param cursor: The cursor for pagination (default is None).
:param limit: The maximum number of projects to retrieve (default is None).
:param from_date: The start date for the consumption metrics (default is None).
:param to_date: The end date for the consumption metrics (default is None).
:return: A dataclass representing the consumption metrics.
More info: https://api-docs.neon.tech/reference/listprojectsconsumption
"""

# Convert datetime objects to ISO 8601 strings.
from_date = (
to_iso8601(from_date) if isinstance(from_date, datetime) else from_date
)
to_date = to_iso8601(to_date) if isinstance(to_date, datetime) else to_date

# Construct the request parameters.
r_params = compact_mapping(
{"cursor": cursor, "limit": limit, "from": from_date, "to": to_date}
)

# Make the request.
return self._request("GET", "consumption/projects", params=r_params)
Loading

0 comments on commit 2dbcfa6

Please sign in to comment.