Skip to content

Commit

Permalink
Merge pull request #1 from OberstVonGatow/Bugfix-Returning-Typenames
Browse files Browse the repository at this point in the history
Bugfix returning typenames
  • Loading branch information
OberstVonGatow authored Oct 26, 2023
2 parents 21c6a58 + 2f6986e commit d95f962
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 201 deletions.
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
},
"homepage": "https://github.com/abap-openapi/abap-openapi-client#readme",
"dependencies": {
"@abaplint/cli": "^2.101.8",
"@abaplint/runtime": "^2.7.20",
"@abaplint/transpiler-cli": "^2.7.20",
"@abaplint/cli": "^2.102.17",
"@abaplint/runtime": "^2.7.70",
"@abaplint/transpiler-cli": "^2.7.70",
"rimraf": "^5.0.1"
}
}
75 changes: 43 additions & 32 deletions src/utils/zcl_oapi_abap_name.clas.abap
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
CLASS zcl_oapi_abap_name DEFINITION PUBLIC.
CLASS zcl_oapi_abap_name DEFINITION
PUBLIC
CREATE PUBLIC.

PUBLIC SECTION.

METHODS to_abap_name
IMPORTING iv_name TYPE string
RETURNING VALUE(rv_name) TYPE string.
METHODS add_used IMPORTING iv_name TYPE string.
IMPORTING
!iv_name TYPE string
RETURNING
VALUE(rv_name) TYPE string.
METHODS add_used
IMPORTING
!iv_name TYPE string.
METHODS is_used
IMPORTING iv_name TYPE string
RETURNING VALUE(rv_used) TYPE abap_bool.
IMPORTING
!iv_name TYPE string
RETURNING
VALUE(rv_used) TYPE abap_bool.
PROTECTED SECTION.
PRIVATE SECTION.
TYPES ty_name TYPE c LENGTH 30.
TYPES ty_name TYPE c LENGTH 28.
DATA mt_used TYPE STANDARD TABLE OF string WITH DEFAULT KEY.
METHODS numbering IMPORTING iv_name TYPE string RETURNING VALUE(rv_name) TYPE ty_name.
METHODS sanitize_name
Expand All @@ -29,12 +39,27 @@ CLASS zcl_oapi_abap_name IMPLEMENTATION.
ENDMETHOD.


METHOD is_used.
DATA lv_name TYPE string.
IF iv_name IS INITIAL.
RETURN.
ENDIF.
lv_name = sanitize_name( iv_name ).
READ TABLE mt_used WITH KEY table_line = lv_name TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
rv_used = abap_true.
RETURN.
ENDIF.
rv_used = abap_false.
ENDMETHOD.


METHOD numbering.
DATA lv_number TYPE n LENGTH 2.
DATA lv_offset TYPE i.
lv_offset = strlen( iv_name ).
IF lv_offset > 28.
lv_offset = 28.
IF lv_offset > 26.
lv_offset = 26.
ENDIF.
DO 99 TIMES.
lv_number = sy-index.
Expand All @@ -49,17 +74,6 @@ CLASS zcl_oapi_abap_name IMPLEMENTATION.
ENDMETHOD.


METHOD to_abap_name.
IF iv_name IS INITIAL.
RETURN.
ENDIF.
rv_name = sanitize_name( iv_name ).
IF is_used( rv_name ) = abap_true.
rv_name = numbering( rv_name ).
ENDIF.
APPEND rv_name TO mt_used.
ENDMETHOD.

METHOD sanitize_name.
rv_name = to_lower( iv_name ).
REPLACE ALL OCCURRENCES OF '-' IN rv_name WITH '_'.
Expand All @@ -72,23 +86,20 @@ CLASS zcl_oapi_abap_name IMPLEMENTATION.
IF rv_name CO '0123456789'.
rv_name = 'n' && rv_name.
ENDIF.
IF strlen( rv_name ) > 30.
rv_name = rv_name(30).
IF strlen( rv_name ) > 28.
rv_name = rv_name(28).
ENDIF.
ENDMETHOD.

METHOD is_used.
DATA lv_name TYPE string.

METHOD to_abap_name.
IF iv_name IS INITIAL.
RETURN.
ENDIF.
lv_name = sanitize_name( iv_name ).
READ TABLE mt_used WITH KEY table_line = lv_name TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
rv_used = abap_true.
RETURN.
rv_name = sanitize_name( iv_name ).
IF is_used( rv_name ) = abap_true.
rv_name = numbering( rv_name ).
ENDIF.
rv_used = abap_false.
APPEND rv_name TO mt_used.
ENDMETHOD.

ENDCLASS.
ENDCLASS.
27 changes: 27 additions & 0 deletions src/utils/zcl_oapi_abap_name.clas.testclasses.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CLASS ltcl_abap_name DEFINITION FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.

PRIVATE SECTION.
METHODS max_abap_name_length FOR TESTING RAISING cx_static_check.
ENDCLASS.


CLASS ltcl_abap_name IMPLEMENTATION.

METHOD max_abap_name_length.
DATA lo_abap_name TYPE REF TO zcl_oapi_abap_name.
DATA lv_abap_name TYPE string.

CREATE OBJECT lo_abap_name.

lv_abap_name = lo_abap_name->to_abap_name( 'a_long_name_longer_then_28_Characters' ).

cl_abap_unit_assert=>assert_number_between(
lower = 1
upper = 28
number = strlen( lv_abap_name ) ).

ENDMETHOD.

ENDCLASS.
1 change: 1 addition & 0 deletions src/utils/zcl_oapi_abap_name.clas.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
</VSEOCLASS>
</asx:values>
</asx:abap>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/zcl_oapi_json.clas.locals_imp.abap
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CLASS lcl_stack IMPLEMENTATION.
METHOD push.
DATA ls_data LIKE LINE OF mt_data.
ls_data-name = iv_name.
ls_data-is_array = boolc( iv_type = 'array').
ls_data-is_array = boolc( iv_type = 'array' ).
APPEND ls_data TO mt_data.
ENDMETHOD.

Expand Down
8 changes: 4 additions & 4 deletions src/v2/zcl_oapi_generator_v2.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ CLASS zcl_oapi_generator_v2 IMPLEMENTATION.
ENDIF.
ENDIF.

lv_typename = 'ret_' && ls_operation-abap_name.
lv_typename = 'r_' && ls_operation-abap_name.

CLEAR lv_post.
LOOP AT ls_operation-responses INTO ls_response.
Expand Down Expand Up @@ -345,14 +345,14 @@ CLASS zcl_oapi_generator_v2 IMPLEMENTATION.
METHOD find_returning_parameter.
DATA ls_response LIKE LINE OF is_operation-responses.
DATA ls_content LIKE LINE OF ls_response-content.
DATA lv_typename TYPE string.
DATA lv_typename TYPE char30.
DATA lo_response_name TYPE REF TO zcl_oapi_response_name.
DATA lv_response_name TYPE string.
DATA lv_returning_type TYPE string.

CREATE OBJECT lo_response_name.

lv_typename = 'ret_' && is_operation-abap_name.
lv_typename = 'r_' && is_operation-abap_name.

LOOP AT is_operation-responses INTO ls_response.
LOOP AT ls_response-content INTO ls_content.
Expand Down Expand Up @@ -382,4 +382,4 @@ CLASS zcl_oapi_generator_v2 IMPLEMENTATION.
ENDLOOP.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
ENDCLASS.
Loading

0 comments on commit d95f962

Please sign in to comment.