Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 642c346

Browse files
committed
v2 adds parameter, response, response header modules (#59)
* Adds parameter template and code to write it * Writes module for each parameter * Removes prependFormOrBodyParameters * Sample regenrated * Samples regenerated * Fixes readme example * simplifies setting items and additional_properties var names * Regenerates sample with fixed schema names * Samples regenerated * Fixes java docstirng typo * Fixes JavaModelTest tests * Fixes tests in JavaModelEnumTest * FIxes tests in JavaClientCodegenTest * FIxes tests in DefaultGeneratorTest * FIxes tests in DefaultCodegenTest * Adds HeaderParameterWithoutName to api_client * Sample regenerated, responses are now modules * Moves request body schemas to the root indentation level of the response modules * Adds code to generate response header modules * Updates fromParameter * Sample updated, fixed bug where form param was not seen as body * Samples regenerated * Fixes java tests
1 parent 2723564 commit 642c346

File tree

543 files changed

+11755
-4206
lines changed
  • modules/openapi-json-schema-generator/src
  • samples/openapi3/client/3_0_3_unit_test/python
    • docs/apis/tags
    • test/test_paths
      • test_response_body_post_additionalproperties_allows_a_schema_which_should_validate_response_body_for_content_types
      • test_response_body_post_additionalproperties_are_allowed_by_default_response_body_for_content_types
      • test_response_body_post_additionalproperties_can_exist_by_itself_response_body_for_content_types
      • test_response_body_post_additionalproperties_should_not_look_in_applicators_response_body_for_content_types
      • test_response_body_post_allof_combined_with_anyof_oneof_response_body_for_content_types
      • test_response_body_post_allof_response_body_for_content_types
      • test_response_body_post_allof_simple_types_response_body_for_content_types
      • test_response_body_post_allof_with_base_schema_response_body_for_content_types
      • test_response_body_post_allof_with_one_empty_schema_response_body_for_content_types
      • test_response_body_post_allof_with_the_first_empty_schema_response_body_for_content_types
      • test_response_body_post_allof_with_the_last_empty_schema_response_body_for_content_types
      • test_response_body_post_allof_with_two_empty_schemas_response_body_for_content_types
      • test_response_body_post_anyof_complex_types_response_body_for_content_types
      • test_response_body_post_anyof_response_body_for_content_types
      • test_response_body_post_anyof_with_base_schema_response_body_for_content_types
      • test_response_body_post_anyof_with_one_empty_schema_response_body_for_content_types
      • test_response_body_post_array_type_matches_arrays_response_body_for_content_types
      • test_response_body_post_boolean_type_matches_booleans_response_body_for_content_types
      • test_response_body_post_by_int_response_body_for_content_types
      • test_response_body_post_by_number_response_body_for_content_types
      • test_response_body_post_by_small_number_response_body_for_content_types
      • test_response_body_post_date_time_format_response_body_for_content_types
      • test_response_body_post_email_format_response_body_for_content_types
      • test_response_body_post_enum_with0_does_not_match_false_response_body_for_content_types
      • test_response_body_post_enum_with1_does_not_match_true_response_body_for_content_types
      • test_response_body_post_enum_with_escaped_characters_response_body_for_content_types
      • test_response_body_post_enum_with_false_does_not_match0_response_body_for_content_types
      • test_response_body_post_enum_with_true_does_not_match1_response_body_for_content_types
      • test_response_body_post_enums_in_properties_response_body_for_content_types
      • test_response_body_post_forbidden_property_response_body_for_content_types
      • test_response_body_post_hostname_format_response_body_for_content_types
      • test_response_body_post_integer_type_matches_integers_response_body_for_content_types
      • test_response_body_post_invalid_instance_should_not_raise_error_when_float_division_inf_response_body_for_content_types
      • test_response_body_post_invalid_string_value_for_default_response_body_for_content_types
      • test_response_body_post_ipv4_format_response_body_for_content_types
      • test_response_body_post_ipv6_format_response_body_for_content_types
      • test_response_body_post_json_pointer_format_response_body_for_content_types
      • test_response_body_post_maximum_validation_response_body_for_content_types
      • test_response_body_post_maximum_validation_with_unsigned_integer_response_body_for_content_types
      • test_response_body_post_maxitems_validation_response_body_for_content_types
      • test_response_body_post_maxlength_validation_response_body_for_content_types
      • test_response_body_post_maxproperties0_means_the_object_is_empty_response_body_for_content_types
      • test_response_body_post_maxproperties_validation_response_body_for_content_types
      • test_response_body_post_minimum_validation_response_body_for_content_types
      • test_response_body_post_minimum_validation_with_signed_integer_response_body_for_content_types
      • test_response_body_post_minitems_validation_response_body_for_content_types
      • test_response_body_post_minlength_validation_response_body_for_content_types
      • test_response_body_post_minproperties_validation_response_body_for_content_types
      • test_response_body_post_nested_allof_to_check_validation_semantics_response_body_for_content_types
      • test_response_body_post_nested_anyof_to_check_validation_semantics_response_body_for_content_types
      • test_response_body_post_nested_items_response_body_for_content_types
      • test_response_body_post_nested_oneof_to_check_validation_semantics_response_body_for_content_types
      • test_response_body_post_not_more_complex_schema_response_body_for_content_types
      • test_response_body_post_not_response_body_for_content_types
      • test_response_body_post_nul_characters_in_strings_response_body_for_content_types
      • test_response_body_post_null_type_matches_only_the_null_object_response_body_for_content_types
      • test_response_body_post_number_type_matches_numbers_response_body_for_content_types
      • test_response_body_post_object_properties_validation_response_body_for_content_types
      • test_response_body_post_object_type_matches_objects_response_body_for_content_types
      • test_response_body_post_oneof_complex_types_response_body_for_content_types
      • test_response_body_post_oneof_response_body_for_content_types
      • test_response_body_post_oneof_with_base_schema_response_body_for_content_types
      • test_response_body_post_oneof_with_empty_schema_response_body_for_content_types
      • test_response_body_post_oneof_with_required_response_body_for_content_types
      • test_response_body_post_pattern_is_not_anchored_response_body_for_content_types
      • test_response_body_post_pattern_validation_response_body_for_content_types
      • test_response_body_post_properties_with_escaped_characters_response_body_for_content_types
      • test_response_body_post_property_named_ref_that_is_not_a_reference_response_body_for_content_types
      • test_response_body_post_ref_in_additionalproperties_response_body_for_content_types
      • test_response_body_post_ref_in_allof_response_body_for_content_types
      • test_response_body_post_ref_in_anyof_response_body_for_content_types
      • test_response_body_post_ref_in_items_response_body_for_content_types
      • test_response_body_post_ref_in_not_response_body_for_content_types
      • test_response_body_post_ref_in_oneof_response_body_for_content_types
      • test_response_body_post_ref_in_property_response_body_for_content_types
      • test_response_body_post_required_default_validation_response_body_for_content_types
      • test_response_body_post_required_validation_response_body_for_content_types
      • test_response_body_post_required_with_empty_array_response_body_for_content_types
      • test_response_body_post_required_with_escaped_characters_response_body_for_content_types
      • test_response_body_post_simple_enum_validation_response_body_for_content_types
      • test_response_body_post_string_type_matches_strings_response_body_for_content_types
      • test_response_body_post_the_default_keyword_does_not_do_anything_if_the_property_is_missing_response_body_for_content_types
      • test_response_body_post_uniqueitems_false_validation_response_body_for_content_types
      • test_response_body_post_uniqueitems_validation_response_body_for_content_types
      • test_response_body_post_uri_format_response_body_for_content_types
      • test_response_body_post_uri_reference_format_response_body_for_content_types
      • test_response_body_post_uri_template_format_response_body_for_content_types
    • unit_test_api
      • paths
        • request_body_post_additionalproperties_allows_a_schema_which_should_validate_request_body/post/response_for_200
        • request_body_post_additionalproperties_are_allowed_by_default_request_body/post/response_for_200
        • request_body_post_additionalproperties_can_exist_by_itself_request_body/post/response_for_200
        • request_body_post_additionalproperties_should_not_look_in_applicators_request_body/post/response_for_200
        • request_body_post_allof_combined_with_anyof_oneof_request_body/post/response_for_200
        • request_body_post_allof_request_body/post/response_for_200
        • request_body_post_allof_simple_types_request_body/post/response_for_200
        • request_body_post_allof_with_base_schema_request_body/post/response_for_200
        • request_body_post_allof_with_one_empty_schema_request_body/post/response_for_200
        • request_body_post_allof_with_the_first_empty_schema_request_body/post/response_for_200
        • request_body_post_allof_with_the_last_empty_schema_request_body/post/response_for_200
        • request_body_post_allof_with_two_empty_schemas_request_body/post/response_for_200
        • request_body_post_anyof_complex_types_request_body/post/response_for_200
        • request_body_post_anyof_request_body/post/response_for_200
        • request_body_post_anyof_with_base_schema_request_body/post/response_for_200
        • request_body_post_anyof_with_one_empty_schema_request_body/post/response_for_200
        • request_body_post_array_type_matches_arrays_request_body/post/response_for_200
        • request_body_post_boolean_type_matches_booleans_request_body/post/response_for_200
        • request_body_post_by_int_request_body/post/response_for_200
        • request_body_post_by_number_request_body/post/response_for_200
        • request_body_post_by_small_number_request_body/post/response_for_200
        • request_body_post_date_time_format_request_body/post/response_for_200
        • request_body_post_email_format_request_body/post/response_for_200
        • request_body_post_enum_with0_does_not_match_false_request_body/post/response_for_200
        • request_body_post_enum_with1_does_not_match_true_request_body/post/response_for_200
        • request_body_post_enum_with_escaped_characters_request_body/post/response_for_200
        • request_body_post_enum_with_false_does_not_match0_request_body/post/response_for_200
        • request_body_post_enum_with_true_does_not_match1_request_body/post/response_for_200
        • request_body_post_enums_in_properties_request_body/post/response_for_200
        • request_body_post_forbidden_property_request_body/post/response_for_200
        • request_body_post_hostname_format_request_body/post/response_for_200
        • request_body_post_integer_type_matches_integers_request_body/post/response_for_200
        • request_body_post_invalid_instance_should_not_raise_error_when_float_division_inf_request_body/post/response_for_200
        • request_body_post_invalid_string_value_for_default_request_body/post/response_for_200
        • request_body_post_ipv4_format_request_body/post/response_for_200
        • request_body_post_ipv6_format_request_body/post/response_for_200
        • request_body_post_json_pointer_format_request_body/post/response_for_200
        • request_body_post_maximum_validation_request_body/post/response_for_200
        • request_body_post_maximum_validation_with_unsigned_integer_request_body/post/response_for_200
        • request_body_post_maxitems_validation_request_body/post/response_for_200
        • request_body_post_maxlength_validation_request_body/post/response_for_200
        • request_body_post_maxproperties0_means_the_object_is_empty_request_body/post/response_for_200
        • request_body_post_maxproperties_validation_request_body/post/response_for_200
        • request_body_post_minimum_validation_request_body/post/response_for_200
        • request_body_post_minimum_validation_with_signed_integer_request_body/post/response_for_200
        • request_body_post_minitems_validation_request_body/post/response_for_200
        • request_body_post_minlength_validation_request_body/post/response_for_200
        • request_body_post_minproperties_validation_request_body/post/response_for_200
        • request_body_post_nested_allof_to_check_validation_semantics_request_body/post/response_for_200
        • request_body_post_nested_anyof_to_check_validation_semantics_request_body/post/response_for_200
        • request_body_post_nested_items_request_body/post/response_for_200
        • request_body_post_nested_oneof_to_check_validation_semantics_request_body/post/response_for_200
        • request_body_post_not_more_complex_schema_request_body/post/response_for_200
        • request_body_post_not_request_body/post/response_for_200
        • request_body_post_nul_characters_in_strings_request_body/post/response_for_200
        • request_body_post_null_type_matches_only_the_null_object_request_body/post/response_for_200
        • request_body_post_number_type_matches_numbers_request_body/post/response_for_200
        • request_body_post_object_properties_validation_request_body/post/response_for_200
        • request_body_post_object_type_matches_objects_request_body/post/response_for_200
        • request_body_post_oneof_complex_types_request_body/post/response_for_200
        • request_body_post_oneof_request_body/post/response_for_200
        • request_body_post_oneof_with_base_schema_request_body/post/response_for_200
        • request_body_post_oneof_with_empty_schema_request_body/post/response_for_200
        • request_body_post_oneof_with_required_request_body/post/response_for_200
        • request_body_post_pattern_is_not_anchored_request_body/post/response_for_200
        • request_body_post_pattern_validation_request_body/post/response_for_200
        • request_body_post_properties_with_escaped_characters_request_body/post/response_for_200
        • request_body_post_property_named_ref_that_is_not_a_reference_request_body/post/response_for_200
        • request_body_post_ref_in_additionalproperties_request_body/post/response_for_200
        • request_body_post_ref_in_allof_request_body/post/response_for_200
        • request_body_post_ref_in_anyof_request_body/post/response_for_200
        • request_body_post_ref_in_items_request_body/post/response_for_200
        • request_body_post_ref_in_not_request_body/post/response_for_200
        • request_body_post_ref_in_oneof_request_body/post/response_for_200
        • request_body_post_ref_in_property_request_body/post/response_for_200
        • request_body_post_required_default_validation_request_body/post/response_for_200
        • request_body_post_required_validation_request_body/post/response_for_200
        • request_body_post_required_with_empty_array_request_body/post/response_for_200
        • request_body_post_required_with_escaped_characters_request_body/post/response_for_200
        • request_body_post_simple_enum_validation_request_body/post/response_for_200
        • request_body_post_string_type_matches_strings_request_body/post/response_for_200
        • request_body_post_the_default_keyword_does_not_do_anything_if_the_property_is_missing_request_body/post/response_for_200
        • request_body_post_uniqueitems_false_validation_request_body/post/response_for_200
        • request_body_post_uniqueitems_validation_request_body/post/response_for_200
        • request_body_post_uri_format_request_body/post/response_for_200
        • request_body_post_uri_reference_format_request_body/post/response_for_200
        • request_body_post_uri_template_format_request_body/post/response_for_200
        • response_body_post_additionalproperties_allows_a_schema_which_should_validate_response_body_for_content_types/post/response_for_200
        • response_body_post_additionalproperties_are_allowed_by_default_response_body_for_content_types/post/response_for_200
        • response_body_post_additionalproperties_can_exist_by_itself_response_body_for_content_types/post/response_for_200
        • response_body_post_additionalproperties_should_not_look_in_applicators_response_body_for_content_types/post/response_for_200
        • response_body_post_allof_combined_with_anyof_oneof_response_body_for_content_types/post/response_for_200
        • response_body_post_allof_response_body_for_content_types/post/response_for_200
        • response_body_post_allof_simple_types_response_body_for_content_types/post/response_for_200
        • response_body_post_allof_with_base_schema_response_body_for_content_types/post/response_for_200
        • response_body_post_allof_with_one_empty_schema_response_body_for_content_types/post/response_for_200
        • response_body_post_allof_with_the_first_empty_schema_response_body_for_content_types/post/response_for_200
        • response_body_post_allof_with_the_last_empty_schema_response_body_for_content_types/post/response_for_200
        • response_body_post_allof_with_two_empty_schemas_response_body_for_content_types/post/response_for_200
        • response_body_post_anyof_complex_types_response_body_for_content_types/post/response_for_200
        • response_body_post_anyof_response_body_for_content_types/post/response_for_200
        • response_body_post_anyof_with_base_schema_response_body_for_content_types/post/response_for_200
        • response_body_post_anyof_with_one_empty_schema_response_body_for_content_types/post/response_for_200
        • response_body_post_array_type_matches_arrays_response_body_for_content_types/post/response_for_200
        • response_body_post_boolean_type_matches_booleans_response_body_for_content_types/post/response_for_200
        • response_body_post_by_int_response_body_for_content_types/post/response_for_200
        • response_body_post_by_number_response_body_for_content_types/post/response_for_200
        • response_body_post_by_small_number_response_body_for_content_types/post/response_for_200
        • response_body_post_date_time_format_response_body_for_content_types/post/response_for_200
        • response_body_post_email_format_response_body_for_content_types/post/response_for_200
        • response_body_post_enum_with0_does_not_match_false_response_body_for_content_types/post/response_for_200
        • response_body_post_enum_with1_does_not_match_true_response_body_for_content_types/post/response_for_200
        • response_body_post_enum_with_escaped_characters_response_body_for_content_types/post/response_for_200
        • response_body_post_enum_with_false_does_not_match0_response_body_for_content_types/post/response_for_200
        • response_body_post_enum_with_true_does_not_match1_response_body_for_content_types/post/response_for_200
        • response_body_post_enums_in_properties_response_body_for_content_types/post/response_for_200
        • response_body_post_forbidden_property_response_body_for_content_types/post/response_for_200
        • response_body_post_hostname_format_response_body_for_content_types/post/response_for_200
        • response_body_post_integer_type_matches_integers_response_body_for_content_types/post/response_for_200
        • response_body_post_invalid_instance_should_not_raise_error_when_float_division_inf_response_body_for_content_types/post/response_for_200
        • response_body_post_invalid_string_value_for_default_response_body_for_content_types/post/response_for_200
        • response_body_post_ipv4_format_response_body_for_content_types/post/response_for_200
        • response_body_post_ipv6_format_response_body_for_content_types/post/response_for_200
        • response_body_post_json_pointer_format_response_body_for_content_types/post/response_for_200
        • response_body_post_maximum_validation_response_body_for_content_types/post/response_for_200
        • response_body_post_maximum_validation_with_unsigned_integer_response_body_for_content_types/post/response_for_200
        • response_body_post_maxitems_validation_response_body_for_content_types/post/response_for_200
        • response_body_post_maxlength_validation_response_body_for_content_types/post/response_for_200
        • response_body_post_maxproperties0_means_the_object_is_empty_response_body_for_content_types/post/response_for_200
        • response_body_post_maxproperties_validation_response_body_for_content_types/post/response_for_200
        • response_body_post_minimum_validation_response_body_for_content_types/post/response_for_200
        • response_body_post_minimum_validation_with_signed_integer_response_body_for_content_types/post/response_for_200
        • response_body_post_minitems_validation_response_body_for_content_types/post/response_for_200
        • response_body_post_minlength_validation_response_body_for_content_types/post/response_for_200
        • response_body_post_minproperties_validation_response_body_for_content_types/post/response_for_200
        • response_body_post_nested_allof_to_check_validation_semantics_response_body_for_content_types/post/response_for_200
        • response_body_post_nested_anyof_to_check_validation_semantics_response_body_for_content_types/post/response_for_200
        • response_body_post_nested_items_response_body_for_content_types/post/response_for_200
        • response_body_post_nested_oneof_to_check_validation_semantics_response_body_for_content_types/post/response_for_200
        • response_body_post_not_more_complex_schema_response_body_for_content_types/post/response_for_200
        • response_body_post_not_response_body_for_content_types/post/response_for_200
        • response_body_post_nul_characters_in_strings_response_body_for_content_types/post/response_for_200
        • response_body_post_null_type_matches_only_the_null_object_response_body_for_content_types/post/response_for_200
        • response_body_post_number_type_matches_numbers_response_body_for_content_types/post/response_for_200
        • response_body_post_object_properties_validation_response_body_for_content_types/post/response_for_200
        • response_body_post_object_type_matches_objects_response_body_for_content_types/post/response_for_200
        • response_body_post_oneof_complex_types_response_body_for_content_types/post/response_for_200
        • response_body_post_oneof_response_body_for_content_types/post/response_for_200
        • response_body_post_oneof_with_base_schema_response_body_for_content_types/post/response_for_200
        • response_body_post_oneof_with_empty_schema_response_body_for_content_types/post/response_for_200
        • response_body_post_oneof_with_required_response_body_for_content_types/post/response_for_200
        • response_body_post_pattern_is_not_anchored_response_body_for_content_types/post/response_for_200
        • response_body_post_pattern_validation_response_body_for_content_types/post/response_for_200
        • response_body_post_properties_with_escaped_characters_response_body_for_content_types/post/response_for_200
        • response_body_post_property_named_ref_that_is_not_a_reference_response_body_for_content_types/post/response_for_200
        • response_body_post_ref_in_additionalproperties_response_body_for_content_types/post/response_for_200
        • response_body_post_ref_in_allof_response_body_for_content_types/post/response_for_200
        • response_body_post_ref_in_anyof_response_body_for_content_types/post/response_for_200
        • response_body_post_ref_in_items_response_body_for_content_types/post/response_for_200
        • response_body_post_ref_in_not_response_body_for_content_types/post/response_for_200
        • response_body_post_ref_in_oneof_response_body_for_content_types/post/response_for_200
        • response_body_post_ref_in_property_response_body_for_content_types/post/response_for_200
        • response_body_post_required_default_validation_response_body_for_content_types/post/response_for_200

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

543 files changed

+11755
-4206
lines changed

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

+21-62
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ apiTemplateFiles are for API outputs only (controllers/handlers).
242242
protected Map<String, String> specialCharReplacements = new LinkedHashMap<>();
243243
// When a model is an alias for a simple type
244244
protected Map<String, String> typeAliases = null;
245-
protected Boolean prependFormOrBodyParameters = false;
246245
// The extension of the generated documentation files (defaults to markdown .md)
247246
protected String docExtension;
248247
protected String ignoreFilePathOverride;
@@ -338,11 +337,6 @@ public void processOpts() {
338337
.get(CodegenConstants.SORT_MODEL_PROPERTIES_BY_REQUIRED_FLAG).toString()));
339338
}
340339

