
                             S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SS	K
Jr  SS
K
Jr   " S S\R                  5      rg)zJA command that generates YAML export schemas for a message in a given API.    )absolute_import)division)unicode_literals)base)
exceptions)flags)	arg_utils)export)registryc                   .    \ rS rSrSr\S 5       rS rSrg)GenerateExportSchemas   a  Generate YAML export schemas for a message in a given API.

*gcloud* commands that have "too many" *create*/*update* command flags may
also provide *export*/*import* commands. *export* lists the current state
of a resource in a YAML *export* format. *import* reads export format data
and either creates a new resource or updates an existing resource.

An export format is an abstract YAML representation of the mutable fields of a
populated protobuf message. Abstraction allows the export format to hide
implementation details of some protobuf constructs like enums and
`additionalProperties`.

One way of describing an export format is with JSON schemas. A schema
documents export format properties for a message in an API, and can also be
used to validate data on import. Validation is important because users can
modify export data before importing it again.

This command generates [JSON schemas](json-schema.org) (in YAML format, go
figure) for a protobuf message in an API. A separate schema files is
generated for each nested message in the resource message.

## CAVEATS

The generated schemas depend on the quality of the protobuf discovery
docs, including proto file comment conventions that are not error checked.
Always manually inspect schemas before using them in a release.

## EXAMPLES

To generate the WorkflowTemplate schemas in the current directory from the
dataproc v1 API:

  $ {command} WorkflowTemplate --api=dataproc --api-version=v1
c                     [         R                  R                  U 5        [         R                  R                  U 5        U R	                  SSS9  U R	                  SSS9  g )Nmessagez@The name of the message to generate the YAML export schemas for.)helpz--directoryzThe path name of the directory to create the YAML export schema files in. If not specified then the files are created in the current directory.)r   API_REQUIRED_FLAGAddToParserAPI_VERSION_FLAGadd_argument)parsers    9lib/surface/meta/apis/messages/generate_export_schemas.pyArgsGenerateExportSchemas.ArgsB   sa    	''/	&&v.
O  Q '  )    c           	         [         R                  " UR                  UR                  S9n [	        UR                  5       UR                  5      n[        R                  " U5      n[        R                  " X!R                  XAR                   5        g ! [         aG    [        R                  " SSR                  UR                  UR                  UR                  5      5      ef = f)N)api_versionr   z+Message [{}] does not exist for API [{} {}])r   GetAPIapir   getattrGetMessagesModuler   AttributeErrorr   InvalidArgumentExceptionformatversionr	   GetRecursiveMessageSpecr
   r   	directory)selfargsr   r   message_specs        r   RunGenerateExportSchemas.RunO   s    
//$((0@0@
AC4--/>g
 44W=L
  \\<9  4//
BIIllDHHckk34 44s   $B AC" N)	__name__
__module____qualname____firstlineno____doc__staticmethodr   r*   __static_attributes__r,   r   r   r   r      s!    !F 
) 
)
9r   r   N)r1   
__future__r   r   r   googlecloudsdk.callioper   r   $googlecloudsdk.command_lib.meta.apisr   $googlecloudsdk.command_lib.util.apisr	   r
   r   SilentCommandr   r,   r   r   <module>r9      s8     Q &  ' ( . 6 : 7 9;9D.. ;9r   