| 1 |
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 |
# may not use this file except in compliance with the License. A copy of |
| 5 |
# the License is located at |
| 6 |
# |
| 7 |
# https://aws.amazon.com/apache2.0/ |
| 8 |
# |
| 9 |
# or in the "license" file accompanying this file. This file is |
| 10 |
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 |
# ANY KIND, either express or implied. See the License for the specific |
| 12 |
# language governing permissions and limitations under the License. |
| 13 |
from botocore.docs.params import ResponseParamsDocumenter |
| 14 |
|
| 15 |
from boto3.docs.utils import get_identifier_description |
| 16 |
|
| 17 |
|
| 18 |
class ResourceShapeDocumenter(ResponseParamsDocumenter): |
| 19 |
EVENT_NAME = 'resource-shape' |
| 20 |
|
| 21 |
|
| 22 |
def document_attribute( |
| 23 |
section, |
| 24 |
service_name, |
| 25 |
resource_name, |
| 26 |
attr_name, |
| 27 |
event_emitter, |
| 28 |
attr_model, |
| 29 |
include_signature=True, |
| 30 |
): |
| 31 |
if include_signature: |
| 32 |
full_attr_name = f"{section.context.get('qualifier', '')}{attr_name}" |
| 33 |
section.style.start_sphinx_py_attr(full_attr_name) |
| 34 |
# Note that an attribute may have one, may have many, or may have no |
| 35 |
# operations that back the resource's shape. So we just set the |
| 36 |
# operation_name to the resource name if we ever to hook in and modify |
| 37 |
# a particular attribute. |
| 38 |
ResourceShapeDocumenter( |
| 39 |
service_name=service_name, |
| 40 |
operation_name=resource_name, |
| 41 |
event_emitter=event_emitter, |
| 42 |
).document_params(section=section, shape=attr_model) |
| 43 |
|
| 44 |
|
| 45 |
def document_identifier( |
| 46 |
section, |
| 47 |
resource_name, |
| 48 |
identifier_model, |
| 49 |
include_signature=True, |
| 50 |
): |
| 51 |
if include_signature: |
| 52 |
full_identifier_name = ( |
| 53 |
f"{section.context.get('qualifier', '')}{identifier_model.name}" |
| 54 |
) |
| 55 |
section.style.start_sphinx_py_attr(full_identifier_name) |
| 56 |
description = get_identifier_description( |
| 57 |
resource_name, identifier_model.name |
| 58 |
) |
| 59 |
section.write(f'*(string)* {description}') |
| 60 |
|
| 61 |
|
| 62 |
def document_reference(section, reference_model, include_signature=True): |
| 63 |
if include_signature: |
| 64 |
full_reference_name = ( |
| 65 |
f"{section.context.get('qualifier', '')}{reference_model.name}" |
| 66 |
) |
| 67 |
section.style.start_sphinx_py_attr(full_reference_name) |
| 68 |
reference_type = f'(:py:class:`{reference_model.resource.type}`) ' |
| 69 |
section.write(reference_type) |
| 70 |
section.include_doc_string( |
| 71 |
f'The related {reference_model.name} if set, otherwise ``None``.' |
| 72 |
) |