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

ash 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 34d2dd8853 Add more fields to REST API dags/dag_id/details endpoint 
(#22756)
34d2dd8853 is described below

commit 34d2dd8853849d00de2e856b1f79cffe4da6d990
Author: Ephraim Anierobi <[email protected]>
AuthorDate: Fri Apr 8 12:58:47 2022 +0100

    Add more fields to REST API dags/dag_id/details endpoint (#22756)
    
    Added more fields to the DAG details endpoint, which is the endpoint for
    getting DAG `object` details
---
 airflow/api_connexion/openapi/v1.yaml              | 42 ++++++++++++++++++++++
 airflow/api_connexion/schemas/dag_schema.py        |  5 +++
 tests/api_connexion/endpoints/test_dag_endpoint.py | 24 +++++++++++++
 tests/api_connexion/schemas/test_dag_schema.py     |  8 ++++-
 4 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/airflow/api_connexion/openapi/v1.yaml 
b/airflow/api_connexion/openapi/v1.yaml
index 909562fc99..a0c3150be1 100644
--- a/airflow/api_connexion/openapi/v1.yaml
+++ b/airflow/api_connexion/openapi/v1.yaml
@@ -2912,7 +2912,49 @@ components:
                 User-specified DAG params.
 
                 *New in version 2.0.1*
+            end_date:
+              type: string
+              format: 'date-time'
+              readOnly: true
+              nullable: true
+              description: |
+                The DAG's end date.
+
+                *New in version 2.3.0*.
+            is_paused_upon_creation:
+              type: boolean
+              readOnly: true
+              nullable: true
+              description: |
+                Whether the DAG is paused upon creation.
+
+                *New in version 2.3.0*
+            last_parsed:
+              type: string
+              format: date-time
+              nullable: true
+              readOnly: true
+              description: |
+                The last time the DAG was parsed.
+
+                *New in version 2.3.0*
+            template_search_path:
+              type: array
+              nullable: true
+              items:
+                type: string
+              description: |
+                The template search path.
+
+                *New in version 2.3.0*
+            render_template_as_native_obj:
+              type: boolean
+              nullable: true
+              readOnly: true
+              description: |
+                Whether to render templates as native Python objects.
 
+                *New in version 2.3.0*
     ExtraLink:
       type: object
       description: Additional links containing additional information about 
the task.
diff --git a/airflow/api_connexion/schemas/dag_schema.py 
b/airflow/api_connexion/schemas/dag_schema.py
index 373e0ff54f..2f36911329 100644
--- a/airflow/api_connexion/schemas/dag_schema.py
+++ b/airflow/api_connexion/schemas/dag_schema.py
@@ -104,6 +104,11 @@ class DAGDetailSchema(DAGSchema):
     tags = fields.Method("get_tags", dump_only=True)  # type: ignore
     is_paused = fields.Method("get_is_paused", dump_only=True)
     is_active = fields.Method("get_is_active", dump_only=True)
+    is_paused_upon_creation = fields.Boolean()
+    end_date = fields.DateTime(dump_only=True)
+    template_search_path = fields.String(dump_only=True)
+    render_template_as_native_obj = fields.Boolean(dump_only=True)
+    last_loaded = fields.DateTime(dump_only=True, data_key='last_parsed')
 
     @staticmethod
     def get_concurrency(obj: DAG):
diff --git a/tests/api_connexion/endpoints/test_dag_endpoint.py 
b/tests/api_connexion/endpoints/test_dag_endpoint.py
index 41bbb4ca7b..f1dc5494d3 100644
--- a/tests/api_connexion/endpoints/test_dag_endpoint.py
+++ b/tests/api_connexion/endpoints/test_dag_endpoint.py
@@ -251,6 +251,7 @@ class TestGetDagDetails(TestDagEndpoint):
             f"/api/v1/dags/{self.dag_id}/details", 
environ_overrides={'REMOTE_USER': "test"}
         )
         assert response.status_code == 200
+        last_parsed = response.json["last_parsed"]
         expected = {
             "catchup": True,
             "concurrency": 16,
@@ -286,6 +287,10 @@ class TestGetDagDetails(TestDagEndpoint):
             "timezone": "Timezone('UTC')",
             "max_active_runs": 16,
             "pickle_id": None,
+            "end_date": None,
+            'is_paused_upon_creation': None,
+            'last_parsed': last_parsed,
+            'render_template_as_native_obj': False,
         }
         assert response.json == expected
 
@@ -294,6 +299,7 @@ class TestGetDagDetails(TestDagEndpoint):
             f"/api/v1/dags/{self.dag2_id}/details", 
environ_overrides={'REMOTE_USER': "test"}
         )
         assert response.status_code == 200
