larshp / ABAP-Swagger

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

duplicated mapping key #60

Closed BlackmanCC closed 3 years ago

BlackmanCC commented 3 years ago

I am trying to register different handler classes for one url path. The reason is that I want to implement different versions of same class in one swagger ui and include version (v2, v3) in path. If the different classes have methods with the same name I get a "duplicated mapping key".

Do you have any idea? What can I do?

larshp commented 3 years ago

first step, try reproducing the issue

I cannot find the error message, https://github.com/larshp/ABAP-Swagger/search?q=duplicated+mapping+key, where/when does the error occur?

BlackmanCC commented 3 years ago

The problem can be reproduced with editor.swagger.io. I found out, that problem occurs because of duplicate method names in the two classes I register. I can avoid the problem with defining different names.

The handler method names in META are currently used to build the swagger "Models" entries. In my understanding you can have different handlers with same output structure (Model) in swagger concept. The current implementation will always open a "Models" entry for each handler even if they use the same output structure.

I think it would be better to open "Models" entries not for each handler but for the structures used by the handlers. What do you think?

larshp commented 3 years ago

well, difficult to tell, I have not seen the actual error or reproduced it

BlackmanCC commented 3 years ago

The error is not the problem. It is possible to avoid it.

What do you think about the concept of only one "Models" entry for 1 structur used in multiple handlers (methods)?

larshp commented 3 years ago

I dont remember the structure from the top of my head, and I don't have an example to look at, sorry

BlackmanCC commented 3 years ago

would it help if I give you an example?

BlackmanCC commented 3 years ago

you can open editor.swagger.io and post following json


  1. Current situation with two methods/handlers using the same response structure, which is shown as 2 "Models"

swagger: '2.0'
info:
  version: 1.0.0
  title: abap Swagger Test
  description: abap Swagger Test REST functions
basePath: /sap/zswag/rest
securityDefinitions:
  basicAuth:
    type: basic
security:
  - basicAuth: []
schemes:
  - http
consumes:
  - application/json
produces:
  - application/json
paths:
  /list:
    get:
      tags:
        - CONTACTS
      summary: list by contactid
      description: ''
      parameters:
        - name: ID_CONTACT
          in: query
          description: ''
          type: string
          maxLength: 12
          required: false
      produces:
        - application/json
      responses:
        '200':
          description: successful operation
          schema:
            $ref: '#/definitions/LIST_Response'
        '401':
          description: not authorized
        '404':
          description: not found
        '500':
          description: error
  /list2:
    get:
      tags:
        - CONTACTS2
      summary: list by testid
      description: ''
      parameters:
        - name: ID_TEST
          in: query
          description: ''
          type: string
          maxLength: 12
          required: false
      produces:
        - application/json
      responses:
        '200':
          description: successful operation
          schema:
            $ref: '#/definitions/LIST2_Response'
        '401':
          description: not authorized
        '404':
          description: not found
        '500':
          description: error
