swagger-js icon indicating copy to clipboard operation
swagger-js copied to clipboard

The spec for post requests with the "requestBody" parameter does not work.

Open ZababurinSergei opened this issue 1 year ago • 1 comments

Q&A (please complete the following information)

  • OS: Ubunut 20.04
  • Environment: Chromium Version 119.0.6045.105 (Official Build) snap (64-bit)
  • Method of installation: npm
  • Swagger-Client version: 3.24.5
  • Swagger/OpenAPI version: openapi: 3.0.1

Content & configuration

When I make a post request, the request body is not added to the request.

http://localhost:4012/metamart-subscription-service/api/v1/directory/record/filter 415 (Unsupported Media Type)

Swagger/OpenAPI definition:

openapi: 3.0.1
info:
  title: OpenAPI definition
  version: v0
servers:
  - url: /metamart-subscription-service
    description: Generated server url
paths:
  "/api/v1/subscription":
    get:
      tags:
        - subscription-controller
      operationId: getSubscriptions
      parameters:
        - name: active
          in: query
          required: false
          schema:
            type: boolean
        - name: recipientId
          in: query
          required: false
          schema:
            type: string
            format: uuid
        - name: interactionId
          in: query
          required: false
          schema:
            type: string
            format: uuid
        - name: subscriptionId
          in: query
          required: false
          schema:
            type: string
            format: uuid
        - name: limit
          in: query
          required: true
          schema:
            type: integer
            format: int32
        - name: offset
          in: query
          required: true
          schema:
            type: integer
            format: int32
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": '#/components/schemas/PageSearchSubscriptionDTO'
    put:
      tags:
        - subscription-controller
      operationId: updateSubscription
      requestBody:
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/UpdateSubscriptionRequest"
        required: true
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": "#/components/schemas/SubscriptionDTO"
    post:
      tags:
        - subscription-controller
      operationId: createSubscription
      requestBody:
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/CreateSubscriptionRequest"
        required: true
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": "#/components/schemas/SubscriptionDTO"
    delete:
      tags:
        - subscription-controller
      operationId: deleteSubscription
      parameters:
        - name: subscriptionId
          in: query
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: No content

  "/api/v1/subscription/setting":
    get:
      tags:
        - subscription-setting-controller
      operationId: getSubscriptionSettings
      parameters:
        - name: active
          in: query
          required: false
          schema:
            type: boolean
        - name: subscriptionId
          in: query
          required: true
          schema:
            type: string
            format: uuid
        - name: subscriptionSettingId
          in: query
          required: false
          schema:
            type: string
            format: uuid
        - name: limit
          in: query
          required: true
          schema:
            type: integer
            format: int32
        - name: offset
          in: query
          required: true
          schema:
            type: integer
            format: int32
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": '#/components/schemas/PageSearchSubscriptionSettingDTO'
    put:
      tags:
        - subscription-setting-controller
      operationId: updateSubscriptionSetting
      requestBody:
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/UpdateSubscriptionSettingRequest"
        required: true
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": "#/components/schemas/SubscriptionSettingDTO"
    post:
      tags:
        - subscription-setting-controller
      operationId: createSubscriptionSetting
      requestBody:
        content:
          application/json:
            schema:
              type: array
              items:
                "$ref": "#/components/schemas/CreateSubscriptionSettingRequest"
        required: true
      responses:
        "201":
          description: OK
    delete:
      tags:
        - subscription-setting-controller
      operationId: deleteSubscriptionSetting
      parameters:
        - name: settingId
          in: query
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: No content
  "/api/v1/rule":
    get:
      tags:
        - rule-controller
      operationId: getRules
      parameters:
        - name: ruleId
          in: query
          required: false
          schema:
            type: string
            format: uuid
        - name: active
          in: query
          required: false
          schema:
            type: boolean
        - name: interactionId
          in: query
          required: false
          schema:
            type: string
            format: uuid
        - name: limit
          in: query
          required: true
          schema:
            type: integer
            format: int32
        - name: offset
          in: query
          required: true
          schema:
            type: integer
            format: int32
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": '#/components/schemas/PageSearchRuleDTO'
    put:
      tags:
        - rule-controller
      operationId: updateRule
      requestBody:
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/UpdateRuleRequest"
        required: true
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": "#/components/schemas/RuleDTO"
    post:
      tags:
        - rule-controller
      operationId: createRule
      requestBody:
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/CreateRuleRequest"
        required: true
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": "#/components/schemas/RuleDTO"
    delete:
      tags:
        - rule-controller
      operationId: deleteRule
      parameters:
        - name: ruleId
          in: query
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: No content
  "/api/v1/directory/record":
    get:
      tags:
        - directory-controller
      operationId: getRecords_2
      parameters:
        - name: active
          in: query
          required: false
          schema:
            type: boolean
        - name: recordId
          in: query
          required: false
          schema:
            type: string
            format: uuid
        - name: directoryId
          in: query
          required: true
          schema:
            type: string
            format: uuid
        - name: limit
          in: query
          required: true
          schema:
            type: integer
            format: int32
        - name: offset
          in: query
          required: true
          schema:
            type: integer
            format: int32
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": "#/components/schemas/PageRecordDTO"
    put:
      tags:
        - directory-controller
      operationId: updateRecord
      requestBody:
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/UpdateRecordRequest"
        required: true
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": "#/components/schemas/RecordDTO"
    post:
      tags:
        - directory-controller
      operationId: createRecord
      requestBody:
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/CreateRecordRequest"
        required: true
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": "#/components/schemas/RecordDTO"
  /api/v1/subscription/filter:
    post:
      tags:
        - subscription-controller
      operationId: searchSubscriptions
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SubscriptionSearchFilter'
        required: true
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/PageSearchSubscriptionDTO'
  /api/v1/rule/filter:
    post:
      tags:
        - rule-controller
      operationId: searchRules
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RuleSearchFilter'
        required: true
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/PageSearchRuleDTO'
  "/api/v1/recipient":
    post:
      tags:
        - recipient-controller
      operationId: getRecipients
      requestBody:
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/RecipientRequest"
        required: true
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                type: array
                items:
                  "$ref": "#/components/schemas/RecipientDTO"
  "/api/v1/fnsi/directory":
    post:
      tags:
        - fnsi-directory-controller
      operationId: createDirectory
      requestBody:
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/CreateFnsiDirectoryRequest"
        required: true
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": "#/components/schemas/FnsiDirectoryDTO"
  "/api/v1/fnsi/directory/update/{directoryOid}":
    post:
      tags:
        - fnsi-directory-update-controller
      operationId: update
      parameters:
        - name: directoryOid
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": "#/components/schemas/FnsiDirectoryUpdateDTO"
  "/api/v1/fnsi/directory/update/all":
    post:
      tags:
        - fnsi-directory-update-controller
      operationId: updateAll
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": "#/components/schemas/FnsiDirectoryUpdateDTO"
  "/api/v1/fnsi/directory/record":
    get:
      tags:
        - fnsi-directory-controller
      operationId: getRecords_1
      parameters:
        - name: directoryOid
          in: query
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                type: array
                items:
                  "$ref": "#/components/schemas/FnsiDirectoryRecordDTO"
    post:
      tags:
        - fnsi-directory-controller
      operationId: createDirectoryRecord
      requestBody:
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/CreateFnsiDirectoryRecordRequest"
        required: true
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": "#/components/schemas/FnsiDirectoryRecordDTO"
    delete:
      tags:
        - directory-controller
      operationId: deleteRecord
      parameters:
        - name: directoryId
          in: query
          required: true
          schema:
            type: string
            format: uuid
        - name: recordId
          in: query
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: No content
  "/api/v1/directory/record/filter":
    post:
      tags:
        - directory-controller
      operationId: searchRecords
      requestBody:
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/RecordSearchFilters"
        required: true
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": "#/components/schemas/PageRecordDTO"
  "/api/v1/fnsi/external/directory":
    get:
      tags:
        - external-fnsi-directory-controller
      operationId: getDirectory
      parameters:
        - name: oid
          in: query
          required: true
          schema:
            type: string
        - name: version
          in: query
          required: false
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                "$ref": "#/components/schemas/ExternalFnsiDirectoryDTO"
components:
  schemas:
    UpdateSubscriptionRequest:
      required:
        - active
        - id
        - startAt
        - updatedAt
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        updatedAt:
          type: string
          format: date-time
        startAt:
          type: string
          format: date-time
        endAt:
          type: string
          format: date-time
    SubscriptionDTO:
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        recipientId:
          type: string
          format: uuid
        interactionId:
          type: string
          format: uuid
        startAt:
          type: string
          format: date-time
        endAt:
          type: string
          format: date-time
    UpdateSubscriptionSettingRequest:
      required:
        - active
        - headerId
        - id
        - subscriptionId
        - updatedAt
        - value
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        updatedAt:
          type: string
          format: date-time
        subscriptionId:
          type: string
          format: uuid
        headerId:
          type: string
          format: uuid
        value:
          type: string
    SubscriptionSettingDTO:
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        subscriptionId:
          type: string
          format: uuid
        headerId:
          type: string
          format: uuid
        value:
          type: string
    UpdateRuleRequest:
      required:
        - active
        - headerId
        - id
        - interactionId
        - updatedAt
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        updatedAt:
          type: string
          format: date-time
        interactionId:
          type: string
          format: uuid
        headerId:
          type: string
          format: uuid
    RuleDTO:
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        interactionId:
          type: string
          format: uuid
        headerId:
          type: string
          format: uuid
    UpdateRecordRequest:
      required:
        - active
        - code
        - directoryId
        - id
        - name
        - updatedAt
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        updatedAt:
          type: string
          format: date-time
        directoryId:
          type: string
          format: uuid
        code:
          type: string
        name:
          type: string
    RecordDTO:
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        directoryId:
          type: string
          format: uuid
        code:
          type: string
        name:
          type: string
    CreateSubscriptionRequest:
      required:
        - active
        - createdAt
        - interactionId
        - recipientId
        - startAt
      type: object
      properties:
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        recipientId:
          type: string
          format: uuid
        interactionId:
          type: string
          format: uuid
        startAt:
          type: string
          format: date-time
        endAt:
          type: string
          format: date-time
    CreateSubscriptionSettingRequest:
      required:
        - active
        - createdAt
        - headerId
        - subscriptionId
        - value
      type: object
      properties:
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        subscriptionId:
          type: string
          format: uuid
        headerId:
          type: string
          format: uuid
        value:
          type: string
    CreateRuleRequest:
      required:
        - createdAt
        - headerId
        - interactionId
      type: object
      properties:
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        interactionId:
          type: string
          format: uuid
        headerId:
          type: string
          format: uuid
    RecipientHeaderDTO:
      type: object
      properties:
        headerCode:
          type: string
        value:
          type: string
    RecipientRequest:
      required:
        - ceType
      type: object
      properties:
        ceType:
          type: string
        headers:
          type: array
          items:
            "$ref": "#/components/schemas/RecipientHeaderDTO"
    RecipientDTO:
      type: object
      properties:
        code:
          type: string
    CreateFnsiDirectoryRequest:
      required:
        - active
        - createdAt
        - name
        - oid
        - version
      type: object
      properties:
        oid:
          type: string
        name:
          type: string
        version:
          type: string
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
    FnsiDirectoryDTO:
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        oid:
          type: string
        name:
          type: string
        version:
          type: string
    FnsiDirectoryUpdateDTO:
      type: object
      properties:
        summary:
          type: string
    CreateFnsiDirectoryRecordRequest:
      required:
        - active
        - createdAt
        - directoryId
        - name
        - oid
      type: object
      properties:
        directoryId:
          type: string
          format: uuid
        oid:
          type: string
        name:
          type: string
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
    FnsiDirectoryRecordDTO:
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        oid:
          type: string
        name:
          type: string
        directoryId:
          type: string
          format: uuid
    CreateRecordRequest:
      required:
        - active
        - code
        - createdAt
        - directoryId
        - name
      type: object
      properties:
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        directoryId:
          type: string
          format: uuid
        code:
          type: string
        name:
          type: string
    RecordSearchFilters:
      required:
        - directoryId
        - field
        - operator
        - type
        - value
      type: object
      properties:
        directoryId:
          type: string
          format: uuid
        active:
          type: boolean
        limit:
          type: integer
          format: int32
        offset:
          type: integer
          format: int32
        type:
          type: integer
          format: int32
        operator:
          type: string
        field:
          type: string
        value:
          type: string
    PageRecordDTO:
      type: object
      properties:
        data:
          type: array
          items:
            "$ref": "#/components/schemas/RecordDTO"
        limit:
          type: integer
          format: int32
        offset:
          type: integer
          format: int32
        total:
          type: integer
          format: int32
    TokenRequest:
      required:
        - data
        - reqType
      type: object
      properties:
        reqType:
          type: integer
          format: int32
        data:
          type: string
    Token:
      type: object
      properties:
        type:
          type: string
        access:
          type: string
        refresh:
          type: string
        expiresIn:
          type: integer
          format: int64
    PermissionDTO:
      type: object
      properties:
        rightId:
          type: string
          format: uuid
        directoryId:
          type: string
          format: uuid
        active:
          type: boolean
    RolePermissionsDTO:
      type: object
      properties:
        roleName:
          type: string
        permissions:
          type: array
          items:
            "$ref": "#/components/schemas/PermissionDTO"
    GetSubscriptionDTO:
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        recipientId:
          type: string
          format: uuid
        interactionId:
          type: string
          format: uuid
        startAt:
          type: string
          format: date-time
        endAt:
          type: string
          format: date-time
        recipientCode:
          type: string
        recipientName:
          type: string
        interactionCode:
          type: string
        interactionName:
          type: string
    LinkHeaderDirectoryDTO:
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        headerId:
          type: string
          format: uuid
        directoryId:
          type: string
          format: uuid
    ExternalFnsiDirectoryDTO:
      type: object
      properties:
        oid:
          type: string
        name:
          type: string
        version:
          type: string
        description:
          type: string
        rowsCount:
          type: integer
          format: int32
        fields:
          type: array
          items:
            "$ref": "#/components/schemas/ExternalFnsiDirectoryFieldDTO"
    ExternalFnsiDirectoryFieldDTO:
      type: object
      properties:
        name:
          type: string
        dataType:
          type: string
        description:
          type: string
    ExternalFnsiDirectoryVersionDTO:
      type: object
      properties:
        version:
          type: string
        createDate:
          type: string
        publishDate:
          type: string
        lastUpdate:
          type: string
        archive:
          type: boolean
    ExternalFnsiDirectoryRecordDTO:
      type: object
      properties:
        oid:
          type: string
        name:
          type: string
        endDate:
          type: string
        startDate:
          type: string
        directoryOid:
          type: string
    DirectoryDTO:
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        showActive:
          type: boolean
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        pathName:
          type: string
        name:
          type: string
        type:
          type: string
    UserInfo:
      type: object
      properties:
        role:
          type: string
        email:
          type: string
        snils:
          type: string
        lastName:
          type: string
        firstName:
          type: string
        enable:
          type: boolean
    SubscriptionSearchFilter:
      required:
        - field
        - operator
        - type
        - value
      type: object
      properties:
        active:
          type: boolean
        type:
          type: integer
          format: int32
        operator:
          type: string
        field:
          type: string
        value:
          type: string
        limit:
          type: integer
          format: int32
        offset:
          type: integer
          format: int32
    PageSearchSubscriptionDTO:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/SearchSubscriptionDTO'
        limit:
          type: integer
          format: int32
        offset:
          type: integer
          format: int32
        total:
          type: integer
          format: int32
    SearchSubscriptionDTO:
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        recipientId:
          type: string
          format: uuid
        interactionId:
          type: string
          format: uuid
        startAt:
          type: string
          format: date-time
        endAt:
          type: string
          format: date-time
        recipientCode:
          type: string
        recipientName:
          type: string
        interactionCode:
          type: string
        interactionName:
          type: string
    RuleSearchFilter:
      required:
        - field
        - operator
        - type
        - value
      type: object
      properties:
        active:
          type: boolean
        type:
          type: integer
          format: int32
        operator:
          type: string
        field:
          type: string
        value:
          type: string
        limit:
          type: integer
          format: int32
        offset:
          type: integer
          format: int32
    PageSearchRuleDTO:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/SearchRuleDTO'
        limit:
          type: integer
          format: int32
        offset:
          type: integer
          format: int32
        total:
          type: integer
          format: int32
    SearchRuleDTO:
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        interactionId:
          type: string
          format: uuid
        interactionCode:
          type: string
        interactionName:
          type: string
        headerId:
          type: string
          format: uuid
        headerCode:
          type: string
        headerName:
          type: string
    PageSearchSubscriptionSettingDTO:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/SearchSubscriptionSettingDTO'
        limit:
          type: integer
          format: int32
        offset:
          type: integer
          format: int32
        total:
          type: integer
          format: int32
    SearchSubscriptionSettingDTO:
      type: object
      properties:
        id:
          type: string
          format: uuid
        active:
          type: boolean
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        subscriptionId:
          type: string
          format: uuid
        headerId:
          type: string
          format: uuid
        interactionId:
          type: string
          format: uuid
        value:
          type: string
        headerCode:
          type: string
        headerName:
          type: string

