Swagger Code Generator from C Sharp

Hello Experts,

Can someone be kind enough to let me know if they're any swagger code generators that can generate swagger code from C#.

Basically I would like to generate the following c# code to swagger;

using System.Net;

const double revenuePerkW = 0.12; 
const double technicianCost = 250; 
const double turbineCost = 100;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{   

    //Get request body
    dynamic data = await req.Content.ReadAsAsync<object>();
    int hours = data.hours;
    int capacity = data.capacity;

    //Formulas to calculate revenue and cost
    double revenueOpportunity = capacity * revenuePerkW * 24;  
    double costToFix = (hours * technicianCost) +  turbineCost;
    string repairTurbine;

    if (revenueOpportunity > costToFix){
        repairTurbine = "Yes";
    }
    else {
        repairTurbine = "No";
    }

    return req.CreateResponse(HttpStatusCode.OK, new{
        message = repairTurbine,
        revenueOpportunity = "$"+ revenueOpportunity,
        costToFix = "$"+ costToFix         
    }); 
}

Open in new window


Thanks

Carlton
LVL 1
Member_2_7966113Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Member_2_7966113Author Commented:
Basically I would like to take the c# code posted above and convert to swagger so that it turns out like this:

swagger: '2.0'
info:
  title: azurefunctionss.azurewebsites.net
  version: 1.0.0
host: azurefunctionss.azurewebsites.net
basePath: /
schemes:
  - https
  - http
paths:
  /api/TurbineRepair:
    post:
      operationId: CalculateCosts
      description: Determines if a technician should be sent for repair
      summary: Calculates costs
      x-ms-summary: Calculates costs
      x-ms-visibility: important
      produces:
        - application/json
      consumes:
        - application/json
      parameters:
        - name: body
          in: body
          description: Hours and capacity used to calculate costs
          x-ms-summary: Hours and capacity
          x-ms-visibility: important
          required: true
          schema:
            type: object
            properties:
              hours:
                description: The amount of effort in hours required to conduct repair
                type: number
                x-ms-summary: Hours
                x-ms-visibility: important
              capacity:
                description: The max output of a turbine in kilowatts
                type: number
                x-ms-summary: Capacity
                x-ms-visibility: important
      responses:
        '200':
          description: Message with cost and revenue numbers
          x-ms-summary: Message
          schema:
            type: object
            properties:
              message:
                type: string
                description: Returns Yes or No depending on calculations
                x-ms-summary: Message
              revenueOpportunity:
                type: string
                description: The revenue opportunity cost
                x-ms-summary: RevenueOpportunity
              costToFix:
                type: string
                description: The cost in $ to fix the turbine
                x-ms-summary: CostToFix
      security:
        - apikeyQuery: []
definitions: {}
securityDefinitions:
  apikeyQuery:
    type: apiKey
    name: code
    in: query

Open in new window

0
Eddie ShipmanAll-around developerCommented:
Why do you need that? Use Swashbuckle, add XMLDocs to your code and it will generate the SwaggerUI for you. I don't know of a YAML generation utility for C#.
1
Member_2_7966113Author Commented:
Hi Eddie,

I'll have to google Swashbuckle as I've never heard of it.
0
Eddie ShipmanAll-around developerCommented:
This is the Nuget package:

https://www.nuget.org/packages/Swashbuckle/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Member_2_7966113Author Commented:
Much appreciated mate
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.