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



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

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

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

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

干杯。

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

最新更新