Skip to content

Commit

Permalink
[yaml] Normalize error_handling docs on API catalog
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Kinard <[email protected]>
  • Loading branch information
Polber committed Nov 8, 2024
1 parent c7e4db7 commit a797dc2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions sdks/python/apache_beam/yaml/generate_yaml_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
import itertools
import re

import docstring_parser
import yaml

from apache_beam.portability.api import schema_pb2
from apache_beam.typehints import schemas
from apache_beam.utils import subprocess_server
from apache_beam.utils.python_callable import PythonCallableWithSource
from apache_beam.version import __version__ as beam_version
from apache_beam.yaml import json_utils
from apache_beam.yaml import yaml_provider
from apache_beam.yaml.yaml_mapping import ErrorHandlingConfig


def _singular(name):
Expand Down Expand Up @@ -135,8 +139,28 @@ def maybe_row_parameters(t):
def maybe_optional(t):
return " (Optional)" if t.nullable else ""

def normalize_error_handling(f):
doc = docstring_parser.parse(
ErrorHandlingConfig.__doc__, docstring_parser.DocstringStyle.GOOGLE)
if f.name == "error_handling":
f = schema_pb2.Field(
name="error_handling",
type=schema_pb2.FieldType(
row_type=schema_pb2.RowType(
schema=schema_pb2.Schema(
fields=[
schemas.schema_field(
param.arg_name,
PythonCallableWithSource.load_from_expression(
param.type_name),
param.description) for param in doc.params
]))),
description=f.description)
return f

def lines():
for f in schema.fields:
f = normalize_error_handling(f)
yield ''.join([
f'**{f.name}** `{pretty_type(f.type)}`',
maybe_optional(f.type),
Expand Down
5 changes: 5 additions & 0 deletions sdks/python/apache_beam/yaml/yaml_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@ def checking_func(row):


class ErrorHandlingConfig(NamedTuple):
"""Class to define Error Handling parameters.
Args:
output (str): Name to use for the output error collection
"""
output: str
# TODO: Other parameters are valid here too, but not common to Java.

Expand Down

0 comments on commit a797dc2

Please sign in to comment.