以编程方式从WSDL / XML生成Swagger YAML Open API Spec

时间:2018-05-31 23:28:53

标签: rest yaml swagger openapi yamldotnet

我已经通过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)?

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我知道这是一个老问题,但是,我一直在寻找相同的东西,却找不到合适的,无忧的解决方案,因此也许这个答案也可以对其他人有所帮助。

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

干杯。