pavanlimo
pavanlimo

Reputation: 4252

Can Swagger be used for SOAP?

I was exploring Swagger and I must acknowledge I'm loving it.

I understand Swagger is primarily for RESTful web services, but I was wondering if we can make it work with SOAP web services as well. May be translate SOAP based web services to RESTful? Or simply call SOAP based services via Swagger UI? Some hack? Has anyone done it?

Upvotes: 29

Views: 69054

Answers (4)

NoOoNY
NoOoNY

Reputation: 13

openapi: 3.0.1

info:

  version: 1.0.0
  title: SOAP
  description: |-
    # Introduction
    > ## 1.1. Purpose

    IMG
    >>> ![Service description](./IMGs/ServiceDescription.png)


    TABLE
    >>>>| TH1             | TH2           |  TH3          | TH4         |
    >>>>| --------------- | ------------- | ------------- | ----------- |
    >>>>| Body1           | Body1         | Body3         | Body4       |



  termsOfService: https://anas.badwais.com/en/terms-conditions
  contact:
    email: [email protected]
  license:
    name: Anas Badwais
    url: http://anas.badwais.com/licenses/LICENSE-2.0.html
externalDocs:
  description: Service description (WSDL)
  url:  'http://WSDL_URL/?wsdl'
servers:
  - description: testing
    url: '{protocol}{Environment}{port}{version}'
    variables:
      protocol:
        enum:
          - 'https://'
          - 'http://'
        default: 'http://'
      Environment:
        enum:
          - 'IPAddress'
        default: 'IPAddress'
      port:
        enum:
          - 'Port'
        default: 'Port'
      version:
        enum:
          - 'Version'
        default: 'Version'

tags:
  - name: tagName
    externalDocs:
      description: Find out more
      url: ''
paths:
  /{OperationName}/:
    post:
      tags:
        - tagName
      summary: OperationName - Breif Description
      description: |-
        description
      operationId: OperationName
      parameters:
        - description: OperationName
          name: OperationName
          required: true
          in: path
          schema:
            type: string
            enum:
              - 'SOAPURL_IF_EXISTS'
            default: 'SOAPURL_IF_EXISTS'
        - description: SOAPAction header for soap 1.1
          name: SOAPAction
          required: true
          in: header
          schema:
            type: string
            enum:
              - OperationName
            default: OperationName
      requestBody:
        $ref: '#/components/requestBodies/OperationNameEnvelope'
      responses:
        '200':
          description: OK
          headers:
            Access-Control-Allow-Origin:
              schema:
                type: string
            Access-Control-Allow-Methods:
              schema:
                type: string
            Access-Control-Allow-Headers:
              schema:
                type: string
            Transfer-Encoding:
              description : chunked
              schema:
                type: string
          content:
            text/xml charset=UTF-8 :
              schema:
                $ref: '#/components/schemas/OperationNameResponseEnvelope'
              examples:
                HappyScenario:
                  $ref: '#/components/examples/OperationName_RS_HappyScenario'

        '500':
          description: Internal Server Error
          headers:
            Access-Control-Allow-Origin:
              schema:
                type: string
            Access-Control-Allow-Methods:
              schema:
                type: string
            Access-Control-Allow-Headers:
              schema:
                type: string
            Transfer-Encoding:
              description: chunked
              schema:
                type: string
          content:
            text/xml charset=UTF-8:
              schema:
                $ref: '#/components/schemas/faultEnvelope'
      # security:

