【问题标题】:Can Swagger be used for SOAP?Swagger 可以用于 SOAP 吗?
【发布时间】:2014-11-04 19:42:53
【问题描述】:
我正在探索Swagger,我必须承认我很喜欢它。
我了解 Swagger 主要用于 RESTful Web 服务,但我想知道我们是否可以让它与 SOAP Web 服务一起使用。
可以将基于 SOAP 的 Web 服务转换为 RESTful?或者只是通过 Swagger UI 调用基于 SOAP 的服务?一些黑客?有人做过吗?
【问题讨论】:
-
我正在使用 wcfextras (wcfextras.codeplex.com) 来丰富和自动提取 WCF 服务中的文档。输出是带有文档服务的 .xml 文件,尽管可以附加 XSLT 模板以将其显示为 html。我见过的其他工具都是商业的。
标签:
web-services
rest
soap
swagger
swagger-ui
【解决方案1】:
根据目前的规范,我不这么认为。在 swagger 中提及 WSDL 的各个方面并不容易
仅举几例:
- 端口类型
- 请求和响应消息的架构和命名空间
- SOAP 编码(RPC/文字等)
【解决方案2】:
在线“将基于 SOAP 的 Web 服务转换为 RESTful”正是 DreamFactory 所做的。基于 Swagger 的开源 API 管理工具。 Here 您可以阅读有关 SOAP-to-REST 功能的信息。
【解决方案4】:
openapi: 3.0.1
info:
version: 1.0.0
title: SOAP
description: |-
# Introduction
> ## 1.1. Purpose
IMG
>>> 
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:
【讨论】:
-
欢迎来到 Stack Overflow。没有任何解释的代码很少有帮助。 Stack Overflow 是关于学习的,而不是提供 sn-ps 来盲目复制和粘贴。请编辑您的问题并解释它如何回答所提出的具体问题。见How to Answer。