Skip to content

Commit 40e12d7

Browse files
authored
Added author and owner fields at the example version level. (#152)
1 parent d17e3f4 commit 40e12d7

File tree

5 files changed

+118
-0
lines changed

5 files changed

+118
-0
lines changed

aws_doc_sdk_examples_tools/metadata.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ class Url:
2727
url: Optional[str]
2828

2929

30+
@dataclass
31+
class Person:
32+
name: str
33+
alias: str
34+
35+
36+
@dataclass
37+
class FeedbackCti:
38+
category: str
39+
type: str
40+
item: str
41+
42+
3043
@dataclass
3144
class Excerpt:
3245
description: Optional[str]
@@ -59,6 +72,10 @@ class Version:
5972
sdkguide: Optional[str] = field(default=None)
6073
# Link to additional topic places.
6174
more_info: List[Url] = field(default_factory=list)
75+
# List of people who have contributed to this example.
76+
authors: List[Person] = field(default_factory=list)
77+
# Feedback and maintenance owner. Primarily for internal use.
78+
owner: Optional[FeedbackCti] = field(default=None)
6279

6380
def validate(self, errors: MetadataErrors, root: Path):
6481
github = self.github

aws_doc_sdk_examples_tools/metadata_errors.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ def message(self):
241241
return "lists version which is not listed in sdks.yaml."
242242

243243

244+
@dataclass
245+
class InvalidFeedbackCti(SdkVersionError):
246+
feedback_cti: str = ""
247+
248+
def message(self):
249+
return (
250+
f"has feedback CTI that is missing at least one field: {self.feedback_cti}"
251+
)
252+
253+
244254
@dataclass
245255
class InvalidGithubLink(SdkVersionError):
246256
link: str = ""
@@ -370,6 +380,15 @@ def message(self):
370380
return f"URL {self.url} is missing a title"
371381

372382

383+
@dataclass
384+
class PersonMissingField(SdkVersionError):
385+
name: str = ""
386+
alias: str = ""
387+
388+
def message(self):
389+
return f"person is missing a field: name: {self.name}, alias: {self.alias}"
390+
391+
373392
@dataclass
374393
class MissingCategoryBody(MetadataParseError):
375394
def message(self):

aws_doc_sdk_examples_tools/metadata_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,21 @@ def test_verify_load_successful():
741741
file=ERRORS_METADATA_PATH,
742742
id="medical-imagingBadFormat",
743743
),
744+
metadata_errors.PersonMissingField(
745+
file=ERRORS_METADATA_PATH,
746+
id="sqs_InvalidOwner",
747+
language="Java",
748+
sdk_version=2,
749+
name="None",
750+
751+
),
752+
metadata_errors.InvalidFeedbackCti(
753+
file=ERRORS_METADATA_PATH,
754+
id="sqs_InvalidOwner",
755+
language="Java",
756+
sdk_version=2,
757+
feedback_cti="AWS|Documentation|None",
758+
),
744759
],
745760
[
746761
metadata_errors.MissingGithubLink(

aws_doc_sdk_examples_tools/test_resources/errors_metadata.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,22 @@ medical-imagingBadFormat:
9696
- sdk_version: 2
9797
services:
9898
medical-imaging: { TestAction }
99+
sqs_InvalidOwner:
100+
title: Invalid owner
101+
title_abbrev: Invalid owner abbrev
102+
synopsis: This synopsis is just fine.
103+
category: Test
104+
languages:
105+
Java:
106+
versions:
107+
- sdk_version: 2
108+
authors:
109+
110+
owner:
111+
category: AWS
112+
type: Documentation
113+
excerpts:
114+
- snippet_tags:
115+
- invalid.feedback.cti
116+
services:
117+
sqs:

aws_doc_sdk_examples_tools/yaml_mapper.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
Url,
1010
Version,
1111
Excerpt,
12+
Person,
13+
FeedbackCti,
1214
)
1315
from .sdks import Sdk
1416
from .services import Service
@@ -204,6 +206,37 @@ def url_from_yaml(
204206
return Url(title, url)
205207

206208

209+
def person_from_yaml(
210+
yaml: Union[None, Dict[str, Optional[str]]]
211+
) -> Optional[Union[Person, MetadataParseError]]:
212+
if yaml is None:
213+
return None
214+
name = yaml.get("name")
215+
alias = yaml.get("alias")
216+
217+
if name is None or alias is None:
218+
return metadata_errors.PersonMissingField(name=str(name), alias=str(alias))
219+
220+
return Person(name, alias)
221+
222+
223+
def feedback_cti_from_yaml(
224+
yaml: Union[None, Dict[str, Optional[str]]]
225+
) -> Optional[Union[FeedbackCti, MetadataParseError]]:
226+
if yaml is None:
227+
return None
228+
category = yaml.get("category")
229+
type = yaml.get("type")
230+
item = yaml.get("item")
231+
232+
if category is None or type is None or item is None:
233+
return metadata_errors.InvalidFeedbackCti(
234+
feedback_cti="|".join([str(category), str(type), str(item)])
235+
)
236+
237+
return FeedbackCti(category, type, item)
238+
239+
207240
def version_from_yaml(
208241
yaml: Dict[str, Any],
209242
cross_content_blocks: Set[str],
@@ -243,6 +276,19 @@ def version_from_yaml(
243276
elif url is not None:
244277
errors.append(url)
245278

279+
authors: List[Person] = []
280+
for author in yaml.get("authors", []):
281+
author = person_from_yaml(author)
282+
if isinstance(author, Person):
283+
authors.append(author)
284+
elif author is not None:
285+
errors.append(author)
286+
287+
owner = feedback_cti_from_yaml(yaml.get("owner"))
288+
if owner is not None and not isinstance(owner, FeedbackCti):
289+
errors.append(owner)
290+
owner = None
291+
246292
add_services = parse_services(yaml.get("add_services", {}), errors)
247293
if add_services:
248294
errors.append(
@@ -264,6 +310,8 @@ def version_from_yaml(
264310
github,
265311
sdkguide,
266312
more_info,
313+
authors,
314+
owner,
267315
),
268316
errors,
269317
)

0 commit comments

Comments
 (0)