def handle_resource_action( client_name, class_name, action, method_path, fn_name, service_model: ServiceModel, shapes_path, resource_path ): operation_model = service_model.operation_model(action.request.operation) input_shape = operation_model.input_shape has_output_shape = action.resource and action.resource.model.shape in service_model.shape_names output_shape = service_model.shape_for(action.resource.model.shape) if has_output_shape else None output_name = action.resource.model.name if action.resource else None if output_name: new_path = get_resource_path_for(output_name, resource_path) append_return_type = ' -> ' + f'[{output_name}]({new_path})' else: append_return_type = '' sub_res_var_name = None is_sub_res = is_sub_resource(resource_path) parameters = input_shape.members if input_shape else {} if is_sub_res: sub_res_name = resource_path[resource_path.rindex('/') + 1 :] sub_res_var_name = get_variable_name_for(sub_res_name) request_params = list(map(lambda x: x.target, action.request.params)) if input_shape: include_params = {name: value for name, value in input_shape.members.items() if name not in request_params} else: include_params = {} param_str = get_param_str_params(input_shape, shapes_path, include_params) else: if input_shape: include_params = { name: value for name, value in input_shape.members.items() if name in input_shape.required_members } else: include_params = {} param_str = get_param_str(input_shape, shapes_path) signature = get_signature_string( client_name, class_name, input_shape, output_shape, fn_name, param_str, shapes_path, append_return_type, sub_res_var_name, parameters, include_params, ) documentation = get_operation_documentation(operation_model, service_model) headline = f'# {fn_name} action' list_item = f'- **[{fn_name}]({method_path})**({param_str}){append_return_type}' return list_item, signature, documentation, headline
def handle_shapes(service_model: ServiceModel, class_name, shapes_path): top_level_shapes = [(service_model.shape_for(name), class_name) for name in service_model.shape_names] if not top_level_shapes: return docs_shapes_path = f'docs/{shapes_path}' create_new_file(docs_shapes_path) service_name = get_service_name(service_model) all_shapes = find_all_shapes(top_level_shapes) shape_docs = [get_shape_doc(shapes_path, shape) for shape in all_shapes] write_lines(docs_shapes_path, [f'# {service_name} data types'] + shape_docs)
def generate_service_types(output, service: ServiceModel, doc=True): output.write("import sys\n") output.write("from typing import Dict, List, Optional\n") output.write("from datetime import datetime\n") output.write("if sys.version_info >= (3, 8):\n") output.write(" from typing import TypedDict\n") output.write("else:\n") output.write(" from typing_extensions import TypedDict\n") output.write("\n") output.write( "from localstack.aws.api import handler, RequestContext, ServiceException, ServiceRequest" ) output.write("\n") # ==================================== print type declarations nodes: Dict[str, ShapeNode] = {} for shape_name in service.shape_names: shape = service.shape_for(shape_name) nodes[shape_name] = ShapeNode(service, shape) # output.write("__all__ = [\n") # for name in nodes.keys(): # output.write(f' "{name}",\n') # output.write("]\n") printed: Set[str] = set() visited: Set[str] = set() stack: List[str] = list(nodes.keys()) stack = sorted(stack, key=lambda name: nodes[name].get_order()) stack.reverse() while stack: name = stack.pop() if name in printed: continue node = nodes[name] dependencies = [dep for dep in node.dependencies if dep not in printed] if not dependencies: node.print_declaration(output, doc=doc) printed.add(name) elif name in visited: # break out of circular dependencies node.print_declaration(output, doc=doc, quote_types=True) printed.add(name) else: stack.append(name) stack.extend(dependencies) visited.add(name)
timestamp_parser=_compliance_timestamp_parser) # We load the json as utf-8, but the response parser is at the # botocore boundary, so it expects to work with bytes. body_bytes = case['response']['body'].encode('utf-8') case['response']['body'] = body_bytes # We need the headers to be case insensitive headers = HeadersDict(case['response']['headers']) case['response']['headers'] = headers # If this is an event stream fake the raw streamed response if operation_model.has_event_stream_output: case['response']['body'] = MockRawResponse(body_bytes) if 'error' in case: output_shape = operation_model.output_shape parsed = parser.parse(case['response'], output_shape) try: error_shape = model.shape_for(parsed['Error']['Code']) except NoShapeFoundError: error_shape = None if error_shape is not None: error_parse = parser.parse(case['response'], error_shape) parsed.update(error_parse) else: output_shape = operation_model.output_shape parsed = parser.parse(case['response'], output_shape) parsed = _fixup_parsed_result(parsed) except Exception as e: msg = ( "\nFailed to run test : %s\n" "Protocol : %s\n" "Description : %s (%s:%s)\n" % ( e, model.metadata['protocol'],