8

我已经通过 WSDL 定义了一个 SOAP API。是否有任何工具可用于将 WSDL 转换为 Open API Swagger 文档?

我假设我需要编写自定义代码来从 XML 创建 Swagger 3.0 Open API YAML 规范。

XML:

<country>
 <name>ABC</name>
 <population>100</population>
 <political_system>
  <system_type>Democracy</system_type>
  <legislature>bicameral</legislature>
</country>

开放 API 定义:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: SysCountry  
servers:
  - url: http://localhost:5595/api/
paths:
 /Country:
  get:
   tags:
    -countries
   responses:
    '200':
      description:List of countries
      content:
       application/json:
        schema:
         $ref:"#/components/schemas/Countries
  post:
   summary:Create a country
   tags:
    -Conuntries
   requestBody:
    required: true
    content:
          application/json:
           schema: 
            $ref: '#/components/schemas/Country'
    responses:
        '201':
          description: Null response
components:
  schemas:
    Country:
      type: object
      required:
        - name
      properties:
        name:
          type: string
        population:
          type: integer
        political_system:
          type: object
          properties:
            system_type:
              type: string
            legislature:
              type:string
    Countries:
      type: array
      items:
        $ref: "#/components/schemas/Country"

是否有任何 .NET C# 库可用于以编程方式创建 YAML 文档(可能类似于 XMLDocument)?

4

2 回答 2

4

我知道这是一个老问题,但是,我一直在寻找同样的东西,但找不到一个体面、无忧的解决方案,所以也许这个答案也可以帮助其他人。

我发现将 WSDL 转换为 YAML 的最简单方法是使用 APIMATIC ( www.apimatic.io )。免费帐户可以转换任意数量的 WSDL(或其他格式),无需订阅。

干杯。

于 2020-08-13T10:47:20.700 回答
3

有 YamlDotNet - https://github.com/aaubry/YamlDotNet 您可以创建一个 YamlStream + YamlDocument 并从那里构建您的文档,类似于使用 XmlDocument。另一种方法是创建类来表示 swagger 文档并使用序列化 API 生成文档,类似于使用 XmlSerializer。

于 2018-06-01T07:06:46.003 回答