components:
  examples:
    OperationName_HappyScenario:
      value:
        Header:
        Body:
          OperationName: '1'

    #-----------------#
    #----------------------------------#

    OperationName_RS_HappyScenario:
      value:
        Header:
        Body:
          OperationName: '1'

  #-----------------#
  #----------------------------------#
  #-----------------#

  requestBodies:
    OperationNameEnvelope:
      description: ''
      content:
        text/xml charset=UTF-8:
          schema:
            $ref: '#/components/schemas/OperationNameEnvelope'
          examples:
            HappyScenario:
              $ref: '#/components/examples/OperationName_HappyScenario'


    #-----------------#
    #----------------------------------#
    #-----------------#

  schemas:
    OperationNameEnvelope:
      type: object
      xml:
        name: Envelope
        prefix: soapenv
        namespace: 'http://schemas.xmlsoap.org/soap/envelope/'
      properties:
        Header:
          type: string
          xml:
            name: Header
            prefix: soapenv
          example:
        Body:
          type: object
          xml:
            name: Body
            prefix: soapenv
          properties:
            OperationNameRequestMessage:
              $ref: '#/components/schemas/OperationNameRequestMessage'

    #-----------------#

    OperationNameRequestMessage:
      type: object
      xml:
        prefix: tns
        namespace: 'https://anas.badwais.com/'
      properties:
        OperationElement:
          type: number

    #-----------------#
    #----------------------------------#
    #-----------------#

    OperationNameResponseEnvelope:
      type: object
      xml:
        name: Envelope
        prefix: soapenv
        namespace: 'http://schemas.xmlsoap.org/soap/envelope/'
      properties:
        Header:
          type: string
          description: ''
          xml:
            prefix: soapenv
          example:
        Body:
          type: object
          description: ''
          xml:
            prefix: soapenv
          properties:
            OperationNameResponseMessage:
              $ref: '#/components/schemas/OperationNameResponseMessage'

    #-----------------#

    OperationNameResponseMessage:
      type: object
      description: ''
      required:
        - Response
      xml:
        prefix: tns
        namespace: 'https://anas.badwais.com/'
      properties:
        ResponseElements:
          type: integer

    #-----------------#
    #----------------------------------#
    #-----------------#

    faultEnvelope:
      type: object
      xml:
        name: Envelope
        prefix: soapenv
        namespace: 'http://schemas.xmlsoap.org/soap/envelope/'
      properties:
        Header:
          type: object
          xml:
            name: Header
            prefix: soapenv
        Body:
          type: object
          xml:
            name: Body
            prefix: soapenv
          properties:
            getVisitorInfo:
              $ref: '#/components/schemas/fault'

    #-----------------#

    fault:
      type: object
      xml:
        name: Fault
        prefix: soapenv
        namespace: 'http://schemas.xmlsoap.org/soap/envelope/'
      properties:
        faultcode:
          type: string
          xml:
            name: faultcode
          example: 1
        faultstring:
          type: string
          xml:
            name: faultstring
          example: Error
        faultactor:
          type: string
          xml:
            name: faultactor
          example: 1
        detail:
          type: object
          xml:
            name: detail
          properties:
            Fault:
              $ref: '#/components/schemas/FaultBody'

    #-----------------#

    FaultBody:
      type: object
      xml:
        name: Fault
        prefix: flt
        namespace: 'http://schemas.xmlsoap.org/soap/envelope/'
      properties:
        ErrorCode:
          type: integer
          format: int64
          xml:
            name: Fault
            prefix: flt
          example: 1
        ErrorType:
          type: string
          xml:
            name: Fault
            prefix: flt
          enum:
            - System
            - Functional
        Message:
          type: string
          xml:
            name: Fault
            prefix: flt
          example: error

  # securitySchemes:

Upvotes: -3

Martin Dow
Martin Dow

Reputation: 5321

This might be worth a try: Swagger connector and Preparing the API for consumption.

There is a module for pointing at a SOAP WSDL to expose it through a Loopback server: http://strongloop.com/strongblog/soap-into-rest-apis-with-loopback-node-js/

As an API server to glue existing and new data sources, LoopBack is designed to facilitate your backend data integration. With the release of loopback-connector-soap module, you can now easily consume SOAP web services and transform them into REST APIs.

I can't yet confirm that it works, but it looks like a way of exposing a SOAP service using Swagger.

Upvotes: 1

Dima Fomin
Dima Fomin

Reputation: 1330

online "translate SOAP based web services to RESTful" is what exactly DreamFactory does. Open Source API management tool based on Swagger. Here you can read about SOAP-to-REST functionality.

Upvotes: 2

Santanu Dey
Santanu Dey

Reputation: 2978

Based on the present spec, I do not think so. It would not be easily possible to mention various aspects of a WSDL in swagger

To name a few:

  1. PortTypes
  2. Schemas and namespaces of request and response messages
  3. SOAP encodings (RPC/Literal etc.)

Upvotes: 8

Related Questions