Skip to content

Commit

Permalink
Use AirflowRouter over fastapi.APIRouter
Browse files Browse the repository at this point in the history
  • Loading branch information
bugraoz93 committed Oct 1, 2024
1 parent 7f1fb27 commit d30d43e
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 38 deletions.
2 changes: 1 addition & 1 deletion airflow/api_fastapi/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ paths:
- Connection
summary: Delete Connection
description: Delete a connection entry.
operationId: delete_connection_public_connections__connection_id__delete
operationId: delete_connection
parameters:
- name: connection_id
in: path
Expand Down
2 changes: 2 additions & 0 deletions airflow/api_fastapi/views/public/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

from __future__ import annotations

from airflow.api_fastapi.views.public.connections import connections_router
from airflow.api_fastapi.views.public.dags import dags_router
from airflow.api_fastapi.views.router import AirflowRouter

public_router = AirflowRouter(prefix="/public")


public_router.include_router(dags_router)
public_router.include_router(connections_router)
5 changes: 3 additions & 2 deletions airflow/api_fastapi/views/public/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
# under the License.
from __future__ import annotations

from fastapi import APIRouter, Depends, HTTPException
from fastapi import Depends, HTTPException
from sqlalchemy import select
from sqlalchemy.orm import Session
from typing_extensions import Annotated

from airflow.api_fastapi.db.common import get_session
from airflow.api_fastapi.openapi.exceptions import create_openapi_http_exception_doc
from airflow.api_fastapi.views.router import AirflowRouter
from airflow.models import Connection

connections_router = APIRouter(tags=["Connection"])
connections_router = AirflowRouter(tags=["Connection"])


@connections_router.delete(
Expand Down
9 changes: 3 additions & 6 deletions airflow/ui/openapi-gen/queries/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ export type DagServicePatchDagsMutationResult = Awaited<
export type DagServicePatchDagMutationResult = Awaited<
ReturnType<typeof DagService.patchDag>
>;
export type ConnectionServiceDeleteConnectionPublicConnectionsConnectionIdDeleteMutationResult =
Awaited<
ReturnType<
typeof ConnectionService.deleteConnectionPublicConnectionsConnectionIdDelete
>
>;
export type ConnectionServiceDeleteConnectionMutationResult = Awaited<
ReturnType<typeof ConnectionService.deleteConnection>
>;
51 changes: 25 additions & 26 deletions airflow/ui/openapi-gen/queries/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,35 +259,34 @@ export const useDagServicePatchDag = <
* @returns void Successful Response
* @throws ApiError
*/
export const useConnectionServiceDeleteConnectionPublicConnectionsConnectionIdDelete =
<
TData = Common.ConnectionServiceDeleteConnectionPublicConnectionsConnectionIdDeleteMutationResult,
TError = unknown,
TContext = unknown,
>(
options?: Omit<
UseMutationOptions<
TData,
TError,
{
connectionId: string;
},
TContext
>,
"mutationFn"
>,
) =>
useMutation<
export const useConnectionServiceDeleteConnection = <
TData = Common.ConnectionServiceDeleteConnectionMutationResult,
TError = unknown,
TContext = unknown,
>(
options?: Omit<
UseMutationOptions<
TData,
TError,
{
connectionId: string;
},
TContext
>({
mutationFn: ({ connectionId }) =>
ConnectionService.deleteConnectionPublicConnectionsConnectionIdDelete({
connectionId,
}) as unknown as Promise<TData>,
...options,
});
>,
"mutationFn"
>,
) =>
useMutation<
TData,
TError,
{
connectionId: string;
},
TContext
>({
mutationFn: ({ connectionId }) =>
ConnectionService.deleteConnection({
connectionId,
}) as unknown as Promise<TData>,
...options,
});
30 changes: 30 additions & 0 deletions airflow/ui/openapi-gen/requests/services.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type {
PatchDagsResponse,
PatchDagData,
PatchDagResponse,
DeleteConnectionData,
DeleteConnectionResponse,
} from "./types.gen";

export class AssetService {
Expand Down Expand Up @@ -159,3 +161,31 @@ export class DagService {
});
}
}

export class ConnectionService {
/**
* Delete Connection
* Delete a connection entry.
* @param data The data for the request.
* @param data.connectionId
* @returns void Successful Response
* @throws ApiError
*/
public static deleteConnection(
data: DeleteConnectionData,
): CancelablePromise<DeleteConnectionResponse> {
return __request(OpenAPI, {
method: "DELETE",
url: "/public/connections/{connection_id}",
path: {
connection_id: data.connectionId,
},
errors: {
401: "Unauthorized",
403: "Forbidden",
404: "Not Found",
422: "Validation Error",
},
});
}
}
6 changes: 3 additions & 3 deletions airflow/ui/openapi-gen/requests/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ export type PatchDagData = {

export type PatchDagResponse = DAGResponse;

export type DeleteConnectionPublicConnectionsConnectionIdDeleteData = {
export type DeleteConnectionData = {
connectionId: string;
};

export type DeleteConnectionPublicConnectionsConnectionIdDeleteResponse = void;
export type DeleteConnectionResponse = void;

export type $OpenApiTs = {
"/ui/next_run_datasets/{dag_id}": {
Expand Down Expand Up @@ -235,7 +235,7 @@ export type $OpenApiTs = {
};
"/public/connections/{connection_id}": {
delete: {
req: DeleteConnectionPublicConnectionsConnectionIdDeleteData;
req: DeleteConnectionData;
res: {
/**
* Successful Response
Expand Down

0 comments on commit d30d43e

Please sign in to comment.