Swagger-Client usage:

    let swagger = Symbol.for("swagger");
    window[swagger] = await new SwaggerClient('http://localhost:4012/mss.yaml')

Describe the bug you're encountering

The request body is not added to post requests.

To reproduce...

Steps to reproduce the behavior:

  1. let swagger = Symbol.for("swagger"); window[swagger] = await new SwaggerClient('http://localhost:4012/mss.yaml')

  2. const reuest = {
     "directoryId": "9c1c47d9-4210-4f93-baa5-78f2addeb66c",
     "active": true,
     "limit": 30,
     "offset": 0,
     "type": 0,
     "operator": "like",
     "field": "code",
     "value": "r"
    

    }

    await window[swagger].apis['directory-controller'].searchRecords(reuest)

Expected behavior

Expected behavior. The request body is added to the request.

Screenshots

error

ZababurinSergei avatar Nov 12 '23 02:11 ZababurinSergei

I'm just trying to get a simple POST to work. My expectations for this library and mental model for what it does appears to be incorrect.

I'm loading a simple swagger file and using this to call it with swaggerjs: client.apis.default.post_users({'name':'john',email:'[email protected]'}).then(console.log).catch(console.log)

The first issue I encountered was that the content type was not being sent, despite it being specified in the swagger.yaml file. To address this, I added a request interceptor. However, now the body is not present in the request.

The documention is lacking a simple example that shows how to handle a post request.

base698 avatar Jun 26 '24 17:06 base698