This is an automated email from the ASF dual-hosted git repository.

jedcunningham pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 956799ad53b AIP-84 Add GET DagVersions endpoint (#46691)
956799ad53b is described below

commit 956799ad53b129a1c1f9c23ce39a9001747f1088
Author: Pierre Jeambrun <[email protected]>
AuthorDate: Thu Feb 13 02:42:53 2025 +0100

    AIP-84 Add GET DagVersions endpoint (#46691)
---
 .../core_api/datamodels/dag_versions.py            |   7 +
 .../api_fastapi/core_api/openapi/v1-generated.yaml | 108 ++++++++++
 .../api_fastapi/core_api/routes/public/__init__.py |   2 +
 .../core_api/routes/public/dag_versions.py         |  96 +++++++++
 airflow/ui/openapi-gen/queries/common.ts           |  32 +++
 airflow/ui/openapi-gen/queries/prefetch.ts         |  58 ++++++
 airflow/ui/openapi-gen/queries/queries.ts          |  59 ++++++
 airflow/ui/openapi-gen/queries/suspense.ts         |  59 ++++++
 airflow/ui/openapi-gen/requests/schemas.gen.ts     |  20 ++
 airflow/ui/openapi-gen/requests/services.gen.ts    |  44 +++++
 airflow/ui/openapi-gen/requests/types.gen.ts       |  47 +++++
 .../core_api/routes/public/test_dag_versions.py    | 219 +++++++++++++++++++++
 12 files changed, 751 insertions(+)

diff --git a/airflow/api_fastapi/core_api/datamodels/dag_versions.py 
b/airflow/api_fastapi/core_api/datamodels/dag_versions.py
index 61f11a26a8c..4a14b7f6d3e 100644
--- a/airflow/api_fastapi/core_api/datamodels/dag_versions.py
+++ b/airflow/api_fastapi/core_api/datamodels/dag_versions.py
@@ -31,3 +31,10 @@ class DagVersionResponse(BaseModel):
     bundle_name: str
     bundle_version: str | None
     created_at: datetime
+
+
+class DAGVersionCollectionResponse(BaseModel):
+    """DAG Version Collection serializer for responses."""
+
+    dag_versions: list[DagVersionResponse]
+    total_entries: int
diff --git a/airflow/api_fastapi/core_api/openapi/v1-generated.yaml 
b/airflow/api_fastapi/core_api/openapi/v1-generated.yaml
index 44aac872412..660f1c24348 100644
--- a/airflow/api_fastapi/core_api/openapi/v1-generated.yaml
+++ b/airflow/api_fastapi/core_api/openapi/v1-generated.yaml
@@ -6649,6 +6649,98 @@ paths:
             application/json:
               schema:
                 $ref: '#/components/schemas/HTTPValidationError'
+  /public/dags/{dag_id}/dagVersions:
+    get:
+      tags:
+      - DagVersion
+      summary: Get Dag Versions
+      description: 'Get all DAG Versions.
+
+
+        This endpoint allows specifying `~` as the dag_id to retrieve DAG 
Versions
+        for all DAGs.'
+      operationId: get_dag_versions
+      parameters:
+      - name: dag_id
+        in: path
+        required: true
+        schema:
+          type: string
+          title: Dag Id
+      - name: limit
+        in: query
+        required: false
+        schema:
+          type: integer
+          minimum: 0
+          default: 100
+          title: Limit
+      - name: offset
+        in: query
+        required: false
+        schema:
+          type: integer
+          minimum: 0
+          default: 0
+          title: Offset
+      - name: version_number
+        in: query
+        required: false
+        schema:
+          type: integer
+          title: Version Number
+      - name: bundle_name
+        in: query
+        required: false
+        schema:
+          type: string
+          title: Bundle Name
+      - name: bundle_version
+        in: query
+        required: false
+        schema:
+          anyOf:
+          - type: string
+          - type: 'null'
+          title: Bundle Version
+      - name: order_by
+        in: query
+        required: false
+        schema:
+          type: string
+          default: id
+          title: Order By
+      responses:
+        '200':
+          description: Successful Response
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/DAGVersionCollectionResponse'
+        '401':
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/HTTPExceptionResponse'
+          description: Unauthorized
+        '403':
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/HTTPExceptionResponse'
+          description: Forbidden
+        '404':
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/HTTPExceptionResponse'
+          description: Not Found
+        '422':
+          description: Validation Error
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/HTTPValidationError'
   /public/monitor/health:
     get:
       tags:
@@ -8404,6 +8496,22 @@ components:
       - total_entries
       title: DAGTagCollectionResponse
       description: DAG Tags Collection serializer for responses.
+    DAGVersionCollectionResponse:
+      properties:
+        dag_versions:
+          items:
+            $ref: '#/components/schemas/DagVersionResponse'
+          type: array
+          title: Dag Versions
+        total_entries:
+          type: integer
+          title: Total Entries
+      type: object
+      required:
+      - dag_versions
+      - total_entries
+      title: DAGVersionCollectionResponse
+      description: DAG Version Collection serializer for responses.
     DAGWarningCollectionResponse:
       properties:
         dag_warnings:
diff --git a/airflow/api_fastapi/core_api/routes/public/__init__.py 
b/airflow/api_fastapi/core_api/routes/public/__init__.py
index 527f993d142..fb1ba416034 100644
--- a/airflow/api_fastapi/core_api/routes/public/__init__.py
+++ b/airflow/api_fastapi/core_api/routes/public/__init__.py
@@ -31,6 +31,7 @@ from airflow.api_fastapi.core_api.routes.public.dag_run 
import dag_run_router
 from airflow.api_fastapi.core_api.routes.public.dag_sources import 
dag_sources_router
 from airflow.api_fastapi.core_api.routes.public.dag_stats import 
dag_stats_router
 from airflow.api_fastapi.core_api.routes.public.dag_tags import dag_tags_router
+from airflow.api_fastapi.core_api.routes.public.dag_versions import 
dag_versions_router
 from airflow.api_fastapi.core_api.routes.public.dag_warning import 
dag_warning_router
 from airflow.api_fastapi.core_api.routes.public.dags import dags_router
 from airflow.api_fastapi.core_api.routes.public.event_logs import 
event_logs_router
@@ -80,6 +81,7 @@ authenticated_router.include_router(variables_router)
 authenticated_router.include_router(task_instances_log_router)
 authenticated_router.include_router(dag_parsing_router)
 authenticated_router.include_router(dag_tags_router)
+authenticated_router.include_router(dag_versions_router)
 
 
 # Include authenticated router in public router
diff --git a/airflow/api_fastapi/core_api/routes/public/dag_versions.py 
b/airflow/api_fastapi/core_api/routes/public/dag_versions.py
new file mode 100644
index 00000000000..bfcad2b6213
--- /dev/null
+++ b/airflow/api_fastapi/core_api/routes/public/dag_versions.py
@@ -0,0 +1,96 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from typing import Annotated
+
+from fastapi import Depends, HTTPException, Request, status
+from sqlalchemy import select
+
+from airflow.api_fastapi.common.db.common import SessionDep, paginated_select
+from airflow.api_fastapi.common.parameters import (
+    FilterParam,
+    QueryLimit,
+    QueryOffset,
+    SortParam,
+    filter_param_factory,
+)
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.datamodels.dag_versions import 
DAGVersionCollectionResponse
+from airflow.api_fastapi.core_api.openapi.exceptions import 
create_openapi_http_exception_doc
+from airflow.models.dag import DAG
+from airflow.models.dag_version import DagVersion
+
+dag_versions_router = AirflowRouter(tags=["DagVersion"], 
prefix="/dags/{dag_id}/dagVersions")
+
+
+@dag_versions_router.get(
+    "",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def get_dag_versions(
+    dag_id: str,
+    limit: QueryLimit,
+    offset: QueryOffset,
+    session: SessionDep,
+    request: Request,
+    version_number: Annotated[
+        FilterParam[int], 
Depends(filter_param_factory(DagVersion.version_number, int))
+    ],
+    bundle_name: Annotated[FilterParam[str], 
Depends(filter_param_factory(DagVersion.bundle_name, str))],
+    bundle_version: Annotated[
+        FilterParam[str | None], 
Depends(filter_param_factory(DagVersion.bundle_version, str | None))
+    ],
+    order_by: Annotated[
+        SortParam,
+        Depends(
+            SortParam(["id", "version_number", "bundle_name", 
"bundle_version"], DagVersion).dynamic_depends()
+        ),
+    ],
+) -> DAGVersionCollectionResponse:
+    """
+    Get all DAG Versions.
+
+    This endpoint allows specifying `~` as the dag_id to retrieve DAG Versions 
for all DAGs.
+    """
+    query = select(DagVersion)
+
+    if dag_id != "~":
+        dag: DAG = request.app.state.dag_bag.get_dag(dag_id)
+        if not dag:
+            raise HTTPException(status.HTTP_404_NOT_FOUND, f"The DAG with 
dag_id: `{dag_id}` was not found")
+
+        query = query.filter(DagVersion.dag_id == dag_id)
+
+    dag_versions_select, total_entries = paginated_select(
+        statement=query,
+        filters=[version_number, bundle_name, bundle_version],
+        order_by=order_by,
+        offset=offset,
+        limit=limit,
+        session=session,
+    )
+    dag_versions = session.scalars(dag_versions_select)
+
+    return DAGVersionCollectionResponse(
+        dag_versions=dag_versions,
+        total_entries=total_entries,
+    )
diff --git a/airflow/ui/openapi-gen/queries/common.ts 
b/airflow/ui/openapi-gen/queries/common.ts
index 2e6d7419d09..d89d1857839 100644
--- a/airflow/ui/openapi-gen/queries/common.ts
+++ b/airflow/ui/openapi-gen/queries/common.ts
@@ -12,6 +12,7 @@ import {
   DagService,
   DagSourceService,
   DagStatsService,
+  DagVersionService,
   DagWarningService,
   DagsService,
   DashboardService,
@@ -1623,6 +1624,37 @@ export const UseVariableServiceGetVariablesKeyFn = (
   } = {},
   queryKey?: Array<unknown>,
 ) => [useVariableServiceGetVariablesKey, ...(queryKey ?? [{ limit, offset, 
orderBy, variableKeyPattern }])];
+export type DagVersionServiceGetDagVersionsDefaultResponse = Awaited<
+  ReturnType<typeof DagVersionService.getDagVersions>
+>;
+export type DagVersionServiceGetDagVersionsQueryResult<
+  TData = DagVersionServiceGetDagVersionsDefaultResponse,
+  TError = unknown,
+> = UseQueryResult<TData, TError>;
+export const useDagVersionServiceGetDagVersionsKey = 
"DagVersionServiceGetDagVersions";
+export const UseDagVersionServiceGetDagVersionsKeyFn = (
+  {
+    bundleName,
+    bundleVersion,
+    dagId,
+    limit,
+    offset,
+    orderBy,
+    versionNumber,
+  }: {
+    bundleName?: string;
+    bundleVersion?: string;
+    dagId: string;
+    limit?: number;
+    offset?: number;
+    orderBy?: string;
+    versionNumber?: number;
+  },
+  queryKey?: Array<unknown>,
+) => [
+  useDagVersionServiceGetDagVersionsKey,
+  ...(queryKey ?? [{ bundleName, bundleVersion, dagId, limit, offset, orderBy, 
versionNumber }]),
+];
 export type MonitorServiceGetHealthDefaultResponse = Awaited<ReturnType<typeof 
MonitorService.getHealth>>;
 export type MonitorServiceGetHealthQueryResult<
   TData = MonitorServiceGetHealthDefaultResponse,
diff --git a/airflow/ui/openapi-gen/queries/prefetch.ts 
b/airflow/ui/openapi-gen/queries/prefetch.ts
index 0aeca60bf2a..b3c706fad96 100644
--- a/airflow/ui/openapi-gen/queries/prefetch.ts
+++ b/airflow/ui/openapi-gen/queries/prefetch.ts
@@ -11,6 +11,7 @@ import {
   DagService,
   DagSourceService,
   DagStatsService,
+  DagVersionService,
   DagWarningService,
   DagsService,
   DashboardService,
@@ -2278,6 +2279,63 @@ export const prefetchUseVariableServiceGetVariables = (
     queryKey: Common.UseVariableServiceGetVariablesKeyFn({ limit, offset, 
orderBy, variableKeyPattern }),
     queryFn: () => VariableService.getVariables({ limit, offset, orderBy, 
variableKeyPattern }),
   });
+/**
+ * Get Dag Versions
+ * Get all DAG Versions.
+ *
+ * This endpoint allows specifying `~` as the dag_id to retrieve DAG Versions 
for all DAGs.
+ * @param data The data for the request.
+ * @param data.dagId
+ * @param data.limit
+ * @param data.offset
+ * @param data.versionNumber
+ * @param data.bundleName
+ * @param data.bundleVersion
+ * @param data.orderBy
+ * @returns DAGVersionCollectionResponse Successful Response
+ * @throws ApiError
+ */
+export const prefetchUseDagVersionServiceGetDagVersions = (
+  queryClient: QueryClient,
+  {
+    bundleName,
+    bundleVersion,
+    dagId,
+    limit,
+    offset,
+    orderBy,
+    versionNumber,
+  }: {
+    bundleName?: string;
+    bundleVersion?: string;
+    dagId: string;
+    limit?: number;
+    offset?: number;
+    orderBy?: string;
+    versionNumber?: number;
+  },
+) =>
+  queryClient.prefetchQuery({
+    queryKey: Common.UseDagVersionServiceGetDagVersionsKeyFn({
+      bundleName,
+      bundleVersion,
+      dagId,
+      limit,
+      offset,
+      orderBy,
+      versionNumber,
+    }),
+    queryFn: () =>
+      DagVersionService.getDagVersions({
+        bundleName,
+        bundleVersion,
+        dagId,
+        limit,
+        offset,
+        orderBy,
+        versionNumber,
+      }),
+  });
 /**
  * Get Health
  * @returns HealthInfoResponse Successful Response
diff --git a/airflow/ui/openapi-gen/queries/queries.ts 
b/airflow/ui/openapi-gen/queries/queries.ts
index 449452418dd..531102d2dd2 100644
--- a/airflow/ui/openapi-gen/queries/queries.ts
+++ b/airflow/ui/openapi-gen/queries/queries.ts
@@ -12,6 +12,7 @@ import {
   DagService,
   DagSourceService,
   DagStatsService,
+  DagVersionService,
   DagWarningService,
   DagsService,
   DashboardService,
@@ -2691,6 +2692,64 @@ export const useVariableServiceGetVariables = <
     queryFn: () => VariableService.getVariables({ limit, offset, orderBy, 
variableKeyPattern }) as TData,
     ...options,
   });
+/**
+ * Get Dag Versions
+ * Get all DAG Versions.
+ *
+ * This endpoint allows specifying `~` as the dag_id to retrieve DAG Versions 
for all DAGs.
+ * @param data The data for the request.
+ * @param data.dagId
+ * @param data.limit
+ * @param data.offset
+ * @param data.versionNumber
+ * @param data.bundleName
+ * @param data.bundleVersion
+ * @param data.orderBy
+ * @returns DAGVersionCollectionResponse Successful Response
+ * @throws ApiError
+ */
+export const useDagVersionServiceGetDagVersions = <
+  TData = Common.DagVersionServiceGetDagVersionsDefaultResponse,
+  TError = unknown,
+  TQueryKey extends Array<unknown> = unknown[],
+>(
+  {
+    bundleName,
+    bundleVersion,
+    dagId,
+    limit,
+    offset,
+    orderBy,
+    versionNumber,
+  }: {
+    bundleName?: string;
+    bundleVersion?: string;
+    dagId: string;
+    limit?: number;
+    offset?: number;
+    orderBy?: string;
+    versionNumber?: number;
+  },
+  queryKey?: TQueryKey,
+  options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
+) =>
+  useQuery<TData, TError>({
+    queryKey: Common.UseDagVersionServiceGetDagVersionsKeyFn(
+      { bundleName, bundleVersion, dagId, limit, offset, orderBy, 
versionNumber },
+      queryKey,
+    ),
+    queryFn: () =>
+      DagVersionService.getDagVersions({
+        bundleName,
+        bundleVersion,
+        dagId,
+        limit,
+        offset,
+        orderBy,
+        versionNumber,
+      }) as TData,
+    ...options,
+  });
 /**
  * Get Health
  * @returns HealthInfoResponse Successful Response
diff --git a/airflow/ui/openapi-gen/queries/suspense.ts 
b/airflow/ui/openapi-gen/queries/suspense.ts
index a7ea9ad976c..8b304aa8d6d 100644
--- a/airflow/ui/openapi-gen/queries/suspense.ts
+++ b/airflow/ui/openapi-gen/queries/suspense.ts
@@ -11,6 +11,7 @@ import {
   DagService,
   DagSourceService,
   DagStatsService,
+  DagVersionService,
   DagWarningService,
   DagsService,
   DashboardService,
@@ -2668,6 +2669,64 @@ export const useVariableServiceGetVariablesSuspense = <
     queryFn: () => VariableService.getVariables({ limit, offset, orderBy, 
variableKeyPattern }) as TData,
     ...options,
   });
+/**
+ * Get Dag Versions
+ * Get all DAG Versions.
+ *
+ * This endpoint allows specifying `~` as the dag_id to retrieve DAG Versions 
for all DAGs.
+ * @param data The data for the request.
+ * @param data.dagId
+ * @param data.limit
+ * @param data.offset
+ * @param data.versionNumber
+ * @param data.bundleName
+ * @param data.bundleVersion
+ * @param data.orderBy
+ * @returns DAGVersionCollectionResponse Successful Response
+ * @throws ApiError
+ */
+export const useDagVersionServiceGetDagVersionsSuspense = <
+  TData = Common.DagVersionServiceGetDagVersionsDefaultResponse,
+  TError = unknown,
+  TQueryKey extends Array<unknown> = unknown[],
+>(
+  {
+    bundleName,
+    bundleVersion,
+    dagId,
+    limit,
+    offset,
+    orderBy,
+    versionNumber,
+  }: {
+    bundleName?: string;
+    bundleVersion?: string;
+    dagId: string;
+    limit?: number;
+    offset?: number;
+    orderBy?: string;
+    versionNumber?: number;
+  },
+  queryKey?: TQueryKey,
+  options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
+) =>
+  useSuspenseQuery<TData, TError>({
+    queryKey: Common.UseDagVersionServiceGetDagVersionsKeyFn(
+      { bundleName, bundleVersion, dagId, limit, offset, orderBy, 
versionNumber },
+      queryKey,
+    ),
+    queryFn: () =>
+      DagVersionService.getDagVersions({
+        bundleName,
+        bundleVersion,
+        dagId,
+        limit,
+        offset,
+        orderBy,
+        versionNumber,
+      }) as TData,
+    ...options,
+  });
 /**
  * Get Health
  * @returns HealthInfoResponse Successful Response
diff --git a/airflow/ui/openapi-gen/requests/schemas.gen.ts 
b/airflow/ui/openapi-gen/requests/schemas.gen.ts
index f0d56a19552..bb1f1a998f0 100644
--- a/airflow/ui/openapi-gen/requests/schemas.gen.ts
+++ b/airflow/ui/openapi-gen/requests/schemas.gen.ts
@@ -2552,6 +2552,26 @@ export const $DAGTagCollectionResponse = {
   description: "DAG Tags Collection serializer for responses.",
 } as const;
 
+export const $DAGVersionCollectionResponse = {
+  properties: {
+    dag_versions: {
+      items: {
+        $ref: "#/components/schemas/DagVersionResponse",
+      },
+      type: "array",
+      title: "Dag Versions",
+    },
+    total_entries: {
+      type: "integer",
+      title: "Total Entries",
+    },
+  },
+  type: "object",
+  required: ["dag_versions", "total_entries"],
+  title: "DAGVersionCollectionResponse",
+  description: "DAG Version Collection serializer for responses.",
+} as const;
+
 export const $DAGWarningCollectionResponse = {
   properties: {
     dag_warnings: {
diff --git a/airflow/ui/openapi-gen/requests/services.gen.ts 
b/airflow/ui/openapi-gen/requests/services.gen.ts
index 2c257419845..995e95e2ea3 100644
--- a/airflow/ui/openapi-gen/requests/services.gen.ts
+++ b/airflow/ui/openapi-gen/requests/services.gen.ts
@@ -199,6 +199,8 @@ import type {
   BulkVariablesResponse,
   ReparseDagFileData,
   ReparseDagFileResponse,
+  GetDagVersionsData,
+  GetDagVersionsResponse,
   GetHealthResponse,
   GetVersionResponse,
   LoginData,
@@ -3333,6 +3335,48 @@ export class DagParsingService {
   }
 }
 
+export class DagVersionService {
+  /**
+   * Get Dag Versions
+   * Get all DAG Versions.
+   *
+   * This endpoint allows specifying `~` as the dag_id to retrieve DAG 
Versions for all DAGs.
+   * @param data The data for the request.
+   * @param data.dagId
+   * @param data.limit
+   * @param data.offset
+   * @param data.versionNumber
+   * @param data.bundleName
+   * @param data.bundleVersion
+   * @param data.orderBy
+   * @returns DAGVersionCollectionResponse Successful Response
+   * @throws ApiError
+   */
+  public static getDagVersions(data: GetDagVersionsData): 
CancelablePromise<GetDagVersionsResponse> {
+    return __request(OpenAPI, {
+      method: "GET",
+      url: "/public/dags/{dag_id}/dagVersions",
+      path: {
+        dag_id: data.dagId,
+      },
+      query: {
+        limit: data.limit,
+        offset: data.offset,
+        version_number: data.versionNumber,
+        bundle_name: data.bundleName,
+        bundle_version: data.bundleVersion,
+        order_by: data.orderBy,
+      },
+      errors: {
+        401: "Unauthorized",
+        403: "Forbidden",
+        404: "Not Found",
+        422: "Validation Error",
+      },
+    });
+  }
+}
+
 export class MonitorService {
   /**
    * Get Health
diff --git a/airflow/ui/openapi-gen/requests/types.gen.ts 
b/airflow/ui/openapi-gen/requests/types.gen.ts
index 18a66636820..54e74a7198d 100644
--- a/airflow/ui/openapi-gen/requests/types.gen.ts
+++ b/airflow/ui/openapi-gen/requests/types.gen.ts
@@ -653,6 +653,14 @@ export type DAGTagCollectionResponse = {
   total_entries: number;
 };
 
+/**
+ * DAG Version Collection serializer for responses.
+ */
+export type DAGVersionCollectionResponse = {
+  dag_versions: Array<DagVersionResponse>;
+  total_entries: number;
+};
+
 /**
  * DAG warning collection serializer for responses.
  */
@@ -2423,6 +2431,18 @@ export type ReparseDagFileData = {
 
 export type ReparseDagFileResponse = null;
 
+export type GetDagVersionsData = {
+  bundleName?: string;
+  bundleVersion?: string | null;
+  dagId: string;
+  limit?: number;
+  offset?: number;
+  orderBy?: string;
+  versionNumber?: number;
+};
+
+export type GetDagVersionsResponse = DAGVersionCollectionResponse;
+
 export type GetHealthResponse = HealthInfoResponse;
 
 export type GetVersionResponse = VersionInfo;
@@ -5077,6 +5097,33 @@ export type $OpenApiTs = {
       };
     };
   };
+  "/public/dags/{dag_id}/dagVersions": {
+    get: {
+      req: GetDagVersionsData;
+      res: {
+        /**
+         * Successful Response
+         */
+        200: DAGVersionCollectionResponse;
+        /**
+         * Unauthorized
+         */
+        401: HTTPExceptionResponse;
+        /**
+         * Forbidden
+         */
+        403: HTTPExceptionResponse;
+        /**
+         * Not Found
+         */
+        404: HTTPExceptionResponse;
+        /**
+         * Validation Error
+         */
+        422: HTTPValidationError;
+      };
+    };
+  };
   "/public/monitor/health": {
     get: {
       res: {
diff --git a/tests/api_fastapi/core_api/routes/public/test_dag_versions.py 
b/tests/api_fastapi/core_api/routes/public/test_dag_versions.py
new file mode 100644
index 00000000000..e24676feb24
--- /dev/null
+++ b/tests/api_fastapi/core_api/routes/public/test_dag_versions.py
@@ -0,0 +1,219 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from unittest import mock
+
+import pytest
+
+from airflow.models.serialized_dag import SerializedDagModel
+from airflow.providers.standard.operators.empty import EmptyOperator
+
+from tests_common.test_utils.db import clear_db_dags, clear_db_serialized_dags
+
+pytestmark = pytest.mark.db_test
+
+
+class TestDagVersionEndpoint:
+    @pytest.fixture(autouse=True)
+    def setup(request, dag_maker):
+        clear_db_dags()
+        clear_db_serialized_dags()
+
+        with dag_maker(
+            "ANOTHER_DAG_ID",
+        ) as dag:
+            EmptyOperator(task_id="task_1")
+            EmptyOperator(task_id="task_2")
+
+        dag.sync_to_db()
+        SerializedDagModel.write_dag(dag, bundle_name="another_bundle_name")
+
+
+class TestGetDagVersions(TestDagVersionEndpoint):
+    @pytest.mark.parametrize(
+        "dag_id, expected_response",
+        [
+            [
+                "~",
+                {
+                    "dag_versions": [
+                        {
+                            "bundle_name": "another_bundle_name",
+                            "bundle_version": None,
+                            "created_at": mock.ANY,
+                            "dag_id": "ANOTHER_DAG_ID",
+                            "id": mock.ANY,
+                            "version_number": 1,
+                        },
+                        {
+                            "bundle_name": "dag_maker",
+                            "bundle_version": None,
+                            "created_at": mock.ANY,
+                            "dag_id": "dag_with_multiple_versions",
+                            "id": mock.ANY,
+                            "version_number": 1,
+                        },
+                        {
+                            "bundle_name": "dag_maker",
+                            "bundle_version": None,
+                            "created_at": mock.ANY,
+                            "dag_id": "dag_with_multiple_versions",
+                            "id": mock.ANY,
+                            "version_number": 2,
+                        },
+                        {
+                            "bundle_name": "dag_maker",
+                            "bundle_version": None,
+                            "created_at": mock.ANY,
+                            "dag_id": "dag_with_multiple_versions",
+                            "id": mock.ANY,
+                            "version_number": 3,
+                        },
+                    ],
+                    "total_entries": 4,
+                },
+            ],
+            [
+                "dag_with_multiple_versions",
+                {
+                    "dag_versions": [
+                        {
+                            "bundle_name": "dag_maker",
+                            "bundle_version": None,
+                            "created_at": mock.ANY,
+                            "dag_id": "dag_with_multiple_versions",
+                            "id": mock.ANY,
+                            "version_number": 1,
+                        },
+                        {
+                            "bundle_name": "dag_maker",
+                            "bundle_version": None,
+                            "created_at": mock.ANY,
+                            "dag_id": "dag_with_multiple_versions",
+                            "id": mock.ANY,
+                            "version_number": 2,
+                        },
+                        {
+                            "bundle_name": "dag_maker",
+                            "bundle_version": None,
+                            "created_at": mock.ANY,
+                            "dag_id": "dag_with_multiple_versions",
+                            "id": mock.ANY,
+                            "version_number": 3,
+                        },
+                    ],
+                    "total_entries": 3,
+                },
+            ],
+        ],
+    )
+    @pytest.mark.usefixtures("make_dag_with_multiple_versions")
+    def test_get_dag_versions(self, test_client, dag_id, expected_response):
+        response = test_client.get(f"/public/dags/{dag_id}/dagVersions")
+        assert response.status_code == 200
+        assert response.json() == expected_response
+
+    @pytest.mark.parametrize(
+        "params, expected_versions, expected_total_entries",
+        [
+            [{"limit": 1}, [("ANOTHER_DAG_ID", 1)], 4],
+            [{"limit": 2}, [("ANOTHER_DAG_ID", 1), 
("dag_with_multiple_versions", 1)], 4],
+            [{"version_number": 1}, [("ANOTHER_DAG_ID", 1), 
("dag_with_multiple_versions", 1)], 2],
+            [{"version_number": 2}, [("dag_with_multiple_versions", 2)], 1],
+            [{"bundle_name": "another_bundle_name"}, [("ANOTHER_DAG_ID", 1)], 
1],
+            [
+                {"order_by": "version_number"},
+                [
+                    ("ANOTHER_DAG_ID", 1),
+                    ("dag_with_multiple_versions", 1),
+                    ("dag_with_multiple_versions", 2),
+                    ("dag_with_multiple_versions", 3),
+                ],
+                4,
+            ],
+            [
+                {"order_by": "-version_number"},
+                [
+                    ("dag_with_multiple_versions", 3),
+                    ("dag_with_multiple_versions", 2),
+                    ("dag_with_multiple_versions", 1),
+                    ("ANOTHER_DAG_ID", 1),
+                ],
+                4,
+            ],
+            [
+                {"order_by": "bundle_name"},
+                [
+                    ("ANOTHER_DAG_ID", 1),
+                    ("dag_with_multiple_versions", 1),
+                    ("dag_with_multiple_versions", 2),
+                    ("dag_with_multiple_versions", 3),
+                ],
+                4,
+            ],
+            [
+                {"order_by": "-bundle_name"},
+                [
+                    ("dag_with_multiple_versions", 3),
+                    ("dag_with_multiple_versions", 2),
+                    ("dag_with_multiple_versions", 1),
+                    ("ANOTHER_DAG_ID", 1),
+                ],
+                4,
+            ],
+            [
+                {"order_by": "bundle_version"},
+                [
+                    ("ANOTHER_DAG_ID", 1),
+                    ("dag_with_multiple_versions", 1),
+                    ("dag_with_multiple_versions", 2),
+                    ("dag_with_multiple_versions", 3),
+                ],
+                4,
+            ],
+            [
+                {"order_by": "-bundle_version"},
+                [
+                    ("dag_with_multiple_versions", 3),
+                    ("dag_with_multiple_versions", 2),
+                    ("dag_with_multiple_versions", 1),
+                    ("ANOTHER_DAG_ID", 1),
+                ],
+                4,
+            ],
+        ],
+    )
+    @pytest.mark.usefixtures("make_dag_with_multiple_versions")
+    def test_get_dag_versions_parameters(
+        self, test_client, params, expected_versions, expected_total_entries
+    ):
+        response = test_client.get("/public/dags/~/dagVersions", params=params)
+        assert response.status_code == 200
+        response_payload = response.json()
+        assert response_payload["total_entries"] == expected_total_entries
+        assert [
+            (dag_version["dag_id"], dag_version["version_number"])
+            for dag_version in response_payload["dag_versions"]
+        ] == expected_versions
+
+    def test_get_dag_versions_should_return_404_for_missing_dag(self, 
test_client):
+        response = test_client.get("/public/dags/MISSING_ID/dagVersions")
+        assert response.status_code == 404
+        assert response.json() == {
+            "detail": "The DAG with dag_id: `MISSING_ID` was not found",
+        }

Reply via email to