MCPcopy Create free account
hub / github.com/aws/aws-cli / OperationDocumentEventHandler

Class OperationDocumentEventHandler

awscli/clidocs.py:491–702  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

489
490
491class OperationDocumentEventHandler(CLIDocumentEventHandler):
492 AWS_DOC_BASE = 'https://docs.aws.amazon.com/goto/WebAPI'
493
494 def doc_description(self, help_command, **kwargs):
495 doc = help_command.doc
496 operation_model = help_command.obj
497 doc.style.h2('Description')
498 doc.include_doc_string(operation_model.documentation)
499 self._add_webapi_crosslink(help_command)
500 self._add_note_for_document_types_if_used(help_command)
501
502 def _add_webapi_crosslink(self, help_command):
503 doc = help_command.doc
504 operation_model = help_command.obj
505 service_model = operation_model.service_model
506 service_uid = service_model.metadata.get('uid')
507 if service_uid is None:
508 # If there's no service_uid in the model, we can't
509 # be certain if the generated cross link will work
510 # so we don't generate any crosslink info.
511 return
512 doc.style.new_paragraph()
513 doc.write("See also: ")
514 link = f'{self.AWS_DOC_BASE}/{service_uid}/{operation_model.name}'
515 doc.style.external_link(title="AWS API Documentation", link=link)
516 doc.writeln('')
517
518 def _add_note_for_document_types_if_used(self, help_command):
519 if operation_uses_document_types(help_command.obj):
520 help_command.doc.style.new_paragraph()
521 help_command.doc.writeln(
522 f'``{help_command.name}`` uses document type values. Document types follow the '
523 'JSON data model where valid values are: strings, numbers, '
524 'booleans, null, arrays, and objects. For command input, '
525 'options and nested parameters that are labeled with the type '
526 '``document`` must be provided as JSON. Shorthand syntax does '
527 'not support document types.'
528 )
529
530 def _json_example_value_name(
531 self, argument_model, include_enum_values=True
532 ):
533 # If include_enum_values is True, then the valid enum values
534 # are included as the sample JSON value.
535 if isinstance(argument_model, StringShape):
536 if argument_model.enum and include_enum_values:
537 choices = argument_model.enum
538 return '|'.join([f'"{c}"' for c in choices])
539 else:
540 return '"string"'
541 elif argument_model.type_name == 'boolean':
542 return 'true|false'
543 else:
544 return f'{argument_model.type_name}'
545
546 def _json_example(self, doc, argument_model, stack):
547 if argument_model.name in stack:
548 # Document the recursion once, otherwise just

Calls

no outgoing calls