Trying to generate stub(java file) with json(application/json) data with file(multipart) using swagger

505 Views Asked by At

trying to submit form with multiple attachments(file) whether it is correct approach or i don't know if i am using multipart/form-data not able to submit json data.

paths: /request/create: post: tags: - Request Service API summary: request for media file access security: [] operationId: createMediaRequest parameters: - name: userId in: header description: user login id required: true schema: type: string - name: xt-trace-id in: header description: request trace id required: true schema: type: string

  requestBody:
    description: to send a request to get media file, id is mandatory for make a request. Id should be a valid and in the form of UUID.
    content:
      application/json:
        schema:
          type: object
          properties:
            deviceinfo:
              type: array
              items:
                $ref: '#/components/schemas/ClientReqData'
            priority:
              type: string
              example: '1'
            appID:
              type: string
              example: 'app1'
            hostID:
              type: string
              example: 'host1'
            subscribers:
              type: string
              example: "[XT123,xt234]"
            requestreason:
              type: string
              example: "audit purpose"
            previousshiftemployee:
              type: string
              example: xyz
            regulationchecklist:
              type: string
              example: "[i have read instructions, I have identified]"
            file:
              type: array
              items:
                type: string
                format: binary
            attachments:
              type: array
              items:
                $ref: '#/components/schemas/Attachments'      
    required: true
    
    
  responses:
    201:
      description: Request for media created
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/CreateMediaResponse'
    400:
      $ref: '#/components/responses/400-bad-request'
    500:
      $ref: '#/components/responses/500-internal-server-error'
    503:
      $ref: '#/components/responses/503-Service-unavailable'

and Attachments is

Attachments:
  type: object
  properties:
    filename:
      type: string
      format: binary
1

There are 1 best solutions below

0
On

I understand you would like to create a stub for the HTTP endpoint defined in the Swagger specification. In other words, you are looking for creating an over-the-wire test double.

There are a couple of options you have: