diff --git a/src/zcl_aff_abap_doc_parser.clas.abap b/src/zcl_aff_abap_doc_parser.clas.abap index dbe5a4ae..050a3a7a 100644 --- a/src/zcl_aff_abap_doc_parser.clas.abap +++ b/src/zcl_aff_abap_doc_parser.clas.abap @@ -555,7 +555,7 @@ CLASS zcl_aff_abap_doc_parser IMPLEMENTATION. DATA(string_to_parse) = abap_doc_string. - FIND ALL OCCURRENCES OF PCRE `\$pattern[\s]*(:[\s]*)?'([^']*)'` IN string_to_parse RESULTS DATA(result_table). + FIND ALL OCCURRENCES OF PCRE `\$pattern[\s]*(:[\s]*)?'(\S*)'` IN string_to_parse RESULTS DATA(result_table). IF lines( result_table ) = 0. DATA(msg) = parser_log->get_message_text( msgno = 109 msgv1 = CONV #( abap_doc_annotation-pattern ) ). diff --git a/src/zcl_aff_abap_doc_parser.clas.testclasses.abap b/src/zcl_aff_abap_doc_parser.clas.testclasses.abap index fd1e4377..4d00e71e 100644 --- a/src/zcl_aff_abap_doc_parser.clas.testclasses.abap +++ b/src/zcl_aff_abap_doc_parser.clas.testclasses.abap @@ -658,7 +658,6 @@ CLASS ltcl_aff_abap_doc_parser IMPLEMENTATION. exp_text = |There are several occurrences of annotation { zcl_aff_abap_doc_parser=>abap_doc_annotation-pattern } . First valid is used| exp_type = zif_aff_log=>c_message_type-info exp_component_name = `Component Name` ). - ENDMETHOD. ENDCLASS. diff --git a/src/zcl_aff_test_types.clas.abap b/src/zcl_aff_test_types.clas.abap index ea787758..1a58bd01 100644 --- a/src/zcl_aff_test_types.clas.abap +++ b/src/zcl_aff_test_types.clas.abap @@ -68,7 +68,7 @@ CLASS zcl_aff_test_types DEFINITION END OF struc_link_wrong_type. TYPES: - "! $pattern '[a-Z]*' + "! $pattern '[a-z]*' ty_string TYPE string. TYPES: @@ -86,10 +86,30 @@ CLASS zcl_aff_test_types DEFINITION BEGIN OF string_pattern_simple, "!

String with pattern

"! description - "! $pattern '[a-Z]*' + "! $pattern '[a-z]*' string_pattern TYPE string, END OF string_pattern_simple. + TYPES: + "!

Structure With Pattern Annotation

+ "! Structure with pattern annotation + BEGIN OF string_pattern_escape_sequence, + "!

String with pattern

+ "! description + "! $pattern '\n\t\r' + string_pattern TYPE string, + END OF string_pattern_escape_sequence. + + TYPES: + "!

Structure With Pattern Annotation

+ "! Structure with pattern annotation + BEGIN OF string_pattern_quotes, + "!

String with pattern

+ "! description + "! $pattern '"\"'' + string_pattern TYPE string, + END OF string_pattern_quotes. + TYPES: "! in ST val(I()) only allow integers "! $values {@link zcl_aff_test_types.data:co_enum} diff --git a/src/zcl_aff_writer_json_schema.clas.abap b/src/zcl_aff_writer_json_schema.clas.abap index af50361d..0f0639e2 100644 --- a/src/zcl_aff_writer_json_schema.clas.abap +++ b/src/zcl_aff_writer_json_schema.clas.abap @@ -441,6 +441,8 @@ CLASS zcl_aff_writer_json_schema IMPLEMENTATION. ENDIF. ENDIF. IF abap_doc-pattern IS NOT INITIAL. + REPLACE ALL OCCURRENCES OF '\' IN abap_doc-pattern WITH '\\'. + REPLACE ALL OCCURRENCES OF '"' IN abap_doc-pattern WITH '\"'. write_tag( |"pattern": "{ abap_doc-pattern }",| ). ENDIF. ENDMETHOD. diff --git a/src/zcl_aff_writer_json_schema.clas.testclasses.abap b/src/zcl_aff_writer_json_schema.clas.testclasses.abap index 6693ce58..4959ccdd 100644 --- a/src/zcl_aff_writer_json_schema.clas.testclasses.abap +++ b/src/zcl_aff_writer_json_schema.clas.testclasses.abap @@ -561,7 +561,9 @@ CLASS ltcl_json_writer_abap_doc DEFINITION FINAL FOR TESTING content_media_type_string FOR TESTING RAISING cx_static_check, encoding_type_next_level FOR TESTING RAISING cx_static_check, pattern_simple FOR TESTING RAISING cx_static_check, - pattern_complex FOR TESTING RAISING cx_static_check. + pattern_complex FOR TESTING RAISING cx_static_check, + pattern_escape_sequence FOR TESTING RAISING cx_static_check, + pattern_with_quotes FOR TESTING RAISING cx_static_check. ENDCLASS. @@ -2806,7 +2808,7 @@ CLASS ltcl_json_writer_abap_doc IMPLEMENTATION. ( ` "title": "String with pattern",` ) ( ` "description": "description",` ) ( ` "type": "string", ` ) - ( ` "pattern": "[a-Z]*" ` ) + ( ` "pattern": "[a-z]*" ` ) ( ` } ` ) ( ` }, ` ) ( ` "additionalProperties": false ` ) @@ -2832,7 +2834,59 @@ CLASS ltcl_json_writer_abap_doc IMPLEMENTATION. ( ` "title": "String with pattern",` ) ( ` "description": "description",` ) ( ` "type": "string", ` ) - ( ` "pattern": "[a-Z]*" ` ) + ( ` "pattern": "[a-z]*" ` ) + ( ` } ` ) + ( ` }, ` ) + ( ` "additionalProperties": false ` ) + ( ` } ` ) + ( ) ). + zcl_aff_tools_unit_test_helper=>assert_equals_ignore_spaces( act_data = act_schema exp_data = exp_schema ). + log = cut->zif_aff_writer~get_log( ). + zcl_aff_tools_unit_test_helper=>assert_log_has_no_message( log = log message_severity_threshold = zif_aff_log=>c_message_type-info ). + ENDMETHOD. + + METHOD pattern_escape_sequence. + DATA(act_schema) = test_generator->generate_type( VALUE zcl_aff_test_types=>string_pattern_escape_sequence( ) ). + DATA(exp_schema) = VALUE string_table( + ( ` { ` ) + ( | "$comment": "This file is autogenerated, do not edit manually, see { zcl_aff_writer_json_schema=>c_link_to_repository } for more information.", | ) + ( | "$schema": "{ zcl_aff_writer_json_schema=>c_schema_specification }",| ) + ( | "$id": "{ schema_id }",| ) + ( ` "title": "Structure With Pattern Annotation", ` ) + ( ` "description": "Structure with pattern annotation", ` ) + ( ` "type": "object", ` ) + ( ` "properties": { ` ) + ( ` "stringPattern": { ` ) + ( ` "title": "String with pattern",` ) + ( ` "description": "description",` ) + ( ` "type": "string", ` ) + ( ` "pattern": "\\n\\t\\r" ` ) + ( ` } ` ) + ( ` }, ` ) + ( ` "additionalProperties": false ` ) + ( ` } ` ) + ( ) ). + zcl_aff_tools_unit_test_helper=>assert_equals_ignore_spaces( act_data = act_schema exp_data = exp_schema ). + log = cut->zif_aff_writer~get_log( ). + zcl_aff_tools_unit_test_helper=>assert_log_has_no_message( log = log message_severity_threshold = zif_aff_log=>c_message_type-info ). + ENDMETHOD. + + METHOD pattern_with_quotes. + DATA(act_schema) = test_generator->generate_type( VALUE zcl_aff_test_types=>string_pattern_quotes( ) ). + DATA(exp_schema) = VALUE string_table( + ( ` { ` ) + ( | "$comment": "This file is autogenerated, do not edit manually, see { zcl_aff_writer_json_schema=>c_link_to_repository } for more information.", | ) + ( | "$schema": "{ zcl_aff_writer_json_schema=>c_schema_specification }",| ) + ( | "$id": "{ schema_id }",| ) + ( ` "title": "Structure With Pattern Annotation", ` ) + ( ` "description": "Structure with pattern annotation", ` ) + ( ` "type": "object", ` ) + ( ` "properties": { ` ) + ( ` "stringPattern": { ` ) + ( ` "title": "String with pattern",` ) + ( ` "description": "description",` ) + ( ` "type": "string", ` ) + ( ` "pattern": "\"\\\"'" ` ) ( ` } ` ) ( ` }, ` ) ( ` "additionalProperties": false ` )