【问题标题】:Generate Swagger YAML Open API Spec programmatically from WSDL/XML从 WSDL/XML 以编程方式生成 Swagger YAML Open API Spec
【发布时间】:2018-05-31 23:28:53
【问题描述】:

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

【问题讨论】:

    标签: rest yaml swagger openapi yamldotnet


    【解决方案1】:

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

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

    干杯。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2022-12-13
        • 1970-01-01
        • 2013-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-08
        • 2021-09-01
        • 1970-01-01
        相关资源
        最近更新 更多