可以将Swagger用于SOAP吗?

时间:2014-09-11 01:30:11

标签: web-services rest soap swagger swagger-ui

我正在探索Swagger,我必须承认我喜欢它。

我理解Swagger主要用于RESTful Web服务,但我想知道我们是否可以使它与SOAP Web服务一起使用。 可能是将基于SOAP的Web服务转换为RESTful?或者只是通过Swagger UI调用基于SOAP的服务?一些黑客?有人做过吗?

4 个答案:

答案 0 :(得分:7)

根据现行规范,我不这么认为。在swagger

中提到WSDL的各个方面是不容易的

仅举几例:

  1. 端口类型
  2. 请求和响应消息的模式和名称空间
  3. SOAP编码(RPC / Literal等)

答案 1 :(得分:1)

这可能值得一试:Swagger connectorPreparing the API for consumption

有一个模块用于指向SOAP WSDL以通过Loopback服务器公开它:http://strongloop.com/strongblog/soap-into-rest-apis-with-loopback-node-js/

  

作为粘合现有数据源和新数据源的API服务器,LoopBack是   旨在促进您的后端数据集成。随着   发布loopback-connector-soap模块,您现在可以轻松使用   SOAP Web服务并将它们转换为REST API。

我还不能确认它是否有效,但它看起来像是一种使用Swagger公开SOAP服务的方式。

答案 2 :(得分:1)

在线"将基于SOAP的Web服务转换为RESTful"正是DreamFactory的确如此。基于Swagger的开源API管理工具。 Here您可以阅读有关SOAP-to-REST功能的信息。

答案 3 :(得分:0)

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: itconsultant89@anas.badwais.com
  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: