• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 101
  • Last Modified:

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
0
Member_2_7966113
Asked:
Member_2_7966113
  • 3
  • 2
1 Solution
 
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
 
Member_2_7966113Author Commented:
Much appreciated mate
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now