13

I have a SOAP API already defined via WSDLs. Is there any tool that I can use to convert WSDL to Open API Swagger documents?

I am assuming that I would need to write custom code to to create a Swagger 3.0 Open API YAML specification from an XML.

XML:

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

Open API Definition:

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"

Is there any .NET C# library that can be used to create YAML documents programmatically (maybe something similar to an XMLDocument)?

sandunes90
  • 455
  • 2
  • 4
  • 22

2 Answers2

8

I know this is an old question, but, I was looking for the same thing and couldn't find a decent, hassle free solution, so maybe this answer can help someone else too.

The easiest way I have found to convert a WSDL to YAML is using APIMATIC (www.apimatic.io). A free account can convert as many WSDLs (or other formats) as you want, there's no need for a subscription.

Cheers.

Adam H
  • 85
  • 1
  • 5
3

There's YamlDotNet - https://github.com/aaubry/YamlDotNet You can create a YamlStream + YamlDocument and build your document from there, similar to using XmlDocument. Another approach is to create classes to represent the swagger document and use the serialization API to generate the document, similar to using XmlSerializer.

Antoine Aubry
  • 12,203
  • 10
  • 45
  • 74