definitions:
  LIST_Response:
    type: object
    properties:
      DATA:
        type: object
        properties:
          T_CONTACT_LIST:
            type: array
            items:
              type: object
              properties:
                VSTELLE1:
                  type: string
                  maxLength: 10
                VSTELLE2:
                  type: string
                  maxLength: 10
                NOTICETEXT:
                  type: string
                CONTACT2:
                  type: string
                  maxLength: 12
                SEPARATOR:
                  type: string
                  maxLength: 4
                CREATED_BY_NAME:
                  type: string
                  maxLength: 80
                BUKRS:
                  type: string
                  maxLength: 4
                PARTNER:
                  type: string
                  maxLength: 10
                CONTACT_PERSON:
                  type: string
                  maxLength: 10
                CLASS:
                  type: string
                  maxLength: 4
                ACTIVITY:
                  type: string
                  maxLength: 4
                TYPE:
                  type: string
                  maxLength: 3
                DIRECTION:
                  type: string
                  maxLength: 1
                PARTNER_INFO:
                  type: string
                  maxLength: 2
                PRIORITY:
                  type: string
                  maxLength: 2
                CONTACT_INFO:
                  type: string
                  maxLength: 2
                CONTACT_DATE:
                  type: string
                CONTACT_TIME:
                  type: string
                CREATED_ON:
                  type: string
                CREATED_BY:
                  type: string
                  maxLength: 12
                AUTH_GROUP:
                  type: string
                  maxLength: 4
                TEXT_LINE:
                  type: string
                  maxLength: 132
                CONTACT:
                  type: string
                  maxLength: 12
                CH_ON:
                  type: string
                CHANGED_BY:
                  type: string
                  maxLength: 12
          COUNT:
            type: integer
          LAST:
            type: string
            maxLength: 12
          CLIPPED:
            type: string
            maxLength: 1
          ET_RETURN:
            type: array
            items:
              type: object
              properties:
                TYPE:
                  type: string
                  maxLength: 1
                ID:
                  type: string
                  maxLength: 20
                NUMBER:
                  type: string
                MESSAGE:
                  type: string
                  maxLength: 220
                LOG_NO:
                  type: string
                  maxLength: 20
                LOG_MSG_NO:
                  type: string
                MESSAGE_V1:
                  type: string
                  maxLength: 50
                MESSAGE_V2:
                  type: string
                  maxLength: 50
                MESSAGE_V3:
                  type: string
                  maxLength: 50
                MESSAGE_V4:
                  type: string
                  maxLength: 50
                PARAMETER:
                  type: string
                  maxLength: 32
                ROW:
                  type: integer
                FIELD:
                  type: string
                  maxLength: 30
                SYSTEM:
                  type: string
                  maxLength: 10
  LIST2_Response:
    type: object
    properties:
      DATA:
        type: object
        properties:
          T_CONTACT_LIST:
            type: array
            items:
              type: object
              properties:
                VSTELLE1:
                  type: string
                  maxLength: 10
                VSTELLE2:
                  type: string
                  maxLength: 10
                NOTICETEXT:
                  type: string
                CONTACT2:
                  type: string
                  maxLength: 12
                SEPARATOR:
                  type: string
                  maxLength: 4
                CREATED_BY_NAME:
                  type: string
                  maxLength: 80
                BUKRS:
                  type: string
                  maxLength: 4
                PARTNER:
                  type: string
                  maxLength: 10
                CONTACT_PERSON:
                  type: string
                  maxLength: 10
                CLASS:
                  type: string
                  maxLength: 4
                ACTIVITY:
                  type: string
                  maxLength: 4
                TYPE:
                  type: string
                  maxLength: 3
                DIRECTION:
                  type: string
                  maxLength: 1
                PARTNER_INFO:
                  type: string
                  maxLength: 2
                PRIORITY:
                  type: string
                  maxLength: 2
                CONTACT_INFO:
                  type: string
                  maxLength: 2
                CONTACT_DATE:
                  type: string
                CONTACT_TIME:
                  type: string
                CREATED_ON:
                  type: string
                CREATED_BY:
                  type: string
                  maxLength: 12
                AUTH_GROUP:
                  type: string
                  maxLength: 4
                TEXT_LINE:
                  type: string
                  maxLength: 132
                CONTACT:
                  type: string
                  maxLength: 12
                CH_ON:
                  type: string
                CHANGED_BY:
                  type: string
                  maxLength: 12
          COUNT:
            type: integer
          LAST:
            type: string
            maxLength: 12
          CLIPPED:
            type: string
            maxLength: 1
          ET_RETURN:
            type: array
            items:
              type: object
              properties:
                TYPE:
                  type: string
                  maxLength: 1
                ID:
                  type: string
                  maxLength: 20
                NUMBER:
                  type: string
                MESSAGE:
                  type: string
                  maxLength: 220
                LOG_NO:
                  type: string
                  maxLength: 20
                LOG_MSG_NO:
                  type: string
                MESSAGE_V1:
                  type: string
                  maxLength: 50
                MESSAGE_V2:
                  type: string
                  maxLength: 50
                MESSAGE_V3:
                  type: string
                  maxLength: 50
                MESSAGE_V4:
                  type: string
                  maxLength: 50
                PARAMETER:
                  type: string
                  maxLength: 32
                ROW:
                  type: integer
                FIELD:
                  type: string
                  maxLength: 30
                SYSTEM:
                  type: string
                  maxLength: 10

  1. two methods/handlers using the same response structure shown as unique Model

swagger: '2.0'
info:
  version: 1.0.0
  title: abap Swagger Test
  description: abap Swagger Test REST functions
