uranusjr commented on code in PR #74084:
URL: https://github.com/apache/airflow/pull/74084#discussion_r4203521227


##########
task-sdk/src/airflow/sdk/importers/yaml_importer/schema.json:
##########
@@ -0,0 +1,306 @@
+{
+  "$defs": {
+    "CodeTask": {
+      "additionalProperties": true,
+      "description": "A task running custom code.\n\nThis should have ``run`` 
holding function arguments, and optionally\n``queue`` to route it.",
+      "properties": {
+        "id": {
+          "title": "Id",
+          "type": "string"
+        },
+        "needs": {
+          "items": {
+            "type": "string"
+          },
+          "title": "Needs",
+          "type": "array"
+        },
+        "extends": {
+          "items": {
+            "type": "string"
+          },
+          "title": "Extends",
+          "type": "array"
+        },
+        "with": {
+          "additionalProperties": {
+            "oneOf": [
+              {
+                "$ref": "#/$defs/XComRef"
+              },
+              {
+                "$ref": "#/$defs/TemplateRef"
+              },
+              {
+                "$ref": "#/$defs/ConstRef"
+              },
+              {
+                "$ref": "#/$defs/_Literal"
+              }
+            ]
+          },
+          "title": "With",
+          "type": "object"
+        },
+        "run": {
+          "additionalProperties": {
+            "oneOf": [
+              {
+                "$ref": "#/$defs/XComRef"
+              },
+              {
+                "$ref": "#/$defs/TemplateRef"
+              },
+              {
+                "$ref": "#/$defs/ConstRef"
+              },
+              {
+                "$ref": "#/$defs/_Literal"
+              }
+            ]
+          },
+          "title": "Run",
+          "type": "object"
+        }
+      },
+      "required": [
+        "id"
+      ],
+      "title": "CodeTask",
+      "type": "object"
+    },
+    "ConstRef": {
+      "additionalProperties": false,
+      "description": "Force a literal; the value is taken verbatim.",
+      "properties": {
+        "$const": {
+          "title": "$Const"
+        }
+      },
+      "required": [
+        "$const"
+      ],
+      "title": "ConstRef",
+      "type": "object"
+    },
+    "OperatorTask": {
+      "additionalProperties": true,
+      "description": "A ready-made operator.\n\nThis should have ``uses`` 
(import path) + ``with``.",
+      "properties": {
+        "id": {
+          "title": "Id",
+          "type": "string"
+        },
+        "needs": {
+          "items": {
+            "type": "string"
+          },
+          "title": "Needs",
+          "type": "array"
+        },
+        "extends": {
+          "items": {
+            "type": "string"
+          },
+          "title": "Extends",
+          "type": "array"
+        },
+        "with": {
+          "additionalProperties": {
+            "oneOf": [
+              {
+                "$ref": "#/$defs/XComRef"
+              },
+              {
+                "$ref": "#/$defs/TemplateRef"
+              },
+              {
+                "$ref": "#/$defs/ConstRef"
+              },
+              {
+                "$ref": "#/$defs/_Literal"
+              }
+            ]
+          },
+          "title": "With",
+          "type": "object"
+        },
+        "uses": {
+          "title": "Uses",
+          "type": "string"
+        }
+      },
+      "required": [
+        "id",
+        "uses"
+      ],
+      "title": "OperatorTask",
+      "type": "object"
+    },
+    "TaskTemplate": {
+      "additionalProperties": true,
+      "description": "A reusable, partial task fragment merged into any task 
that ``extends`` it.\n\nThis holds arbitrary keys as-is. All validation is done 
on the merged task.",

Review Comment:
   I decided to use `json_schema_extra` to be able to keep using rst in 
docstring but set a different string in the generated schema.



##########
task-sdk/src/airflow/sdk/importers/yaml_importer/parser.py:
##########
@@ -0,0 +1,72 @@
+# 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.
+"""
+Parse a YAML/JSON DAG file into validated :class:`~.models.DagDocument` 
objects.
+
+The pydantic models (`.models`) are the schema; this module is the thin I/O + 
versioning
+layer around them: it lazily streams each document of a multi-document 
YAML/JSON stream (a string or a
+readable file object),
+resolves its `$schema` version against the Cadwyn bundle (migrating an 
older-pinned document
+up to head), validates it, and turns pydantic/YAML failures into a readable
+:class:`YamlDagParseError` at the offending document. Parsing is lazy, so 
errors surface as
+the iterator is consumed. It is pure (yaml + pydantic + cadwyn; no `airflow` 
import), so it is
+unit-testable without a runtime.

Review Comment:
   Removed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to