Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python: Use openapi-codegen for high-level python API client #1646

Merged
merged 15 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## Unreleased
* Libs/Python **(Breaking)**: `PostOptions` and `ListOptions` are no longer used in methods for `Authentication`,`Endpoint`,`EventType`,`Integration`,`MessageAttempt`,`Message` and `Statistics` resources. Instead each API call now has it's own `{Resource}{Operation}Options`. (Both sync and async)
* Libs/Python: In `Application` the `dashboard_access` method is deprecated in favor of `app_portal_access`. (Both sync and async)
* Libs/Python **(Breaking)**: `EndpointStatsOptions` is renamed to `EndpointGetStatsOptions`
* Libs/Python **(Breaking)**: `MessageAttemptListOptions` is removed in favor of call specific `{Resource}{Operation}Options`
* Libs/Python **(Breaking)**: For `Statistics` in the `aggregate_event_types` method the `task_id` parameter is removed, Please note that previously this parameter was ignored and had no affect (Both sync and async)
* Libs/Kotlin **(Breaking)**: Mark `api` field of all API resource classes as `private` (previously
only some were private, accidentally)
* Libs/Kotlin **(Breaking)**: Update `recover` to return `RecoverOut` (instead of nothing)
Expand Down
55 changes: 48 additions & 7 deletions python/svix/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,62 @@
ApplicationCreateOptions,
ApplicationGetOrCreateOptions,
)
from .authentication import AuthenticationAsync, Authentication
from .endpoint import EndpointAsync, Endpoint, EndpointListOptions
from .event_type import EventTypeAsync, EventType, EventTypeListOptions
from .integration import IntegrationAsync, Integration
from .message import MessageAsync, Message
from .authentication import (
AuthenticationAsync,
Authentication,
AuthenticationAppPortalAccessOptions,
AuthenticationDashboardAccessOptions,
AuthenticationExpireAllOptions,
AuthenticationLogoutOptions,
)
from .endpoint import (
EndpointAsync,
Endpoint,
EndpointListOptions,
EndpointCreateOptions,
EndpointRecoverOptions,
EndpointReplayMissingOptions,
EndpointRotateSecretOptions,
EndpointSendExampleOptions,
EndpointGetStatsOptions,
)
from .event_type import (
EventTypeAsync,
EventType,
EventTypeListOptions,
EventTypeCreateOptions,
EventTypeImportOpenapiOptions,
EventTypeDeleteOptions,
)
from .integration import (
IntegrationAsync,
Integration,
IntegrationListOptions,
IntegrationCreateOptions,
IntegrationRotateKeyOptions,
)
from .message import (
MessageAsync,
Message,
MessageListOptions,
MessageCreateOptions,
MessageGetOptions,
)
from .message_attempt import (
MessageAttemptAsync,
MessageAttempt,
MessageAttemptListOptions,
MessageAttemptListByEndpointOptions,
MessageAttemptListByMsgOptions,
MessageAttemptListAttemptedMessagesOptions,
MessageAttemptListAttemptedDestinationsOptions,
MessageAttemptResendOptions,
MessageListAttemptsForEndpointOptions,
)
from .operational_webhook import (
OperationalWebhookEndpointAsync,
OperationalWebhookEndpoint,
)
from .statistics import StatisticsAsync, Statistics
from .statistics import StatisticsAsync, Statistics, StatisticsAggregateAppStatsOptions

