Skip to content

Instantly share code, notes, and snippets.

@justinyoo justinyoo/GetSwaggerHttpTrigger.cs Secret
Last active Jun 12, 2017

What would you like to do?
Azure Functions with Swagger
public static class GetSwaggerHttpTrigger
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, string version, TraceWriter log)
var wwwroot = Environment.GetEnvironmentVariable("WEBROOT_PATH");
var filepath = $"{wwwroot}\\swagger-{version}.yaml";
if (!File.Exists(filepath))
return req.CreateResponse(HttpStatusCode.NotFound);
var settings = new JsonSerializerSettings()
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Formatting = Formatting.Indented
var formatter = new JsonMediaTypeFormatter() { SerializerSettings = settings };
using (var reader = File.OpenText(filepath))
var yaml = await reader.ReadToEndAsync().ConfigureAwait(false);
var deserialiser = new DeserializerBuilder().Build();
var deserialised = deserialiser.Deserialize<dynamic>(yaml);
return req.CreateResponse(HttpStatusCode.OK, (object)deserialised, formatter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.