o 2&a@s@ddlmZGdddeZGdddeZGdddeZdS) ) defaultdictc@s eZdZdS)ParameterRequiredErrorN)__name__ __module__ __qualname__rr//usr/lib/python3/dist-packages/awscli/schema.pyrsrc@sbeZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ dS)SchemaTransformeraE Transforms a custom argument parameter schema into an internal model representation so that it can be treated like a normal service model. This includes shorthand JSON parsing and automatic documentation generation. The format of the schema follows JSON Schema, which can be found here: http://json-schema.org/ Only a relevant subset of features is supported here: * Types: `object`, `array`, `string`, `integer`, `boolean` * Properties: `type`, `description`, `required`, `enum` For example:: { "type": "array", "items": { "type": "object", "properties": { "arg1": { "type": "string", "required": True, "enum": [ "Value1", "Value2", "Value3" ] }, "arg2": { "type": "integer", "description": "The number of calls" } } } } Assuming the schema is applied to a service named `foo`, with an operation named `bar` and that the parameter is called `baz`, you could call it with the shorthand JSON like so:: $ aws foo bar --baz arg1=Value1,arg2=5 arg1=Value2 structurelist)objectarraycCs t|_dSN)ShapeNameGenerator _shape_namerselfrrr__init__Gs zSchemaTransformer.__init__cCsi}|||d|S)aConvert JSON schema to the format used internally by the AWS CLI. :type schema: dict :param schema: The JSON schema describing the argument model. :rtype: dict :return: The transformed model in a form that can be consumed internally by the AWS CLI. The dictionary returned will have a list of shapes, where the shape representing the transformed schema is always named ``InputShape`` in the returned dictionary. InputShape) _transform)rschemashapesrrr transformJszSchemaTransformer.transformcCsd|vrtd|ddkr|||||<|S|ddkr(|||||<|S|ddkr8|||||<|S||||<|S)NtypeMissing required key: 'type'r r map)r_transform_structure_transform_list_transform_map_transform_scalar)rrr shape_namerrrr\s   zSchemaTransformer._transformcCs ||Sr)_populate_initial_shape)rrrrrris z#SchemaTransformer._transform_scalarc Cs||}i}g}|dD]'\}}||}|j|} d| i||<|ddr/|||||| q||d<|rA||d<|S)N propertiesshaperequiredFmembers)r!items_json_schema_to_aws_typernew_shape_namegetappendr) rrrstructure_shaper%required_memberskeyvaluecurrent_type_namecurrent_shape_namerrrrls     z&SchemaTransformer._transform_structurecCsP||}dD]}|||}|j|}d|i||<|||||q|S)N)r-r.r#r!r'rr(r)rrrr+ attribute type_namer rrrrs   z SchemaTransformer._transform_mapcCsF||}||d}|j|}d|i|d<||d|||S)Nr&r#memberr1)rrr list_shape member_typemember_shape_namerrrrs   z!SchemaTransformer._transform_listcCs:d||i}d|vr|d|d<d|vr|d|d<|S)Nr description documentationenum)r')rrr#rrrr!s   z)SchemaTransformer._populate_initial_shapecCs&d|vrtd|d}|j||S)Nrr)rJSON_SCHEMA_TO_AWS_TYPESr))rrr3rrrr'sz*SchemaTransformer._json_schema_to_aws_typeN)rrr__doc__r;rrrrrrrr!r'rrrrr s.   r c@seZdZddZddZdS)rcCstt|_dSr)rint _name_cacherrrrrszShapeNameGenerator.__init__cCs,|j|d7<|j|}d||fS)Nz%sType%s)r> capitalize)rr3 current_indexrrrr(s z!ShapeNameGenerator.new_shape_nameN)rrrrr(rrrrrs rN) collectionsr ValueErrorrr r rrrrrs