from svix.internal.openapi_client.models.aggregate_event_types_out import (
AggregateEventTypesOut,
Expand Down
90 changes: 83 additions & 7 deletions python/svix/api/authentication.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,90 @@
from .common import PostOptions, ApiBase
import typing as t
from dataclasses import dataclass
from deprecated import deprecated

from .common import ApiBase, BaseOptions


from ..internal.openapi_client.api.authentication import (
v1_authentication_app_portal_access,
v1_authentication_dashboard_access,
v1_authentication_expire_all,
v1_authentication_logout,
)

from ..internal.openapi_client.models.app_portal_access_in import AppPortalAccessIn
from ..internal.openapi_client.models.app_portal_access_out import AppPortalAccessOut
from ..internal.openapi_client.models.dashboard_access_out import DashboardAccessOut
from ..internal.openapi_client.models.application_token_expire_in import (
ApplicationTokenExpireIn,
)


@dataclass
class AuthenticationAppPortalAccessOptions(BaseOptions):
idempotency_key: t.Optional[str] = None


@dataclass
class AuthenticationDashboardAccessOptions(BaseOptions):
idempotency_key: t.Optional[str] = None


@dataclass
class AuthenticationExpireAllOptions(BaseOptions):
idempotency_key: t.Optional[str] = None


@dataclass
class AuthenticationLogoutOptions(BaseOptions):
idempotency_key: t.Optional[str] = None


class AuthenticationAsync(ApiBase):
async def app_portal_access(
self,
app_id: str,
app_portal_access_in: AppPortalAccessIn,
options: PostOptions = PostOptions(),
options: AuthenticationAppPortalAccessOptions = AuthenticationAppPortalAccessOptions(),
) -> AppPortalAccessOut:
"""Use this function to get magic links (and authentication codes) for connecting your users to the Consumer Application Portal."""
return await v1_authentication_app_portal_access.request_asyncio(
client=self._client,
app_id=app_id,
json_body=app_portal_access_in,
**options.to_dict(),
)

@deprecated
async def dashboard_access(
self, app_id: str, options: PostOptions = PostOptions()
self,
app_id: str,
options: AuthenticationDashboardAccessOptions = AuthenticationDashboardAccessOptions(),
) -> DashboardAccessOut:
return await v1_authentication_dashboard_access.request_asyncio(
client=self._client, app_id=app_id, **options.to_dict()
)

async def logout(self, options: PostOptions = PostOptions()) -> None:
async def expire_all(
self,
app_id: str,
application_token_expire_in: ApplicationTokenExpireIn,
options: AuthenticationExpireAllOptions = AuthenticationExpireAllOptions(),
) -> None:
"""Expire all of the tokens associated with a specific application."""
return await v1_authentication_expire_all.request_asyncio(
client=self._client,
app_id=app_id,
json_body=application_token_expire_in,
**options.to_dict(),
)

async def logout(
self, options: AuthenticationLogoutOptions = AuthenticationLogoutOptions()
) -> None:
"""Logout an app token.

Trying to log out other tokens will fail."""
return await v1_authentication_logout.request_asyncio(
client=self._client, **options.to_dict()
)
Expand All @@ -42,23 +95,46 @@ def app_portal_access(
self,
app_id: str,
app_portal_access_in: AppPortalAccessIn,
options: PostOptions = PostOptions(),
options: AuthenticationAppPortalAccessOptions = AuthenticationAppPortalAccessOptions(),
) -> AppPortalAccessOut:
"""Use this function to get magic links (and authentication codes) for connecting your users to the Consumer Application Portal."""
return v1_authentication_app_portal_access.request_sync(
client=self._client,
app_id=app_id,
json_body=app_portal_access_in,
**options.to_dict(),
)

def expire_all(
self,
app_id: str,
application_token_expire_in: ApplicationTokenExpireIn,
options: AuthenticationExpireAllOptions = AuthenticationExpireAllOptions(),
) -> None:
"""Expire all of the tokens associated with a specific application."""
return v1_authentication_expire_all.request_sync(
client=self._client,
app_id=app_id,
json_body=application_token_expire_in,
**options.to_dict(),
)

@deprecated
def dashboard_access(
self, app_id: str, options: PostOptions = PostOptions()
self,
app_id: str,
options: AuthenticationDashboardAccessOptions = AuthenticationDashboardAccessOptions(),
) -> DashboardAccessOut:
return v1_authentication_dashboard_access.request_sync(
client=self._client, app_id=app_id, **options.to_dict()
)

def logout(self, options: PostOptions = PostOptions()) -> None:
def logout(
self, options: AuthenticationLogoutOptions = AuthenticationLogoutOptions()
) -> None:
"""Logout an app token.

Trying to log out other tokens will fail."""
return v1_authentication_logout.request_sync(
client=self._client, **options.to_dict()
)
Loading