larshp / ABAP-Swagger

Expose ABAP REST services with Swagger/openapi spec
MIT License
97 stars 40 forks source link

Optional Parameter Not Working #35

Closed thesourav123 closed 5 years ago

thesourav123 commented 6 years ago

If i have optional parameters then it is still showing as "Required" image

Now, in output image

larshp commented 6 years ago

yes, not implemented, see https://github.com/larshp/ABAP-Swagger/issues/33

thesourav123 commented 6 years ago

@larshp, In PARAMETERS method inside ZCL_SWAG_SPEC, it looks simple to fix it.


 LOOP AT is_meta-parameters ASSIGNING <ls_parameter>
        WHERE pardecltyp = zcl_swag=>c_parm_kind-importing.

      APPEND '{' TO lt_string.

      CONCATENATE '"name":"' <ls_parameter>-sconame '",' INTO ls_string.
      APPEND ls_string TO lt_string.

      READ TABLE is_meta-meta-url-group_names FROM <ls_parameter>-sconame
        TRANSPORTING NO FIELDS.
      IF sy-subrc = 0.
        APPEND '"in":"path",' TO lt_string.
      ELSEIF is_meta-meta-method = zcl_swag=>c_method-get.
        APPEND '"in":"query",' TO lt_string.
      ELSE.
        APPEND '"in":"body",' TO lt_string.
      ENDIF.

      APPEND '"description":"",' TO lt_string.

      CREATE OBJECT lo_map
        EXPORTING
          is_param = <ls_parameter>.
      lv_type = lo_map->map( ).
      CONCATENATE lv_type ',' INTO ls_string.
      APPEND ls_string TO lt_string.

     """"""""""""" APPEND '"required":true'   TO lt_string.
*********************************************************************************
      IF <LS_PARAMETER>-PAROPTIONL = 'X'.
         APPEND '"required":false'   TO lt_string.
      ELSE.
        APPEND '"required":true'   TO lt_string.
      ENDIF.
********************************************************************************
      APPEND '},' TO lt_string.
    ENDLOOP.
larshp commented 6 years ago

yeah, that will change the spec, but does the code also work if not supplying the parameter?

thesourav123 commented 6 years ago

You mean will it work without any importing parameter?

larshp commented 6 years ago

try calling the REST service without supplying TICKETNO

thesourav123 commented 6 years ago

Yup, it calls SAP, My method and executes successfully.