341-
if (additionalProperties.containsKey(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS)) {
342-
this.setPrependFormOrBodyParameters(Boolean.valueOf(additionalProperties
343-
.get(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS).toString()));
344-
}
345-
346340
if (additionalProperties.containsKey(CodegenConstants.ENSURE_UNIQUE_PARAMS)) {
347341
this.setEnsureUniqueParams(Boolean.valueOf(additionalProperties
348342
.get(CodegenConstants.ENSURE_UNIQUE_PARAMS).toString()));
@@ -1339,15 +1333,6 @@ public Boolean getSortModelPropertiesByRequiredFlag() {
13391333
public void setSortModelPropertiesByRequiredFlag(Boolean sortModelPropertiesByRequiredFlag) {
13401334
this.sortModelPropertiesByRequiredFlag = sortModelPropertiesByRequiredFlag;
13411335
}
1342-
1343-
public Boolean getPrependFormOrBodyParameters() {
1344-
return prependFormOrBodyParameters;
1345-
}
1346-
1347-
public void setPrependFormOrBodyParameters(Boolean prependFormOrBodyParameters) {
1348-
this.prependFormOrBodyParameters = prependFormOrBodyParameters;
1349-
}
1350-
13511336
public Boolean getEnsureUniqueParams() {
13521337
return ensureUniqueParams;
13531338
}
@@ -2934,7 +2919,7 @@ public CodegenModel fromModel(String name, Schema schema) {
29342919
m.setFormat(schema.getFormat());
29352920
m.setComposedSchemas(getComposedSchemas(schema));
29362921
if (ModelUtils.isArraySchema(schema)) {
2937-
CodegenProperty arrayProperty = fromProperty(name, schema, false);
2922+
CodegenProperty arrayProperty = fromProperty("items", schema, false);
29382923
m.setItems(arrayProperty.items);
29392924
m.arrayModelType = arrayProperty.complexType;
29402925
addParentContainer(m, name, schema);
@@ -4259,7 +4244,7 @@ public CodegenOperation fromOperation(String path,
42594244
for (Entry<String, Header> entry : headers.entrySet()) {
42604245
String headerName = entry.getKey();
42614246
Header header = ModelUtils.getReferencedHeader(this.openAPI, entry.getValue());
4262-
CodegenParameter responseHeader = headerToCodegenParameter(header, headerName, r.imports, String.format(Locale.ROOT, "%sResponseParameter", r.code));
4247+
CodegenParameter responseHeader = headerToCodegenParameter(header, headerName, r.imports, "");
42634248
responseHeaders.add(responseHeader);
42644249
}
42654250
r.setResponseHeaders(responseHeaders);
@@ -4348,11 +4333,8 @@ public CodegenOperation fromOperation(String path,
43484333
setParameterEncodingValues(cp, requestBody.getContent().get(contentType));
43494334
postProcessParameter(cp);
43504335
}
4351-
// add form parameters to the beginning of all parameter list
4352-
if (prependFormOrBodyParameters) {
4353-
for (CodegenParameter cp : formParams) {
4354-
allParams.add(cp.copy());
4355-
}
4336+
if (formParams.size() == 1) {
4337+
bodyParam = formParams.get(0);
43564338
}
43574339
} else {
43584340
// process body parameter
@@ -4368,10 +4350,6 @@ public CodegenOperation fromOperation(String path,
43684350

43694351
bodyParams.add(bodyParam);
43704352

4371-
if (prependFormOrBodyParameters) {
4372-
allParams.add(bodyParam);
4373-
}
4374-
43754353
// add example
43764354
if (schemas != null && !isSkipOperationExample()) {
43774355
op.requestBodyExamples = new ExampleGenerator(schemas, this.openAPI).generate(null, new ArrayList<>(getConsumesInfo(this.openAPI, operation)), bodyParam.baseType);
@@ -4380,20 +4358,14 @@ public CodegenOperation fromOperation(String path,
43804358
}
43814359

43824360
if (parameters != null) {
4361+
Integer i = 0;
43834362
for (Parameter param : parameters) {
43844363
param = ModelUtils.getReferencedParameter(this.openAPI, param);
43854364

4386-
CodegenParameter p = fromParameter(param, imports);
4387-
p.setContent(getContent(param.getContent(), imports, param.getName()));
4388-
4389-
// ensure unique params
4390-
if (ensureUniqueParams) {
4391-
while (!isParameterNameUnique(p, allParams)) {
4392-
p.paramName = generateNextName(p.paramName);
4393-
}
4394-
}
4395-
4365+
CodegenParameter p = fromParameter(param, imports, i.toString());
4366+
p.setContent(getContent(param.getContent(), imports, "schema"));
43964367
allParams.add(p);
4368+
i++;
43974369

43984370
if (param instanceof QueryParameter || "query".equalsIgnoreCase(param.getIn())) {
43994371
queryParams.add(p.copy());
@@ -4410,27 +4382,6 @@ public CodegenOperation fromOperation(String path,
44104382
}
44114383
}
44124384

4413-
// add form/body parameter (if any) to the end of all parameter list
4414-
if (!prependFormOrBodyParameters) {
4415-
for (CodegenParameter cp : formParams) {
4416-
if (ensureUniqueParams) {
4417-
while (!isParameterNameUnique(cp, allParams)) {
4418-
cp.paramName = generateNextName(cp.paramName);
4419-
}
4420-
}
4421-
allParams.add(cp.copy());
4422-
}
4423-
4424-
for (CodegenParameter cp : bodyParams) {
4425-
if (ensureUniqueParams) {
4426-
while (!isParameterNameUnique(cp, allParams)) {
4427-
cp.paramName = generateNextName(cp.paramName);
4428-
}
4429-
}
4430-
allParams.add(cp.copy());
4431-
}
4432-
}
4433-
44344385
// create optional, required parameters
44354386
for (CodegenParameter cp : allParams) {
44364387
if (cp.required) { //required parameters
@@ -4440,6 +4391,14 @@ public CodegenOperation fromOperation(String path,
44404391
op.hasOptionalParams = true;
44414392
}
44424393
}
4394+
if (bodyParam != null) {
4395+
if (bodyParam.required) {
4396+
requiredParams.add(bodyParam.copy());
4397+
} else {
4398+
optionalParams.add(bodyParam.copy());
4399+
op.hasOptionalParams = true;
4400+
}
4401+
}
44434402

44444403
// add imports to operation import tag
44454404
for (String i : imports) {
@@ -4811,7 +4770,7 @@ protected void updateParameterForString(CodegenParameter codegenParameter, Schem
48114770
* @param imports set of imports for library/package/module
48124771
* @return Codegen Parameter object
48134772
*/
4814-
public CodegenParameter fromParameter(Parameter parameter, Set<String> imports) {
4773+
public CodegenParameter fromParameter(Parameter parameter, Set<String> imports, String priorJsonPathFragment) {
48154774
CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
48164775

48174776
codegenParameter.baseName = parameter.getName();
@@ -4845,9 +4804,9 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
48454804
parameterModelName = getParameterDataType(parameter, parameterSchema);
48464805
CodegenProperty prop;
48474806
if (getUseInlineModelResolver()) {
4848-
prop = fromProperty(parameter.getName(), getReferencedSchemaWhenNotEnum(parameterSchema), false);
4807+
prop = fromProperty("schema", getReferencedSchemaWhenNotEnum(parameterSchema), false);
48494808
} else {
4850-
prop = fromProperty(parameter.getName(), parameterSchema, false);
4809+
prop = fromProperty("schema", parameterSchema, false);
48514810
}
48524811
codegenParameter.setSchema(prop);
48534812
if (addSchemaImportsFromV3SpecLocations) {
@@ -5036,7 +4995,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
50364995
if ("multi".equals(collectionFormat)) {
50374996
codegenParameter.isCollectionFormatMulti = true;
50384997
}
5039-
codegenParameter.paramName = toParamName(parameter.getName());
4998+
codegenParameter.paramName = toParamName(priorJsonPathFragment);
50404999
if (!addSchemaImportsFromV3SpecLocations) {
50415000
// import
50425001
if (codegenProperty.complexType != null) {
@@ -7105,7 +7064,7 @@ private CodegenParameter headerToCodegenParameter(Header header, String headerNa
71057064
headerParam.setExample(header.getExample());
71067065
headerParam.setContent(header.getContent());
71077066
headerParam.setExtensions(header.getExtensions());
7108-
CodegenParameter param = fromParameter(headerParam, imports);
7067+
CodegenParameter param = fromParameter(headerParam, imports, headerName);
71097068
param.setContent(getContent(headerParam.getContent(), imports, mediaTypeSchemaSuffix));
71107069
return param;
71117070
}

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java

+44-5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868

6969
import static org.openapitools.codegen.utils.OnceLogger.once;
7070
import static org.openapitools.codegen.utils.StringUtils.camelize;
71+
import static org.openapitools.codegen.utils.StringUtils.escape;
7172
import static org.openapitools.codegen.utils.StringUtils.underscore;
7273

7374
public class PythonClientCodegen extends AbstractPythonCodegen {
@@ -114,7 +115,10 @@ public PythonClientCodegen() {
114115
importBaseType = false;
115116
addSchemaImportsFromV3SpecLocations = true;
116117
sortModelPropertiesByRequiredFlag = Boolean.TRUE;
117-
sortParamsByRequiredFlag = Boolean.TRUE;
118+
// this must be false for parameter numbers to stay the same as the ones in the spec
119+
// if another schema $refs a schema in a parameter, the json path
120+
// and generated module must have the same parameter index as the spec
121+
sortParamsByRequiredFlag = Boolean.FALSE;
118122
addSuffixToDuplicateOperationNicknames = false;
119123

120124
modifyFeatureSet(features -> features
@@ -590,9 +594,23 @@ protected void generateEndpoints(OperationsMap objs) {
590594
outputFilename = packageFilename(Arrays.asList("paths", pathModuleName, co.httpMethod, "request_body.py"));
591595
pathsFiles.add(Arrays.asList(paramMap, "endpoint_request_body.handlebars", outputFilename));
592596
}
597+
// paths.some_path.post.parameter_0.py
598+
Integer i = 0;
599+
for (CodegenParameter cp: co.allParams) {
600+
Map<String, Object> paramMap = new HashMap<>();
601+
paramMap.put("parameter", cp);
602+
// TODO consolidate imports into body param only
603+
paramMap.put("imports", co.imports);
604+
paramMap.put("packageName", packageName);
605+
outputFilename = packageFilename(Arrays.asList("paths", pathModuleName, co.httpMethod, toParamName(i.toString())+".py"));
606+
pathsFiles.add(Arrays.asList(paramMap, "endpoint_parameter.handlebars", outputFilename));
607+
i++;
608+
}
593609

594610
for (CodegenResponse response: co.responses) {
595-
// paths.some_path.post.response_for_200.py (file per response)
611+
// paths.some_path.post.response_for_200.__init__.py (file per response)
612+
// response is a package because responses have Headers which can be refed
613+
// so each inline header should be a module in the response package
596614
Map<String, Object> responseMap = new HashMap<>();
597615
responseMap.put("response", response);
598616
responseMap.put("packageName", packageName);
@@ -602,8 +620,17 @@ protected void generateEndpoints(OperationsMap objs) {
602620
} else {
603621
responseModuleName += response.code;
604622
}
605-
String responseFilename = packageFilename(Arrays.asList("paths", pathModuleName, co.httpMethod, responseModuleName+ ".py"));
623+
String responseFilename = packageFilename(Arrays.asList("paths", pathModuleName, co.httpMethod, responseModuleName, "__init__.py"));
606624
pathsFiles.add(Arrays.asList(responseMap, "endpoint_response.handlebars", responseFilename));
625+
for (CodegenParameter header: response.getResponseHeaders()) {
626+
Map<String, Object> headerMap = new HashMap<>();
627+
headerMap.put("parameter", header);
628+
// TODO consolidate imports into header param only
629+
headerMap.put("imports", co.imports);
630+
headerMap.put("packageName", packageName);
631+
String headerFilename = packageFilename(Arrays.asList("paths", pathModuleName, co.httpMethod, responseModuleName, toParamName(header.baseName) + ".py"));
632+
pathsFiles.add(Arrays.asList(headerMap, "endpoint_response_header.handlebars", headerFilename));
633+
}
607634
}
608635
/*
609636
This stub file exists to allow pycharm to read and use typing.overload decorators for it to see that
@@ -940,8 +967,8 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
940967
return objs;
941968
}
942969

943-
public CodegenParameter fromParameter(Parameter parameter, Set<String> imports) {
944-
CodegenParameter cp = super.fromParameter(parameter, imports);
970+
public CodegenParameter fromParameter(Parameter parameter, Set<String> imports, String priorJsonPathFragment) {
971+
CodegenParameter cp = super.fromParameter(parameter, imports, priorJsonPathFragment);
945972
if (parameter.getStyle() != null) {
946973
switch(parameter.getStyle()) {
947974
case MATRIX:
@@ -2742,6 +2769,18 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
27422769
return objs;
27432770
}
27442771

2772+
@Override
2773+
public String toParamName(String name) {
2774+
try {
2775+
Integer.parseInt(name);
2776+
// for parameters in path, or an endpoint
2777+
return "parameter_" + name;
2778+
} catch (NumberFormatException nfe) {
2779+
// for header parameters in responses
2780+
return "parameter_" + toModelFilename(name);
2781+
}
2782+
}
2783+
27452784
@Override
27462785
public void postProcess() {
27472786
System.out.println("################################################################################");

modules/openapi-json-schema-generator/src/main/resources/python/README_common.handlebars

+1-25
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,16 @@
1-
```python
2-
{{#with apiInfo}}{{#each apis}}{{#unless hasMore}}{{#if hasHttpSignatureMethods}}import datetime{{/if}}{{/unless}}{{/each}}{{/with}}
3-
import time
4-
import {{{packageName}}}
5-
from pprint import pprint
61
{{#with apiInfo}}
72
{{#each apis}}
83
{{#if @first}}
9-
from {{packageName}}.{{apiPackage}}.tags import {{classFilename}}
10-
{{#each imports}}
11-
{{{import}}}
12-
{{/each}}
134
{{#with operations}}
145
{{#each operation}}
156
{{#if @first}}
16-
{{> doc_auth_partial}}
17-
18-
# Enter a context with an instance of the API client
19-
with {{{packageName}}}.ApiClient(configuration) as api_client:
20-
# Create an instance of the API class
21-
api_instance = {{classFilename}}.{{{classname}}}(api_client)
22-
{{#each allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{#unless required}} (optional){{/unless}}{{#if defaultValue}} (default to {{{.}}}){{/if}}
23-
{{/each}}
24-
25-
try:
26-
{{#if summary}} # {{{summary}}}
27-
{{/if}} {{#if returnType}}api_response = {{/if}}api_instance.{{{operationId}}}({{#each allParams}}{{#if required}}{{paramName}}{{/if}}{{#unless required}}{{paramName}}={{paramName}}{{/unless}}{{#if hasMore}}, {{/if}}{{/each}}){{#if returnType}}
28-
pprint(api_response){{/if}}
29-
except {{{packageName}}}.ApiException as e:
30-
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
7+
{{> api_doc_example }}
318
{{/if}}
329
{{/each}}
3310
{{/with}}
3411
{{/if}}
3512
{{/each}}
3613
{{/with}}
37-
```
3814

3915
## Documentation for API Endpoints
4016

0 commit comments

Comments
 (0)