From a6d4c9bf54b0ff5dd4717576ee77cdd44760287a Mon Sep 17 00:00:00 2001 From: KoNekoD <108808201+KoNekoD@users.noreply.github.com> Date: Fri, 19 Apr 2024 09:48:05 +0300 Subject: [PATCH] Added Go support (#118) Added Go support --- .editorconfig | 491 ++++++++++++++++++ Makefile | 19 + docker/Dockerfile | 35 ++ docker/docker-compose.yml | 14 +- docker/memory_limit.ini | 1 + docker/php/Dockerfile | 14 - docker/php/php.ini | 18 - .../Dart/DartOutputGenerator.php | 4 +- src/OutputGenerator/Go/GoEnumResolver.php | 68 +++ src/OutputGenerator/Go/GoOutputGenerator.php | 72 +++ .../Go/GoRecursionValidator.php | 56 ++ src/OutputGenerator/Go/GoTypeResolver.php | 105 ++++ .../Go/OutputFilesProcessorProvider.php | 34 ++ .../OutputGeneratorInterface.php | 2 +- .../TypeScript/TypeScriptOutputGenerator.php | 6 +- tests/OutputGenerator/GoGeneratorTest.php | 319 ++++++++++++ .../GoOutputGeneratorSimple.php | 4 +- ...atorTest__testDtoConstantDoesntThrow__1.go | 17 + ...oGeneratorTest__testNestedDtoConvert__1.go | 25 + ...GoGeneratorTest__testNormalization__1.json | 141 +++++ .../GoGeneratorTest__testNormalization__2.go | 26 + ...orTest__testNormalizationDirectory__1.json | 276 ++++++++++ ...atorTest__testNormalizationDirectory__2.go | 58 +++ ...NormalizationWithCustomTypeResolvers__1.go | 17 + ...atorTest__testPhp81SuccessWhenBacked__1.go | 27 + .../GoGeneratorTest__testUseTypeEnum__1.go | 27 + .../GoSnapshotComparator.php | 15 + 27 files changed, 1850 insertions(+), 41 deletions(-) create mode 100644 .editorconfig create mode 100644 Makefile create mode 100644 docker/Dockerfile create mode 100644 docker/memory_limit.ini delete mode 100644 docker/php/Dockerfile delete mode 100644 docker/php/php.ini create mode 100644 src/OutputGenerator/Go/GoEnumResolver.php create mode 100644 src/OutputGenerator/Go/GoOutputGenerator.php create mode 100644 src/OutputGenerator/Go/GoRecursionValidator.php create mode 100644 src/OutputGenerator/Go/GoTypeResolver.php create mode 100644 src/OutputGenerator/Go/OutputFilesProcessorProvider.php create mode 100644 tests/OutputGenerator/GoGeneratorTest.php create mode 100644 tests/OutputGenerator/__snapshots__/GoGeneratorTest/testDtoConstantDoesntThrow/GoGeneratorTest__testDtoConstantDoesntThrow__1.go create mode 100644 tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNestedDtoConvert/GoGeneratorTest__testNestedDtoConvert__1.go create mode 100644 tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalization/GoGeneratorTest__testNormalization__1.json create mode 100644 tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalization/GoGeneratorTest__testNormalization__2.go create mode 100644 tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalizationDirectory/GoGeneratorTest__testNormalizationDirectory__1.json create mode 100644 tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalizationDirectory/GoGeneratorTest__testNormalizationDirectory__2.go create mode 100644 tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalizationWithCustomTypeResolvers/GoGeneratorTest__testNormalizationWithCustomTypeResolvers__1.go create mode 100644 tests/OutputGenerator/__snapshots__/GoGeneratorTest/testPhp81SuccessWhenBacked/GoGeneratorTest__testPhp81SuccessWhenBacked__1.go create mode 100644 tests/OutputGenerator/__snapshots__/GoGeneratorTest/testUseTypeEnum/GoGeneratorTest__testUseTypeEnum__1.go create mode 100644 tests/SnapshotComparator/GoSnapshotComparator.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9a23f39 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,491 @@ +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +max_line_length = 120 +tab_width = 4 +ij_continuation_indent_size = 8 +ij_formatter_off_tag = @formatter:off +ij_formatter_on_tag = @formatter:on +ij_formatter_tags_enabled = false +ij_smart_tabs = false +ij_visual_guides = none +ij_wrap_on_typing = false + +[.editorconfig] +ij_editorconfig_align_group_field_declarations = false +ij_editorconfig_space_after_colon = false +ij_editorconfig_space_after_comma = true +ij_editorconfig_space_before_colon = false +ij_editorconfig_space_before_comma = false +ij_editorconfig_spaces_around_assignment_operators = true + +[{*.ant,*.fxml,*.jhm,*.jnlp,*.jrxml,*.rng,*.tld,*.wsdl,*.xml,*.xsd,*.xsl,*.xslt,*.xul,phpunit.xml.dist}] +ij_xml_align_attributes = true +ij_xml_align_text = false +ij_xml_attribute_wrap = normal +ij_xml_block_comment_add_space = false +ij_xml_block_comment_at_first_column = true +ij_xml_keep_blank_lines = 2 +ij_xml_keep_indents_on_empty_lines = false +ij_xml_keep_line_breaks = true +ij_xml_keep_line_breaks_in_text = true +ij_xml_keep_whitespaces = false +ij_xml_keep_whitespaces_around_cdata = preserve +ij_xml_keep_whitespaces_inside_cdata = false +ij_xml_line_comment_at_first_column = true +ij_xml_space_after_tag_name = false +ij_xml_space_around_equals_in_attribute = false +ij_xml_space_inside_empty_tag = false +ij_xml_text_wrap = normal + +[{*.bash,*.sh,*.zsh}] +indent_size = 2 +tab_width = 2 +ij_shell_binary_ops_start_line = false +ij_shell_keep_column_alignment_padding = false +ij_shell_minify_program = false +ij_shell_redirect_followed_by_space = false +ij_shell_switch_cases_indented = false +ij_shell_use_unix_line_separator = true + +[{*.cjs,*.js,*.js.twig}] +indent_size = 2 +ij_continuation_indent_size = 2 +ij_javascript_align_imports = false +ij_javascript_align_multiline_array_initializer_expression = false +ij_javascript_align_multiline_binary_operation = false +ij_javascript_align_multiline_chained_methods = false +ij_javascript_align_multiline_extends_list = false +ij_javascript_align_multiline_for = true +ij_javascript_align_multiline_parameters = true +ij_javascript_align_multiline_parameters_in_calls = false +ij_javascript_align_multiline_ternary_operation = false +ij_javascript_align_object_properties = 0 +ij_javascript_align_union_types = false +ij_javascript_align_var_statements = 0 +ij_javascript_array_initializer_new_line_after_left_brace = false +ij_javascript_array_initializer_right_brace_on_new_line = false +ij_javascript_array_initializer_wrap = off +ij_javascript_assignment_wrap = off +ij_javascript_binary_operation_sign_on_next_line = false +ij_javascript_binary_operation_wrap = off +ij_javascript_blacklist_imports = rxjs/Rx, node_modules/**, **/node_modules/**, @angular/material, @angular/material/typings/** +ij_javascript_blank_lines_after_imports = 1 +ij_javascript_blank_lines_around_class = 1 +ij_javascript_blank_lines_around_field = 0 +ij_javascript_blank_lines_around_function = 1 +ij_javascript_blank_lines_around_method = 1 +ij_javascript_block_brace_style = end_of_line +ij_javascript_block_comment_add_space = false +ij_javascript_block_comment_at_first_column = true +ij_javascript_call_parameters_new_line_after_left_paren = false +ij_javascript_call_parameters_right_paren_on_new_line = false +ij_javascript_call_parameters_wrap = off +ij_javascript_catch_on_new_line = false +ij_javascript_chained_call_dot_on_new_line = true +ij_javascript_class_brace_style = end_of_line +ij_javascript_comma_on_new_line = false +ij_javascript_do_while_brace_force = never +ij_javascript_else_on_new_line = false +ij_javascript_enforce_trailing_comma = keep +ij_javascript_extends_keyword_wrap = off +ij_javascript_extends_list_wrap = off +ij_javascript_field_prefix = _ +ij_javascript_file_name_style = relaxed +ij_javascript_finally_on_new_line = false +ij_javascript_for_brace_force = never +ij_javascript_for_statement_new_line_after_left_paren = false +ij_javascript_for_statement_right_paren_on_new_line = false +ij_javascript_for_statement_wrap = off +ij_javascript_force_quote_style = false +ij_javascript_force_semicolon_style = false +ij_javascript_function_expression_brace_style = end_of_line +ij_javascript_if_brace_force = never +ij_javascript_import_merge_members = global +ij_javascript_import_prefer_absolute_path = global +ij_javascript_import_sort_members = true +ij_javascript_import_sort_module_name = false +ij_javascript_import_use_node_resolution = true +ij_javascript_imports_wrap = on_every_item +ij_javascript_indent_case_from_switch = true +ij_javascript_indent_chained_calls = true +ij_javascript_indent_package_children = 0 +ij_javascript_jsx_attribute_value = braces +ij_javascript_keep_blank_lines_in_code = 2 +ij_javascript_keep_first_column_comment = true +ij_javascript_keep_indents_on_empty_lines = false +ij_javascript_keep_line_breaks = true +ij_javascript_keep_simple_blocks_in_one_line = false +ij_javascript_keep_simple_methods_in_one_line = false +ij_javascript_line_comment_add_space = true +ij_javascript_line_comment_at_first_column = false +ij_javascript_method_brace_style = end_of_line +ij_javascript_method_call_chain_wrap = off +ij_javascript_method_parameters_new_line_after_left_paren = false +ij_javascript_method_parameters_right_paren_on_new_line = false +ij_javascript_method_parameters_wrap = off +ij_javascript_object_literal_wrap = on_every_item +ij_javascript_parentheses_expression_new_line_after_left_paren = false +ij_javascript_parentheses_expression_right_paren_on_new_line = false +ij_javascript_place_assignment_sign_on_next_line = false +ij_javascript_prefer_as_type_cast = false +ij_javascript_prefer_explicit_types_function_expression_returns = false +ij_javascript_prefer_explicit_types_function_returns = false +ij_javascript_prefer_explicit_types_vars_fields = false +ij_javascript_prefer_parameters_wrap = false +ij_javascript_reformat_c_style_comments = false +ij_javascript_space_after_colon = true +ij_javascript_space_after_comma = true +ij_javascript_space_after_dots_in_rest_parameter = false +ij_javascript_space_after_generator_mult = true +ij_javascript_space_after_property_colon = true +ij_javascript_space_after_quest = true +ij_javascript_space_after_type_colon = true +ij_javascript_space_after_unary_not = false +ij_javascript_space_before_async_arrow_lparen = true +ij_javascript_space_before_catch_keyword = true +ij_javascript_space_before_catch_left_brace = true +ij_javascript_space_before_catch_parentheses = true +ij_javascript_space_before_class_lbrace = true +ij_javascript_space_before_class_left_brace = true +ij_javascript_space_before_colon = true +ij_javascript_space_before_comma = false +ij_javascript_space_before_do_left_brace = true +ij_javascript_space_before_else_keyword = true +ij_javascript_space_before_else_left_brace = true +ij_javascript_space_before_finally_keyword = true +ij_javascript_space_before_finally_left_brace = true +ij_javascript_space_before_for_left_brace = true +ij_javascript_space_before_for_parentheses = true +ij_javascript_space_before_for_semicolon = false +ij_javascript_space_before_function_left_parenth = true +ij_javascript_space_before_generator_mult = false +ij_javascript_space_before_if_left_brace = true +ij_javascript_space_before_if_parentheses = true +ij_javascript_space_before_method_call_parentheses = false +ij_javascript_space_before_method_left_brace = true +ij_javascript_space_before_method_parentheses = false +ij_javascript_space_before_property_colon = false +ij_javascript_space_before_quest = true +ij_javascript_space_before_switch_left_brace = true +ij_javascript_space_before_switch_parentheses = true +ij_javascript_space_before_try_left_brace = true +ij_javascript_space_before_type_colon = false +ij_javascript_space_before_unary_not = false +ij_javascript_space_before_while_keyword = true +ij_javascript_space_before_while_left_brace = true +ij_javascript_space_before_while_parentheses = true +ij_javascript_spaces_around_additive_operators = true +ij_javascript_spaces_around_arrow_function_operator = true +ij_javascript_spaces_around_assignment_operators = true +ij_javascript_spaces_around_bitwise_operators = true +ij_javascript_spaces_around_equality_operators = true +ij_javascript_spaces_around_logical_operators = true +ij_javascript_spaces_around_multiplicative_operators = true +ij_javascript_spaces_around_relational_operators = true +ij_javascript_spaces_around_shift_operators = true +ij_javascript_spaces_around_unary_operator = false +ij_javascript_spaces_within_array_initializer_brackets = false +ij_javascript_spaces_within_brackets = false +ij_javascript_spaces_within_catch_parentheses = false +ij_javascript_spaces_within_for_parentheses = false +ij_javascript_spaces_within_if_parentheses = false +ij_javascript_spaces_within_imports = false +ij_javascript_spaces_within_interpolation_expressions = false +ij_javascript_spaces_within_method_call_parentheses = false +ij_javascript_spaces_within_method_parentheses = false +ij_javascript_spaces_within_object_literal_braces = false +ij_javascript_spaces_within_object_type_braces = true +ij_javascript_spaces_within_parentheses = false +ij_javascript_spaces_within_switch_parentheses = false +ij_javascript_spaces_within_type_assertion = false +ij_javascript_spaces_within_union_types = true +ij_javascript_spaces_within_while_parentheses = false +ij_javascript_special_else_if_treatment = true +ij_javascript_ternary_operation_signs_on_next_line = false +ij_javascript_ternary_operation_wrap = off +ij_javascript_union_types_wrap = on_every_item +ij_javascript_use_chained_calls_group_indents = false +ij_javascript_use_double_quotes = true +ij_javascript_use_explicit_js_extension = auto +ij_javascript_use_path_mapping = always +ij_javascript_use_public_modifier = false +ij_javascript_use_semicolon_after_statement = true +ij_javascript_var_declaration_wrap = normal +ij_javascript_while_brace_force = never +ij_javascript_while_on_new_line = false +ij_javascript_wrap_comments = false + +[{*.ctp,*.hphp,*.inc,*.module,*.php,*.php4,*.php5,*.phtml}] +ij_continuation_indent_size = 4 +ij_php_align_assignments = false +ij_php_align_class_constants = false +ij_php_align_group_field_declarations = false +ij_php_align_inline_comments = false +ij_php_align_key_value_pairs = false +ij_php_align_match_arm_bodies = false +ij_php_align_multiline_array_initializer_expression = true +ij_php_align_multiline_binary_operation = false +ij_php_align_multiline_chained_methods = false +ij_php_align_multiline_extends_list = false +ij_php_align_multiline_for = true +ij_php_align_multiline_parameters = false +ij_php_align_multiline_parameters_in_calls = false +ij_php_align_multiline_ternary_operation = false +ij_php_align_named_arguments = false +ij_php_align_phpdoc_comments = false +ij_php_align_phpdoc_param_names = false +ij_php_anonymous_brace_style = end_of_line +ij_php_api_weight = 28 +ij_php_array_initializer_new_line_after_left_brace = true +ij_php_array_initializer_right_brace_on_new_line = true +ij_php_array_initializer_wrap = on_every_item +ij_php_assignment_wrap = off +ij_php_attributes_wrap = off +ij_php_author_weight = 28 +ij_php_binary_operation_sign_on_next_line = false +ij_php_binary_operation_wrap = off +ij_php_blank_lines_after_class_header = 0 +ij_php_blank_lines_after_function = 1 +ij_php_blank_lines_after_imports = 1 +ij_php_blank_lines_after_opening_tag = 0 +ij_php_blank_lines_after_package = 1 +ij_php_blank_lines_around_class = 1 +ij_php_blank_lines_around_constants = 0 +ij_php_blank_lines_around_field = 0 +ij_php_blank_lines_around_method = 1 +ij_php_blank_lines_before_class_end = 0 +ij_php_blank_lines_before_imports = 1 +ij_php_blank_lines_before_method_body = 0 +ij_php_blank_lines_before_package = 1 +ij_php_blank_lines_before_return_statement = 1 +ij_php_blank_lines_between_imports = 0 +ij_php_block_brace_style = end_of_line +ij_php_call_parameters_new_line_after_left_paren = true +ij_php_call_parameters_right_paren_on_new_line = true +ij_php_call_parameters_wrap = on_every_item +ij_php_catch_on_new_line = false +ij_php_category_weight = 28 +ij_php_class_brace_style = next_line +ij_php_comma_after_last_array_element = true +ij_php_concat_spaces = false +ij_php_copyright_weight = 28 +ij_php_deprecated_weight = 28 +ij_php_do_while_brace_force = always +ij_php_else_if_style = combine +ij_php_else_on_new_line = false +ij_php_example_weight = 28 +ij_php_extends_keyword_wrap = split_into_lines +ij_php_extends_list_wrap = off +ij_php_fields_default_visibility = private +ij_php_filesource_weight = 28 +ij_php_finally_on_new_line = false +ij_php_for_brace_force = always +ij_php_for_statement_new_line_after_left_paren = false +ij_php_for_statement_right_paren_on_new_line = false +ij_php_for_statement_wrap = off +ij_php_force_empty_methods_in_one_line = true +ij_php_force_short_declaration_array_style = true +ij_php_getters_setters_naming_style = camel_case +ij_php_getters_setters_order_style = getters_first +ij_php_global_weight = 28 +ij_php_group_use_wrap = on_every_item +ij_php_if_brace_force = always +ij_php_if_lparen_on_next_line = false +ij_php_if_rparen_on_next_line = false +ij_php_ignore_weight = 28 +ij_php_import_sorting = alphabetic +ij_php_indent_break_from_case = true +ij_php_indent_case_from_switch = true +ij_php_indent_code_in_php_tags = false +ij_php_internal_weight = 28 +ij_php_keep_blank_lines_after_lbrace = 2 +ij_php_keep_blank_lines_before_right_brace = 2 +ij_php_keep_blank_lines_in_code = 2 +ij_php_keep_blank_lines_in_declarations = 2 +ij_php_keep_control_statement_in_one_line = true +ij_php_keep_first_column_comment = true +ij_php_keep_indents_on_empty_lines = false +ij_php_keep_line_breaks = true +ij_php_keep_rparen_and_lbrace_on_one_line = true +ij_php_keep_simple_classes_in_one_line = false +ij_php_keep_simple_methods_in_one_line = false +ij_php_lambda_brace_style = end_of_line +ij_php_license_weight = 28 +ij_php_line_comment_add_space = false +ij_php_line_comment_at_first_column = true +ij_php_link_weight = 28 +ij_php_lower_case_boolean_const = true +ij_php_lower_case_keywords = true +ij_php_lower_case_null_const = true +ij_php_method_brace_style = next_line +ij_php_method_call_chain_wrap = off +ij_php_method_parameters_new_line_after_left_paren = true +ij_php_method_parameters_right_paren_on_new_line = true +ij_php_method_parameters_wrap = on_every_item +ij_php_method_weight = 28 +ij_php_modifier_list_wrap = false +ij_php_multiline_chained_calls_semicolon_on_new_line = false +ij_php_namespace_brace_style = 1 +ij_php_new_line_after_php_opening_tag = false +ij_php_null_type_position = in_the_end +ij_php_package_weight = 28 +ij_php_param_weight = 0 +ij_php_parameters_attributes_wrap = off +ij_php_parentheses_expression_new_line_after_left_paren = false +ij_php_parentheses_expression_right_paren_on_new_line = false +ij_php_phpdoc_blank_line_before_tags = false +ij_php_phpdoc_blank_lines_around_parameters = false +ij_php_phpdoc_keep_blank_lines = true +ij_php_phpdoc_param_spaces_between_name_and_description = 1 +ij_php_phpdoc_param_spaces_between_tag_and_type = 1 +ij_php_phpdoc_param_spaces_between_type_and_name = 1 +ij_php_phpdoc_use_fqcn = false +ij_php_phpdoc_wrap_long_lines = false +ij_php_place_assignment_sign_on_next_line = false +ij_php_place_parens_for_constructor = 0 +ij_php_property_read_weight = 28 +ij_php_property_weight = 28 +ij_php_property_write_weight = 28 +ij_php_return_type_on_new_line = false +ij_php_return_weight = 1 +ij_php_see_weight = 28 +ij_php_since_weight = 28 +ij_php_sort_phpdoc_elements = true +ij_php_space_after_colon = true +ij_php_space_after_colon_in_enum_backed_type = true +ij_php_space_after_colon_in_named_argument = true +ij_php_space_after_colon_in_return_type = true +ij_php_space_after_comma = true +ij_php_space_after_for_semicolon = true +ij_php_space_after_quest = true +ij_php_space_after_type_cast = false +ij_php_space_after_unary_not = false +ij_php_space_before_array_initializer_left_brace = false +ij_php_space_before_catch_keyword = true +ij_php_space_before_catch_left_brace = true +ij_php_space_before_catch_parentheses = true +ij_php_space_before_class_left_brace = true +ij_php_space_before_closure_left_parenthesis = true +ij_php_space_before_colon = true +ij_php_space_before_colon_in_enum_backed_type = false +ij_php_space_before_colon_in_named_argument = false +ij_php_space_before_colon_in_return_type = false +ij_php_space_before_comma = false +ij_php_space_before_do_left_brace = true +ij_php_space_before_else_keyword = true +ij_php_space_before_else_left_brace = true +ij_php_space_before_finally_keyword = true +ij_php_space_before_finally_left_brace = true +ij_php_space_before_for_left_brace = true +ij_php_space_before_for_parentheses = true +ij_php_space_before_for_semicolon = false +ij_php_space_before_if_left_brace = true +ij_php_space_before_if_parentheses = true +ij_php_space_before_method_call_parentheses = false +ij_php_space_before_method_left_brace = true +ij_php_space_before_method_parentheses = false +ij_php_space_before_quest = true +ij_php_space_before_short_closure_left_parenthesis = false +ij_php_space_before_switch_left_brace = true +ij_php_space_before_switch_parentheses = true +ij_php_space_before_try_left_brace = true +ij_php_space_before_unary_not = false +ij_php_space_before_while_keyword = true +ij_php_space_before_while_left_brace = true +ij_php_space_before_while_parentheses = true +ij_php_space_between_ternary_quest_and_colon = false +ij_php_spaces_around_additive_operators = true +ij_php_spaces_around_arrow = false +ij_php_spaces_around_assignment_in_declare = false +ij_php_spaces_around_assignment_operators = true +ij_php_spaces_around_bitwise_operators = true +ij_php_spaces_around_equality_operators = true +ij_php_spaces_around_logical_operators = true +ij_php_spaces_around_multiplicative_operators = true +ij_php_spaces_around_null_coalesce_operator = true +ij_php_spaces_around_pipe_in_union_type = false +ij_php_spaces_around_relational_operators = true +ij_php_spaces_around_shift_operators = true +ij_php_spaces_around_unary_operator = false +ij_php_spaces_around_var_within_brackets = false +ij_php_spaces_within_array_initializer_braces = false +ij_php_spaces_within_brackets = false +ij_php_spaces_within_catch_parentheses = false +ij_php_spaces_within_for_parentheses = false +ij_php_spaces_within_if_parentheses = false +ij_php_spaces_within_method_call_parentheses = false +ij_php_spaces_within_method_parentheses = false +ij_php_spaces_within_parentheses = false +ij_php_spaces_within_short_echo_tags = true +ij_php_spaces_within_switch_parentheses = false +ij_php_spaces_within_while_parentheses = false +ij_php_special_else_if_treatment = false +ij_php_subpackage_weight = 28 +ij_php_ternary_operation_signs_on_next_line = false +ij_php_ternary_operation_wrap = off +ij_php_throws_weight = 2 +ij_php_todo_weight = 28 +ij_php_unknown_tag_weight = 28 +ij_php_upper_case_boolean_const = false +ij_php_upper_case_null_const = false +ij_php_uses_weight = 28 +ij_php_var_weight = 28 +ij_php_variable_naming_style = camel_case +ij_php_version_weight = 28 +ij_php_while_brace_force = always +ij_php_while_on_new_line = false + +[{*.har,*.jsb2,*.jsb3,*.json,.babelrc,.eslintrc,.stylelintrc,bowerrc,composer.lock,jest.config}] +max_line_length = off +ij_json_keep_blank_lines_in_code = 0 +ij_json_keep_indents_on_empty_lines = false +ij_json_keep_line_breaks = true +ij_json_space_after_colon = true +ij_json_space_after_comma = true +ij_json_space_before_colon = false +ij_json_space_before_comma = false +ij_json_spaces_within_braces = false +ij_json_spaces_within_brackets = false +ij_json_wrap_long_lines = false + +[{*.markdown,*.md}] +ij_markdown_force_one_space_after_blockquote_symbol = true +ij_markdown_force_one_space_after_header_symbol = true +ij_markdown_force_one_space_after_list_bullet = true +ij_markdown_force_one_space_between_words = true +ij_markdown_keep_indents_on_empty_lines = false +ij_markdown_max_lines_around_block_elements = 1 +ij_markdown_max_lines_around_header = 1 +ij_markdown_max_lines_between_paragraphs = 1 +ij_markdown_min_lines_around_block_elements = 1 +ij_markdown_min_lines_around_header = 1 +ij_markdown_min_lines_between_paragraphs = 1 + +[{*.twg,*.twig}] +ij_twig_keep_indents_on_empty_lines = false +ij_twig_spaces_inside_comments_delimiters = true +ij_twig_spaces_inside_delimiters = true +ij_twig_spaces_inside_variable_delimiters = true + +[{*.yaml,*.yml}] +indent_size = 2 +ij_yaml_align_values_properties = do_not_align +ij_yaml_autoinsert_sequence_marker = true +ij_yaml_block_mapping_on_new_line = false +ij_yaml_indent_sequence_value = true +ij_yaml_keep_indents_on_empty_lines = false +ij_yaml_keep_line_breaks = true +ij_yaml_sequence_on_new_line = false +ij_yaml_space_before_colon = false +ij_yaml_spaces_within_braces = true +ij_yaml_spaces_within_brackets = true + +[*.html.twig] +max_line_length = off + +[bundles.php] +max_line_length = off \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2ecfe19 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +COMPOSE_FILE = ./docker/docker-compose.yml +DOCKER_COMPOSE = docker compose -f ${COMPOSE_FILE} +DOCKER_COMPOSE_PHP_FPM_EXEC = ${DOCKER_COMPOSE} exec php-converter + +build: + ${DOCKER_COMPOSE} build + +up: + ${DOCKER_COMPOSE} up -d --remove-orphans + +down: + ${DOCKER_COMPOSE} down -v + +down_force: + ${DOCKER_COMPOSE} down -v --rmi=all --remove-orphans + +console: + if ! ${DOCKER_COMPOSE} ps | grep -q raphael-php-fpm; then make up; fi + ${DOCKER_COMPOSE_PHP_FPM_EXEC} bash diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..b33fe72 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,35 @@ +FROM php:8.3-fpm-alpine as php-converter + +ARG SCRIPT_URL='https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions' +RUN set -eux && \ + curl -sSLf -o /usr/local/bin/install-php-extensions ${SCRIPT_URL} && \ + chmod +x /usr/local/bin/install-php-extensions && \ + apk add git bash gettext openssh && \ + touch /var/log/xdebug.log && chmod 0666 /var/log/xdebug.log && \ + install-php-extensions @composer intl zip opcache pcntl sockets xsl + +ARG PHP_IDE_CONFIG="serverName=Docker" +ENV PHP_IDE_CONFIG=$PHP_IDE_CONFIG +ARG XDEBUG_AUTOSTART=trigger +ARG DEV_HOST_IP=172.18.7.1 +ARG DEV_XDEBUG_IDE_KEY=PHPSTORM +ARG XDEBUG_FILE=/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +RUN install-php-extensions xdebug gd && \ + echo "xdebug.mode=debug" >> $XDEBUG_FILE && \ + echo "xdebug.start_with_request=$XDEBUG_AUTOSTART" >> $XDEBUG_FILE && \ + echo "xdebug.client_host=$DEV_HOST_IP" >> $XDEBUG_FILE && \ + echo "xdebug.client_port=9003" >> $XDEBUG_FILE && \ + echo "xdebug.log=/var/log/xdebug.log" >> $XDEBUG_FILE && \ + echo "xdebug.idekey=$DEV_XDEBUG_IDE_KEY" >> $XDEBUG_FILE && \ + apk add --no-cache ranger vim nano vifm; + +COPY --from=cytopia/gofmt:latest /usr/local/bin/gofmt /usr/bin/gofmt +COPY ./docker/memory_limit.ini /usr/local/etc/php/conf.d/memory_limit.ini + +ARG UID=1000 +ARG GID=1000 +RUN addgroup -g $GID app && adduser -D -u $UID -G app app && addgroup app www-data +USER app +COPY --chown=app:app ../ /var/www/php-converter +WORKDIR /var/www/php-converter +USER www-data diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index d5e5731..a53a403 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -5,7 +5,19 @@ name: php-converter services: php-converter: container_name: php-converter + user: app build: - context: ./php + dockerfile: ./docker/Dockerfile + context: ../ volumes: - ../.:/var/www/php-converter:cached + networks: + - php-converter-network + +networks: + php-converter-network: + name: php-converter-network + ipam: + config: + - subnet: 172.18.7.0/24 + gateway: 172.18.7.1 diff --git a/docker/memory_limit.ini b/docker/memory_limit.ini new file mode 100644 index 0000000..e5b78f9 --- /dev/null +++ b/docker/memory_limit.ini @@ -0,0 +1 @@ +memory_limit = 1G \ No newline at end of file diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile deleted file mode 100644 index fcf72a2..0000000 --- a/docker/php/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM php:8.2-fpm-alpine AS php-converter - -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer - -#ssh key is needed for downloading vendors -RUN apk add git openssh -RUN mkdir ~/.ssh - -COPY php.ini /usr/local/etc/php/php.ini - -WORKDIR /var/www/php-converter -COPY ../../. ./ - -ENV COMPOSER_ALLOW_SUPERUSER=1 diff --git a/docker/php/php.ini b/docker/php/php.ini deleted file mode 100644 index 3a7e366..0000000 --- a/docker/php/php.ini +++ /dev/null @@ -1,18 +0,0 @@ -session.auto_start = Off -short_open_tag = Off - -# http://symfony.com/doc/current/performance.html -opcache.interned_strings_buffer = 16 -opcache.max_accelerated_files = 20000 -opcache.memory_consumption = 256 -realpath_cache_size = 4096K -realpath_cache_ttl = 600 - -memory_limit = 128M -post_max_size = 6M -upload_max_filesize = 5M - -display_errors = Off -display_startup_errors = Off - -error_log = /var/log/php-fpm.log \ No newline at end of file diff --git a/src/OutputGenerator/Dart/DartOutputGenerator.php b/src/OutputGenerator/Dart/DartOutputGenerator.php index a233721..227b640 100644 --- a/src/OutputGenerator/Dart/DartOutputGenerator.php +++ b/src/OutputGenerator/Dart/DartOutputGenerator.php @@ -35,11 +35,11 @@ public function __construct( } /** @return OutputFile[] */ - public function generate(ConverterResult $converterResult): array + public function generate(ConverterResult $result): array { $this->outputWriter->reset(); - $dtoList = $converterResult->dtoList; + $dtoList = $result->dtoList; foreach ($dtoList->getList() as $dto) { $this->outputWriter->writeType($this->convertToDartType($dto, $dtoList), $dto); } diff --git a/src/OutputGenerator/Go/GoEnumResolver.php b/src/OutputGenerator/Go/GoEnumResolver.php new file mode 100644 index 0000000..95495ea --- /dev/null +++ b/src/OutputGenerator/Go/GoEnumResolver.php @@ -0,0 +1,68 @@ +getProperties()[0] ?? null; + if ($firstEnumProperty === null) { + throw new Exception('Enum must have at least one property'); + } + + $firstEnumPropValue = $firstEnumProperty->getValue(); + if (is_int($firstEnumPropValue)) { + $type = 'int'; + } elseif (is_string($firstEnumPropValue)) { + $type = 'string'; + } else { + throw new Exception('Enum property must be int or string, got ' . gettype($firstEnumPropValue)); + } + $props = self::convertEnumToGoEnumProperties($dto->getProperties(), $dto->getName()); + + return sprintf("type %s %s\n\nconst (%s\n)", $dto->getName(), $type, $props); + } + + /** + * @param DtoEnumProperty[] $properties + * @throws Exception + */ + private function convertEnumToGoEnumProperties(array $properties, string $enum): string + { + $string = ''; + + $maxEnumPropNameLength = 0; + foreach ($properties as $prop) { + $maxEnumPropNameLength = max($maxEnumPropNameLength, strlen($prop->getName())); + } + + foreach ($properties as $prop) { + $const = $prop->getName(); + if (in_array($const, $this->usedConstantsStore)) { + $const .= $enum; + } + if (array_key_exists($const, $this->usedConstantsStore)) { + throw new Exception('Please rename constant ' . $const); + } + $this->usedConstantsStore[] = $const; + + $spaces = str_repeat(' ', $maxEnumPropNameLength - strlen($prop->getName()) + 1); + + $value = $prop->isNumeric() ? $prop->getValue() : sprintf('"%s"', $prop->getValue()); + $string .= sprintf("\n\t%s$spaces%s = %s", $const, $enum, $value); + } + + return $string; + } +} diff --git a/src/OutputGenerator/Go/GoOutputGenerator.php b/src/OutputGenerator/Go/GoOutputGenerator.php new file mode 100644 index 0000000..a3226a8 --- /dev/null +++ b/src/OutputGenerator/Go/GoOutputGenerator.php @@ -0,0 +1,72 @@ +outputFilesProcessor = OutputFilesProcessorProvider::provide($outputFilesProcessor); + $this->enumResolver = new GoEnumResolver(); + } + + /** + * @return OutputFile[] + * @throws Exception + */ + public function generate(ConverterResult $result): array + { + $this->outputWriter->reset(); + foreach ($result->dtoList->getList() as $dto) { + $this->outputWriter->writeType($this->convert($dto, $result->dtoList), $dto); + } + + return $this->outputFilesProcessor->process($this->outputWriter->getTypes()); + } + + /** @throws Exception */ + private function convert(DtoType $dto, DtoList $dtoList): string + { + if ($dto->getExpressionType()->equals(ExpressionType::class())) { + $structProps = ''; + $maxStructPropNameLength = 0; + foreach ($dto->getProperties() as $prop) { + $maxStructPropNameLength = max($maxStructPropNameLength, strlen($prop->getName())); + } + foreach ($dto->getProperties() as $prop) { + $spaces = str_repeat(' ', $maxStructPropNameLength - strlen($prop->getName()) + 1); + + $structProps .= sprintf( + "\n\t%s$spaces%s", + ucfirst($prop->getName()), + $this->resolver->resolve($prop->getType(), $dto, $dtoList) + ); + } + + return sprintf("type %s struct {%s\n}", $dto->getName(), $structProps); + } + if ($dto->getExpressionType()->isAnyEnum()) { + return $this->enumResolver->resolve($dto); + } + throw new Exception('Unknown expression type ' . $dto->getExpressionType()->jsonSerialize()); + } +} diff --git a/src/OutputGenerator/Go/GoRecursionValidator.php b/src/OutputGenerator/Go/GoRecursionValidator.php new file mode 100644 index 0000000..7375a91 --- /dev/null +++ b/src/OutputGenerator/Go/GoRecursionValidator.php @@ -0,0 +1,56 @@ +getProperties() as $value) { + if (!$value instanceof DtoClassProperty) { + continue; + } + $type = $value->getType(); + if (!$type instanceof PhpUnknownType) { + continue; + } + if (!$classNameResolver->supports($type, $dto, $dtoList)) { + continue; + } + + $dtoName = $dto->getName(); + if (in_array($dtoName, $visited)) { + return true; + } + + $visited[] = $dtoName; + + /** @var string $resolvedType */ + $resolvedType = $classNameResolver->resolve($type, $dto, $dtoList); + + $resolvedDto = $dtoList->getDtoByType($resolvedType); + if (!$resolvedDto) { + throw new Exception(sprintf('Unknown type %s', $resolvedType)); + } + + return self::isRecursionFound($resolvedDto, $dtoList, $visited); + } + + return false; + } +} diff --git a/src/OutputGenerator/Go/GoTypeResolver.php b/src/OutputGenerator/Go/GoTypeResolver.php new file mode 100644 index 0000000..b2c57b0 --- /dev/null +++ b/src/OutputGenerator/Go/GoTypeResolver.php @@ -0,0 +1,105 @@ + $this->resolve($type, $dto, $dtoList); + $types = array_map($fn, $type->getTypes()); + + // Two args, one of them is null + if (count($types) === 2 && in_array('null', $types)) { + $types = array_diff($types, ['null']); + + if (str_starts_with($types[0], '*')) { + return $types[0]; // If it was resolveUnknown recursion found(dirty fix) + } + + return "*$types[0]"; + } + throw new Exception('Unsupported union type: ' . json_encode($type)); + } + + /** @throws Exception */ + private function resolveUnknown(PhpUnknownType $type, ?DtoType $dto, DtoList $dtoList): string + { + $result = null; + foreach ($this->unknownTypeResolvers as $resolver) { + if ($resolver->supports($type, $dto, $dtoList)) { + $result = $resolver->resolve($type, $dto, $dtoList); + if ($result instanceof PhpTypeInterface) { + return $this->resolve($result, $dto, $dtoList); + } + + // If it was ClassNameTypeResolver + if ( + is_string($result) && + $resolver instanceof ClassNameTypeResolver && + GoRecursionValidator::isRecursionFound($dto, $dtoList) + ) { + return "*$result"; + } + } + } + if ($result === null) { + throw UnsupportedTypeException::forType($type, $dto?->getName() ?? ''); + } + + return $result; + } + + /** @throws Exception */ + private function resolveBase(PhpBaseType $type, ?DtoType $dto): string + { + return match (true) { + $type->equalsTo(PhpBaseType::int()) => 'int', + $type->equalsTo(PhpBaseType::float()) => 'float64', + $type->equalsTo(PhpBaseType::string()) => 'string', + $type->equalsTo(PhpBaseType::bool()) => 'bool', + $type->equalsTo(PhpBaseType::mixed()), + $type->equalsTo(PhpBaseType::object()) => 'interface{}', + $type->equalsTo(PhpBaseType::array()), + $type->equalsTo(PhpBaseType::iterable()) => '[]interface{}', + $type->equalsTo(PhpBaseType::null()) => 'null', + $type->equalsTo(PhpBaseType::self()) => "*{$dto->getName()}", // * for prevent recursive definition + default => throw new Exception('Unknown base PHP type: %s' . json_encode($type)) + }; + } + + /** @throws Exception */ + public function resolve(PhpTypeInterface $type, ?DtoType $d, DtoList $dl): string + { + return match ($type::class) { + PhpBaseType::class => $this->resolveBase($type, $d), + PhpListType::class => sprintf('[]%s', $this->resolve($type->getType(), $d, $dl)), + PhpUnionType::class => $this->resolveUnion($type, $d, $dl), + PhpUnknownType::class => $this->resolveUnknown($type, $d, $dl), + PhpOptionalType::class => $this->resolve($type->getType(), $d, $dl), + default => throw new Exception('Type not implemented: ' . get_class($type)) + }; + } +} diff --git a/src/OutputGenerator/Go/OutputFilesProcessorProvider.php b/src/OutputGenerator/Go/OutputFilesProcessorProvider.php new file mode 100644 index 0000000..f466bfe --- /dev/null +++ b/src/OutputGenerator/Go/OutputFilesProcessorProvider.php @@ -0,0 +1,34 @@ +outputWriter->reset(); - $dtoList = $converterResult->dtoList; + $dtoList = $result->dtoList; foreach ($dtoList->getList() as $dto) { $this->outputWriter->writeType($this->convertToTypeScriptType($dto, $dtoList), $dto); } - $apiEndpointList = $converterResult->apiEndpointList; + $apiEndpointList = $result->apiEndpointList; foreach ($apiEndpointList->getList() as $apiEndpoint) { $this->outputWriter->writeApiEndpoint($this->apiEndpointGenerator->generate($apiEndpoint, $dtoList), $apiEndpoint); } diff --git a/tests/OutputGenerator/GoGeneratorTest.php b/tests/OutputGenerator/GoGeneratorTest.php new file mode 100644 index 0000000..1574c84 --- /dev/null +++ b/tests/OutputGenerator/GoGeneratorTest.php @@ -0,0 +1,319 @@ + <<<'CODE' + <<<'CODE' + <<<'CODE' + <<<'CODE' + <<<'CODE' + <<<'CODE' + <<<'CODE' +color; + } + + public function getUser(): int + { + return $this->user; + } +} +CODE, + ]; + + private GoOutputGenerator $gen1; // Only with ClassNameTypeResolver + + private GoOutputGenerator $gen2; // Without ClassNameTypeResolver + + private GoOutputGenerator $gen3; // With DateTimeTypeResolver and ClassNameTypeResolver + + protected function getSnapshotDirectory(): string + { + if ($this->snapshotSubDirectory === null) { + return ( + dirname((new ReflectionClass($this))->getFileName()) . + DIRECTORY_SEPARATOR . '__snapshots__' + ); + } + + return ( + dirname((new ReflectionClass($this))->getFileName()) . + DIRECTORY_SEPARATOR . '__snapshots__' . DIRECTORY_SEPARATOR . $this->snapshotSubDirectory + ); + } + + protected function setUp(): void + { + $this->snapshotSubDirectory = 'GoGeneratorTest/' . $this->name(); + + $this->gen1 = new GoOutputGenerator( + outputWriter: new SingleFileOutputWriter('generated.go'), + resolver: new GoTypeResolver([new ClassNameTypeResolver()]), + ); + + $this->gen2 = new GoOutputGenerator( + outputWriter: new SingleFileOutputWriter('generated.go'), + resolver: new GoTypeResolver([]), + ); + + $this->gen3 = new GoOutputGenerator( + outputWriter: new SingleFileOutputWriter('generated.go'), + resolver: new GoTypeResolver([new ClassNameTypeResolver(), new DateTimeTypeResolver()]) + ); + } + + public function testNormalization(): void + { + $converted = (new Converter([new DtoVisitor()]))->convert([self::TEMPLATES['testNormalization']]); + $this->assertMatchesJsonSnapshot($converted->dtoList->getList()); + $results = $this->gen2->generate($converted); + $this->assertCount(1, $results); + $this->assertMatchesSnapshot($results[0]->getContent(), new GoSnapshotComparator()); + } + + public function testNestedDtoConvert(): void + { + $converted = (new Converter([new DtoVisitor()]))->convert([self::TEMPLATES['nestedDtoConvert']]); + $results = $this->gen1->generate($converted); + $this->assertCount(1, $results); + $this->assertMatchesSnapshot($results[0]->getContent(), new GoSnapshotComparator()); + } + + public function testUseTypeEnum(): void + { + $normalized = (new Converter([new DtoVisitor()]))->convert([self::TEMPLATES['useTypeEnum']]); + $results = $this->gen1->generate($normalized); + $this->assertCount(1, $results); + $this->assertMatchesSnapshot($results[0]->getContent(), new GoSnapshotComparator()); + } + + public function testNormalizationDirectory(): void + { + $fileProvider = FileSystemCodeProvider::phpFiles(__DIR__ . '/Fixtures'); + $result = (new Converter([new DtoVisitor()]))->convert($fileProvider->getListings()); + $this->assertMatchesJsonSnapshot($result->dtoList->getList()); + $results = $this->gen1->generate($result); + $this->assertCount(1, $results); + $this->assertMatchesSnapshot($results[0]->getContent(), new GoSnapshotComparator()); + } + + public function testNormalizationWithCustomTypeResolvers(): void + { + $converted = (new Converter([new DtoVisitor()]))->convert([self::TEMPLATES['useDateTime']]); + $results = $this->gen3->generate($converted); + $this->assertCount(1, $results); + $this->assertMatchesSnapshot($results[0]->getContent(), new GoSnapshotComparator()); + } + + public function testUnknownTypeThrows(): void + { + $visitors = [new DtoVisitor(new PhpAttributeFilter('Dto'))]; + $result = (new Converter($visitors))->convert([self::TEMPLATES['unknownType']]); + $this->expectExceptionMessage('PHP Type B is not supported. PHP class: A'); + $this->gen3->generate($result); + } + + public function testDtoConstantDoesntThrow(): void + { + $visitors = [new DtoVisitor(new PhpAttributeFilter('Dto'))]; + $converted = (new Converter($visitors))->convert([self::TEMPLATES['dtoConstant']]); + $results = $this->gen3->generate($converted); + $this->assertMatchesSnapshot($results[0]->getContent(), new GoSnapshotComparator()); + } + + public function testPhp81SuccessWhenBacked(): void + { + $visitors = [new DtoVisitor(new PhpAttributeFilter('Dto'))]; + $result = (new Converter($visitors))->convert([self::TEMPLATES['backed']]); + $results = $this->gen1->generate($result); + $this->assertCount(1, $results); + $this->assertMatchesSnapshot($results[0]->getContent(), new GoSnapshotComparator()); + } +} diff --git a/tests/OutputGenerator/GoOutputGeneratorSimple.php b/tests/OutputGenerator/GoOutputGeneratorSimple.php index d7cca34..0cb1175 100644 --- a/tests/OutputGenerator/GoOutputGeneratorSimple.php +++ b/tests/OutputGenerator/GoOutputGeneratorSimple.php @@ -30,11 +30,11 @@ public function __construct( ) { } - public function generate(ConverterResult $converterResult): array + public function generate(ConverterResult $result): array { $this->outputWriter->reset(); - $dtoList = $converterResult->dtoList; + $dtoList = $result->dtoList; foreach ($dtoList->getList() as $dto) { $this->outputWriter->writeType($this->convertToGoType($dto, $dtoList), $dto); } diff --git a/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testDtoConstantDoesntThrow/GoGeneratorTest__testDtoConstantDoesntThrow__1.go b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testDtoConstantDoesntThrow/GoGeneratorTest__testDtoConstantDoesntThrow__1.go new file mode 100644 index 0000000..520e937 --- /dev/null +++ b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testDtoConstantDoesntThrow/GoGeneratorTest__testDtoConstantDoesntThrow__1.go @@ -0,0 +1,17 @@ +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! + +package gen + +type A struct { + CreatedAt string +} + +type GenderEnum int + +const ( + UNKNOWN GenderEnum = 2 + MAN GenderEnum = 0 + WOMAN GenderEnum = 1 +) diff --git a/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNestedDtoConvert/GoGeneratorTest__testNestedDtoConvert__1.go b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNestedDtoConvert/GoGeneratorTest__testNestedDtoConvert__1.go new file mode 100644 index 0000000..1e72a04 --- /dev/null +++ b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNestedDtoConvert/GoGeneratorTest__testNestedDtoConvert__1.go @@ -0,0 +1,25 @@ +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! + +package gen + +type FullName struct { + FirstName string + LastName string +} + +type Me struct { + Request *UserCreate +} + +type Profile struct { + Name *FullName + Age int +} + +type UserCreate struct { + Id string + Profile *Profile + Me *Me +} diff --git a/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalization/GoGeneratorTest__testNormalization__1.json b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalization/GoGeneratorTest__testNormalization__1.json new file mode 100644 index 0000000..632d765 --- /dev/null +++ b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalization/GoGeneratorTest__testNormalization__1.json @@ -0,0 +1,141 @@ +[ + { + "name": "CloudNotify", + "expressionType": { + "type": "class" + }, + "properties": [ + { + "type": { + "name": "string" + }, + "name": "id" + }, + { + "type": { + "types": [ + { + "name": "string" + }, + { + "name": "null" + } + ] + }, + "name": "fcmToken" + } + ], + "generics": [] + }, + { + "name": "Response", + "expressionType": { + "type": "class" + }, + "properties": [ + { + "type": { + "name": "mixed" + }, + "name": "data" + } + ], + "generics": [ + { + "name": "T", + "context": [], + "generics": [] + } + ] + }, + { + "name": "UserCreate", + "expressionType": { + "type": "class" + }, + "properties": [ + { + "type": { + "array": { + "name": "string" + } + }, + "name": "achievements" + }, + { + "type": { + "array": { + "array": { + "name": "int" + } + } + }, + "name": "matrix" + }, + { + "type": { + "types": [ + { + "name": "string" + }, + { + "name": "null" + } + ] + }, + "name": "name" + }, + { + "type": { + "types": [ + { + "name": "string" + }, + { + "name": "null" + } + ] + }, + "name": "duplicatesInType" + }, + { + "type": { + "name": "int" + }, + "name": "age" + }, + { + "type": { + "types": [ + { + "name": "bool" + }, + { + "name": "null" + } + ] + }, + "name": "isApproved" + }, + { + "type": { + "name": "float" + }, + "name": "latitude" + }, + { + "type": { + "name": "float" + }, + "name": "longitude" + }, + { + "type": { + "name": "mixed" + }, + "name": "mixed" + } + ], + "generics": [] + } +] diff --git a/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalization/GoGeneratorTest__testNormalization__2.go b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalization/GoGeneratorTest__testNormalization__2.go new file mode 100644 index 0000000..5081c99 --- /dev/null +++ b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalization/GoGeneratorTest__testNormalization__2.go @@ -0,0 +1,26 @@ +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! + +package gen + +type CloudNotify struct { + Id string + FcmToken *string +} + +type Response struct { + Data interface{} +} + +type UserCreate struct { + Achievements []string + Matrix [][]int + Name *string + DuplicatesInType *string + Age int + IsApproved *bool + Latitude float64 + Longitude float64 + Mixed interface{} +} diff --git a/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalizationDirectory/GoGeneratorTest__testNormalizationDirectory__1.json b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalizationDirectory/GoGeneratorTest__testNormalizationDirectory__1.json new file mode 100644 index 0000000..ac59b2c --- /dev/null +++ b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalizationDirectory/GoGeneratorTest__testNormalizationDirectory__1.json @@ -0,0 +1,276 @@ +[ + { + "name": "Activity", + "expressionType": { + "type": "class" + }, + "properties": [ + { + "type": { + "name": "string" + }, + "name": "id" + }, + { + "type": { + "name": "string" + }, + "name": "createdAt" + } + ], + "generics": [] + }, + { + "name": "FullName", + "expressionType": { + "type": "class" + }, + "properties": [ + { + "type": { + "name": "string" + }, + "name": "firstName" + }, + { + "type": { + "name": "string" + }, + "name": "lastName" + } + ], + "generics": [] + }, + { + "name": "NumberEnum", + "expressionType": { + "type": "enum-non-standard" + }, + "properties": [ + { + "name": "VIEW", + "value": 0 + }, + { + "name": "EDIT", + "value": 1 + }, + { + "name": "CREATE", + "value": 2 + } + ], + "generics": [] + }, + { + "name": "PermissionsEnum", + "expressionType": { + "type": "enum-non-standard" + }, + "properties": [ + { + "name": "VIEW", + "value": "view" + }, + { + "name": "EDIT", + "value": "edit" + } + ], + "generics": [] + }, + { + "name": "Profile", + "expressionType": { + "type": "class" + }, + "properties": [ + { + "type": { + "types": [ + { + "name": "FullName", + "context": [], + "generics": [] + }, + { + "name": "null" + } + ] + }, + "name": "name" + }, + { + "type": { + "name": "int" + }, + "name": "age" + } + ], + "generics": [] + }, + { + "name": "User", + "expressionType": { + "type": "class" + }, + "properties": [ + { + "type": { + "name": "string" + }, + "name": "id" + }, + { + "type": { + "types": [ + { + "name": "User", + "context": [], + "generics": [] + }, + { + "name": "null" + } + ] + }, + "name": "bestFriend" + }, + { + "type": { + "array": { + "name": "User", + "context": [], + "generics": [] + } + }, + "name": "friends" + }, + { + "type": { + "name": "self" + }, + "name": "selfProperty" + }, + { + "type": { + "name": "self" + }, + "name": "selfConstructor" + } + ], + "generics": [] + }, + { + "name": "UserCreate", + "expressionType": { + "type": "class" + }, + "properties": [ + { + "type": { + "name": "string" + }, + "name": "id" + }, + { + "type": { + "name": "PermissionsEnum", + "context": [], + "generics": [] + }, + "name": "permissions" + }, + { + "type": { + "types": [ + { + "name": "Profile", + "context": [], + "generics": [] + }, + { + "name": "null" + } + ] + }, + "name": "profile" + }, + { + "type": { + "name": "int" + }, + "name": "age" + }, + { + "type": { + "types": [ + { + "name": "string" + }, + { + "name": "null" + } + ] + }, + "name": "name" + }, + { + "type": { + "name": "float" + }, + "name": "latitude" + }, + { + "type": { + "name": "float" + }, + "name": "longitude" + }, + { + "type": { + "name": "array" + }, + "name": "achievements" + }, + { + "type": { + "array": { + "name": "string" + } + }, + "name": "tags" + }, + { + "type": { + "array": { + "name": "Activity", + "context": [], + "generics": [] + } + }, + "name": "activities" + }, + { + "type": { + "name": "mixed" + }, + "name": "mixed" + }, + { + "type": { + "types": [ + { + "name": "bool" + }, + { + "name": "null" + } + ] + }, + "name": "isApproved" + } + ], + "generics": [] + } +] diff --git a/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalizationDirectory/GoGeneratorTest__testNormalizationDirectory__2.go b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalizationDirectory/GoGeneratorTest__testNormalizationDirectory__2.go new file mode 100644 index 0000000..f4f8196 --- /dev/null +++ b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalizationDirectory/GoGeneratorTest__testNormalizationDirectory__2.go @@ -0,0 +1,58 @@ +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! + +package gen + +type Activity struct { + Id string + CreatedAt string +} + +type FullName struct { + FirstName string + LastName string +} + +type NumberEnum int + +const ( + VIEW NumberEnum = 0 + EDIT NumberEnum = 1 + CREATE NumberEnum = 2 +) + +type PermissionsEnum string + +const ( + VIEWPermissionsEnum PermissionsEnum = "view" + EDITPermissionsEnum PermissionsEnum = "edit" +) + +type Profile struct { + Name *FullName + Age int +} + +type User struct { + Id string + BestFriend *User + Friends []User + SelfProperty *User + SelfConstructor *User +} + +type UserCreate struct { + Id string + Permissions PermissionsEnum + Profile *Profile + Age int + Name *string + Latitude float64 + Longitude float64 + Achievements []interface{} + Tags []string + Activities []Activity + Mixed interface{} + IsApproved *bool +} diff --git a/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalizationWithCustomTypeResolvers/GoGeneratorTest__testNormalizationWithCustomTypeResolvers__1.go b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalizationWithCustomTypeResolvers/GoGeneratorTest__testNormalizationWithCustomTypeResolvers__1.go new file mode 100644 index 0000000..f43f8d6 --- /dev/null +++ b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testNormalizationWithCustomTypeResolvers/GoGeneratorTest__testNormalizationWithCustomTypeResolvers__1.go @@ -0,0 +1,17 @@ +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! + +package gen + +type UserCreate struct { + CreatedAt string + UpdatedAt string + PromotedAt *string +} + +type UserCreateConstructor struct { + CreatedAt string + UpdatedAt string + PromotedAt *string +} diff --git a/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testPhp81SuccessWhenBacked/GoGeneratorTest__testPhp81SuccessWhenBacked__1.go b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testPhp81SuccessWhenBacked/GoGeneratorTest__testPhp81SuccessWhenBacked__1.go new file mode 100644 index 0000000..c3fe7f8 --- /dev/null +++ b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testPhp81SuccessWhenBacked/GoGeneratorTest__testPhp81SuccessWhenBacked__1.go @@ -0,0 +1,27 @@ +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! + +package gen + +type Color int + +const ( + RED Color = 0 + BLUE Color = 1 + WHITE Color = 2 +) + +type Role string + +const ( + ADMIN Role = "admin" + EDITOR Role = "editor" + READER Role = "reader" +) + +type User struct { + Color Color + User int + Role Role +} diff --git a/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testUseTypeEnum/GoGeneratorTest__testUseTypeEnum__1.go b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testUseTypeEnum/GoGeneratorTest__testUseTypeEnum__1.go new file mode 100644 index 0000000..51eeb4a --- /dev/null +++ b/tests/OutputGenerator/__snapshots__/GoGeneratorTest/testUseTypeEnum/GoGeneratorTest__testUseTypeEnum__1.go @@ -0,0 +1,27 @@ +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! +// THE FILE WAS AUTOGENERATED USING PHP-CONVERTER. PLEASE DO NOT EDIT IT! + +package gen + +type ColorEnum int + +const ( + RED ColorEnum = 0 + GREEN ColorEnum = 1 + BLUE ColorEnum = 2 +) + +type RoleEnum string + +const ( + ADMIN RoleEnum = "admin" + READER RoleEnum = "reader" + EDITOR RoleEnum = "editor" +) + +type User struct { + Id string + ThemeColor ColorEnum + Role RoleEnum +} diff --git a/tests/SnapshotComparator/GoSnapshotComparator.php b/tests/SnapshotComparator/GoSnapshotComparator.php new file mode 100644 index 0000000..3a29b48 --- /dev/null +++ b/tests/SnapshotComparator/GoSnapshotComparator.php @@ -0,0 +1,15 @@ +