Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate Swagger YAML Open API Spec programmatically from WSDL/XML

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)?

like image 556
sandunes90 Avatar asked May 31 '18 23:05

sandunes90


People also ask

How do I create an OpenAPI Swagger spec?

How to generate OpenAPI from existing APIs. Head over to Swagger Inspector, and insert the end point of the resource you want to have documented. You can then navigate to the right panel from the History section of Swagger Inspector, and click "Create API definition" to create the OAS definition.

Is Swagger same as WSDL?

The objective of Swagger is to create a “RESTful contract for your API, detailing all of its resources and operations in a human and machine-readable format.” In this sense it is a functional equivalent of WSDL documents for SOAP, providing automatically generated descriptions that make it easier to discover and ...


2 Answers

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.

like image 111
Adam H Avatar answered Oct 05 '22 06:10

Adam H


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.

like image 38
Antoine Aubry Avatar answered Oct 05 '22 06:10

Antoine Aubry