diff --git a/aws_doc_sdk_examples_tools/metadata_test.py b/aws_doc_sdk_examples_tools/metadata_test.py index 849a9d4..dd70219 100644 --- a/aws_doc_sdk_examples_tools/metadata_test.py +++ b/aws_doc_sdk_examples_tools/metadata_test.py @@ -22,7 +22,7 @@ ) from aws_doc_sdk_examples_tools.doc_gen import DocGen from aws_doc_sdk_examples_tools.sdks import Sdk -from aws_doc_sdk_examples_tools.services import Service +from aws_doc_sdk_examples_tools.services import Service, ServiceExpanded def load( @@ -38,41 +38,44 @@ def load( SERVICES = { "ses": Service( long="&SESlong;", - expanded_long="Amazon Simple Email Service (Amazon SES)", short="&SES;", - expanded_short="Amazon SES", + expanded=ServiceExpanded( + long="Amazon Simple Email Service (Amazon SES)", short="Amazon SES" + ), sort="ses", version=1, ), "sns": Service( long="&SNSlong;", - expanded_long="Amazon Simple Notification Service (Amazon SNS)", short="&SNS;", - expanded_short="Amazon SNS", + expanded=ServiceExpanded( + long="Amazon Simple Notification Service (Amazon SNS)", short="Amazon SNS" + ), sort="sns", version=1, ), "sqs": Service( long="&SQSlong;", - expanded_long="Amazon Simple Queue Service (Amazon SQS)", short="&SQS;", - expanded_short="Amazon SQS", + expanded=ServiceExpanded( + long="Amazon Simple Queue Service (Amazon SQS)", short="Amazon SQS" + ), sort="sqs", version=1, ), "s3": Service( long="&S3long;", - expanded_long="Amazon Simple Storage Service (Amazon S3)", short="&S3;", - expanded_short="Amazon S3", + expanded=ServiceExpanded( + long="Amazon Simple Storage Service (Amazon S3)", short="Amazon S3" + ), sort="s3", version=1, ), "autogluon": Service( long="AutoGluon Test", - expanded_long="AutoGluon Test", short="AG Test", - expanded_short="AutoGluon Test", + expanded=ServiceExpanded(long="AutoGluon Test", short="AutoGluon Test"), sort="autogluon", version=1, ), @@ -447,7 +450,7 @@ def test_common_errors( assert expected_errors == [*actual] -TEST_SERVICES = {"test": Service("test", "test", "test", "test", "test", "1")} +TEST_SERVICES = {"test": Service("test", "test", "test", "1")} def test_idFormat(): diff --git a/aws_doc_sdk_examples_tools/services.py b/aws_doc_sdk_examples_tools/services.py index 7d3247e..d82d460 100644 --- a/aws_doc_sdk_examples_tools/services.py +++ b/aws_doc_sdk_examples_tools/services.py @@ -9,6 +9,12 @@ from aws_doc_sdk_examples_tools.metadata_errors import MetadataErrors, check_mapping +@dataclass +class ServiceExpanded: + long: str + short: str + + @dataclass class ServiceGuide: subtitle: str @@ -18,11 +24,10 @@ class ServiceGuide: @dataclass class Service: long: str - expanded_long: str short: str - expanded_short: str sort: str version: Union[int, str] + expanded: Optional[ServiceExpanded] = field(default=None) api_ref: Optional[str] = field(default=None) blurb: Optional[str] = field(default=None) bundle: Optional[str] = field(default=None) @@ -37,9 +42,8 @@ def from_yaml( errors = MetadataErrors() long = check_mapping(yaml.get("long"), "long") - expanded_long = yaml.get("expanded", {}).get("long") + expanded = yaml.get("expanded") short = check_mapping(yaml.get("short"), "short") - expanded_short = yaml.get("expanded", {}).get("short") sort = yaml.get("sort") version = yaml.get("version") @@ -49,12 +53,16 @@ def from_yaml( if isinstance(short, metadata_errors.MetadataParseError): errors.append(short) short = "" - if expanded_long is None: - errors.append(metadata_errors.MissingField(field="expanded_long")) - expanded_long = "" - if expanded_short is None: - errors.append(metadata_errors.MissingField(field="expanded_short")) - expanded_short = "" + if expanded is None: + errors.append(metadata_errors.MissingField(field="expanded")) + else: + long_expanded = expanded.get("long") + short_expanded = expanded.get("short") + if not long_expanded: + errors.append(metadata_errors.MissingField(field="expanded.long")) + if not short_expanded: + errors.append(metadata_errors.MissingField(field="expanded.short")) + expanded = ServiceExpanded(long=long_expanded, short=short_expanded) if sort is None: errors.append(metadata_errors.MissingField(field="sort")) sort = "" @@ -87,9 +95,8 @@ def from_yaml( return ( cls( long=long, - expanded_long=expanded_long, short=short, - expanded_short=expanded_short, + expanded=expanded, sort=sort, api_ref=api_ref, blurb=blurb, diff --git a/aws_doc_sdk_examples_tools/services_test.py b/aws_doc_sdk_examples_tools/services_test.py index b864861..47f7173 100644 --- a/aws_doc_sdk_examples_tools/services_test.py +++ b/aws_doc_sdk_examples_tools/services_test.py @@ -7,7 +7,12 @@ import yaml from aws_doc_sdk_examples_tools import metadata_errors -from aws_doc_sdk_examples_tools.services import parse, Service, ServiceGuide +from aws_doc_sdk_examples_tools.services import ( + parse, + Service, + ServiceGuide, + ServiceExpanded, +) def load(path: str) -> Tuple[Dict[str, Service], metadata_errors.MetadataErrors]: @@ -47,9 +52,10 @@ def test_services(): assert examples == { "s3": Service( short="&S3;", - expanded_short="Amazon S3", + expanded=ServiceExpanded( + long="Amazon Simple Storage Service (Amazon S3)", short="Amazon S3" + ), long="&S3long;", - expanded_long="Amazon Simple Storage Service (Amazon S3)", sort="S3", version="s3-2006-03-01", caveat="The examples in this section are pretty neat, and we recommend you print them out so you can read them in bed with a good glass of wine.", @@ -62,18 +68,21 @@ def test_services(): ), "sns": Service( short="&SNS;", - expanded_short="Amazon SNS", long="&SNSlong;", - expanded_long="Amazon Simple Notification Service (Amazon SNS)", + expanded=ServiceExpanded( + long="Amazon Simple Notification Service (Amazon SNS)", + short="Amazon SNS", + ), sort="SNS", version="sns-2010-03-31", bundle="sqs", ), "sqs": Service( short="&SQS;", - expanded_short="Amazon SQS", long="&SQSlong;", - expanded_long="Amazon Simple Queue Service (Amazon SQS)", + expanded=ServiceExpanded( + long="Amazon Simple Queue Service (Amazon SQS)", short="Amazon SQS" + ), sort="SQS", tags={ "product_categories": set(["Category 1", "Category 2"]), @@ -83,9 +92,8 @@ def test_services(): ), "textract": Service( short="&TEXTRACT;", - expanded_short="Amazon Textract", long="&TEXTRACTlong;", - expanded_long="Amazon Textract", + expanded=ServiceExpanded(long="Amazon Textract", short="Amazon Textract"), sort="Textract", tags={"product_categories": set(["Category 1"])}, version="textract-2018-06-27",