basePath: /sap/zswag/rest
securityDefinitions:
  basicAuth:
    type: basic
security:
  - basicAuth: []
schemes:
  - http
consumes:
  - application/json
produces:
  - application/json
paths:
  /list:
    get:
      tags:
        - CONTACTS
      summary: list by contactid
      description: ''
      parameters:
        - name: ID_CONTACT
          in: query
          description: ''
          type: string
          maxLength: 12
          required: false
      produces:
        - application/json
      responses:
        '200':
          description: successful operation
          schema:
            $ref: '#/definitions/LIST_Response'
        '401':
          description: not authorized
        '404':
          description: not found
        '500':
          description: error
  /list2:
    get:
      tags:
        - CONTACTS2
      summary: list by testid
      description: ''
      parameters:
        - name: ID_TEST
          in: query
          description: ''
          type: string
          maxLength: 12
          required: false
      produces:
        - application/json
      responses:
        '200':
          description: successful operation
          schema:
            $ref: '#/definitions/LIST_Response'
        '401':
          description: not authorized
        '404':
          description: not found
        '500':
          description: error
definitions:
  LIST_Response:
    type: object
    properties:
      DATA:
        type: object
        properties:
          T_CONTACT_LIST:
            type: array
            items:
              type: object
              properties:
                VSTELLE1:
                  type: string
                  maxLength: 10
                VSTELLE2:
                  type: string
                  maxLength: 10
                NOTICETEXT:
                  type: string
                CONTACT2:
                  type: string
                  maxLength: 12
                SEPARATOR:
                  type: string
                  maxLength: 4
                CREATED_BY_NAME:
                  type: string
                  maxLength: 80
                BUKRS:
                  type: string
                  maxLength: 4
                PARTNER:
                  type: string
                  maxLength: 10
                CONTACT_PERSON:
                  type: string
                  maxLength: 10
                CLASS:
                  type: string
                  maxLength: 4
                ACTIVITY:
                  type: string
                  maxLength: 4
                TYPE:
                  type: string
                  maxLength: 3
                DIRECTION:
                  type: string
                  maxLength: 1
                PARTNER_INFO:
                  type: string
                  maxLength: 2
                PRIORITY:
                  type: string
                  maxLength: 2
                CONTACT_INFO:
                  type: string
                  maxLength: 2
                CONTACT_DATE:
                  type: string
                CONTACT_TIME:
                  type: string
                CREATED_ON:
                  type: string
                CREATED_BY:
                  type: string
                  maxLength: 12
                AUTH_GROUP:
                  type: string
                  maxLength: 4
                TEXT_LINE:
                  type: string
                  maxLength: 132
                CONTACT:
                  type: string
                  maxLength: 12
                CH_ON:
                  type: string
                CHANGED_BY:
                  type: string
                  maxLength: 12
          COUNT:
            type: integer
          LAST:
            type: string
            maxLength: 12
          CLIPPED:
            type: string
            maxLength: 1
          ET_RETURN:
            type: array
            items:
              type: object
              properties:
                TYPE:
                  type: string
                  maxLength: 1
                ID:
                  type: string
                  maxLength: 20
                NUMBER:
                  type: string
                MESSAGE:
                  type: string
                  maxLength: 220
                LOG_NO:
                  type: string
                  maxLength: 20
                LOG_MSG_NO:
                  type: string
                MESSAGE_V1:
                  type: string
                  maxLength: 50
                MESSAGE_V2:
                  type: string
                  maxLength: 50
                MESSAGE_V3:
                  type: string
                  maxLength: 50
                MESSAGE_V4:
                  type: string
                  maxLength: 50
                PARAMETER:
                  type: string
                  maxLength: 32
                ROW:
                  type: integer
                FIELD:
                  type: string
                  maxLength: 30
                SYSTEM:
                  type: string
                  maxLength: 10
BlackmanCC commented 3 years ago

I implemented the new handling in my fork in branch "unique_models".

Instead of using Handler name as Model I use the data type (structure) name of the returning parameter od the method. Then I delete duplicate entries in mt_descriptions before adding them.

Can you check before I make a pull-request?

larshp commented 3 years ago

just open the pull request, its easier to see whats changed, plus it runs CI