def serialize_config_file(self) -> str: def _config_imports(async_mode: bool) -> FileImport: file_import = FileImport() file_import.add_from_import("azure.core.configuration", "Configuration", ImportType.AZURECORE) file_import.add_from_import("azure.core.pipeline", "policies", ImportType.AZURECORE) file_import.add_from_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL) if self.code_model.options["package_version"]: file_import.add_from_import( ".._version" if async_mode else "._version", "VERSION", ImportType.LOCAL) for gp in self.code_model.global_parameters: file_import.merge(gp.imports()) return file_import package_name = self.code_model.options['package_name'] if package_name and package_name.startswith("azure-"): package_name = package_name[len("azure-"):] sdk_moniker = package_name if package_name else self.code_model.class_name.lower( ) if self.code_model.options['credential']: self._correct_credential_parameter() template = self.env.get_template("config.py.jinja2") return template.render(code_model=self.code_model, async_mode=self.async_mode, imports=FileImportSerializer( _config_imports(self.async_mode), is_python_3_file=self.async_mode), sdk_moniker=sdk_moniker)
def serialize_functions_init_file(self, operation): template = self.env.get_template("functions-init.py.jinja2") return template.render( code_model=self.code_model, request_type="HttpRequest", return_type="HttpResponse", function_name=operation.name, operations_description="Doing operation here", request_comment_description="Passing the request", return_comment_description="Request", magic_comment="### Do Magic Here! ###", imports=FileImportSerializer(self._get_imports()), success_status_code="200", failure_status_code="405")
def serialize(self) -> str: # Generate the models template = self.env.get_template("model_container.py.jinja2") return template.render( code_model=self.code_model, imports=FileImportSerializer( self.imports(), is_python_3_file=self.is_python_3_file), str=str, init_line=self.init_line, init_args=self.init_args, prop_documentation_string=ModelBaseSerializer. prop_documentation_string, prop_type_documentation_string=ModelBaseSerializer. prop_type_documentation_string, )
def serialize_service_client_file(self) -> str: def _service_client_imports() -> FileImport: file_import = self.code_model.service_client.imports( self.code_model, self.async_mode) for gp in self.code_model.global_parameters: file_import.merge(gp.imports()) return file_import template = self.env.get_template("service_client.py.jinja2") if self.code_model.options['credential']: self._correct_credential_parameter() return template.render( code_model=self.code_model, async_mode=self.async_mode, imports=FileImportSerializer(_service_client_imports(), is_python_3_file=self.async_mode), )
def serialize(self) -> str: def _is_lro(operation): return isinstance(operation, LROOperation) def _is_paging(operation): return isinstance(operation, PagingOperation) operation_group_template = self.env.get_template("operations_container.py.jinja2") if self.operation_group.is_empty_operation_group: operation_group_template = self.env.get_template("operations_container_mixin.py.jinja2") return operation_group_template.render( code_model=self.code_model, operation_group=self.operation_group, imports=FileImportSerializer( self.operation_group.imports(self.async_mode, bool(self.code_model.schemas)), is_python_3_file=self.async_mode ), async_mode=self.async_mode, is_lro=_is_lro, is_paging=_is_paging, )