+        last_parsed = response.json["last_parsed"]
         expected = {
             "catchup": True,
             "concurrency": 16,
@@ -322,6 +328,10 @@ class TestGetDagDetails(TestDagEndpoint):
             "timezone": "Timezone('UTC')",
             "max_active_runs": 16,
             "pickle_id": None,
+            "end_date": None,
+            'is_paused_upon_creation': None,
+            'last_parsed': last_parsed,
+            'render_template_as_native_obj': False,
         }
         assert response.json == expected
 
@@ -330,6 +340,7 @@ class TestGetDagDetails(TestDagEndpoint):
             f"/api/v1/dags/{self.dag3_id}/details", 
environ_overrides={'REMOTE_USER': "test"}
         )
         assert response.status_code == 200
+        last_parsed = response.json["last_parsed"]
         expected = {
             "catchup": True,
             "concurrency": 16,
@@ -358,6 +369,10 @@ class TestGetDagDetails(TestDagEndpoint):
             "timezone": "Timezone('UTC')",
             "max_active_runs": 16,
             "pickle_id": None,
+            "end_date": None,
+            'is_paused_upon_creation': None,
+            'last_parsed': last_parsed,
+            'render_template_as_native_obj': False,
         }
         assert response.json == expected
 
@@ -405,12 +420,17 @@ class TestGetDagDetails(TestDagEndpoint):
             "timezone": "Timezone('UTC')",
             "max_active_runs": 16,
             "pickle_id": None,
+            "end_date": None,
+            'is_paused_upon_creation': None,
+            'render_template_as_native_obj': False,
         }
         response = self.client.get(
             f"/api/v1/dags/{self.dag_id}/details", 
environ_overrides={'REMOTE_USER': "test"}
         )
 
         assert response.status_code == 200
+        expected.update({'last_parsed': response.json['last_parsed']})
+
         assert response.json == expected
 
         patcher.stop()
@@ -449,7 +469,11 @@ class TestGetDagDetails(TestDagEndpoint):
             'timezone': "Timezone('UTC')",
             "max_active_runs": 16,
             "pickle_id": None,
+            "end_date": None,
+            'is_paused_upon_creation': None,
+            'render_template_as_native_obj': False,
         }
+        expected.update({'last_parsed': response.json['last_parsed']})
         assert response.json == expected
 
     def test_should_raises_401_unauthenticated(self):
diff --git a/tests/api_connexion/schemas/test_dag_schema.py 
b/tests/api_connexion/schemas/test_dag_schema.py
index 6161b21476..ca7e04ae89 100644
--- a/tests/api_connexion/schemas/test_dag_schema.py
+++ b/tests/api_connexion/schemas/test_dag_schema.py
@@ -160,6 +160,7 @@ class TestDAGDetailSchema:
             tags=['example1', 'example2'],
         )
         schema = DAGDetailSchema()
+
         expected = {
             'catchup': True,
             'concurrency': 16,
@@ -190,5 +191,10 @@ class TestDAGDetailSchema:
             'timezone': "Timezone('UTC')",
             'max_active_runs': 16,
             'pickle_id': None,
+            "end_date": None,
+            'is_paused_upon_creation': None,
+            'render_template_as_native_obj': False,
         }
-        assert schema.dump(dag) == expected
+        obj = schema.dump(dag)
+        expected.update({'last_parsed': obj['last_parsed']})
+        assert obj == expected

Reply via email to