You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
usingSystem.Net;usingSystem.Net.Mime;usingMicrosoft.AspNetCore.Http;usingMicrosoft.AspNetCore.Mvc;usingMicrosoft.Azure.Functions.Worker;usingMicrosoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;usingMicrosoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;usingMicrosoft.Azure.WebJobs.Extensions.OpenApi.Core.Resolvers;usingMicrosoft.Extensions.Logging;usingMicrosoft.OpenApi.Models;usingNewtonsoft.Json.Serialization;namespacePocApiDescFunction;publicclassHttpHelloMe{privatereadonlyILogger<HttpHelloMe>_logger;publicHttpHelloMe(ILogger<HttpHelloMe>logger){_logger=logger;}[Function(nameof(HttpHelloMe))][OpenApiOperation(operationId:"Greeting",tags:["GM"])][OpenApiParameter(name:"name",In=ParameterLocation.Path,Required=true,Type=typeof(string),Description="The name of the person.")][OpenApiResponseWithBody(statusCode:HttpStatusCode.OK,contentType:MediaTypeNames.Application.Json,bodyType:typeof(Hello),Description="It is always a great day to have a great day!",Example=typeof(HelloOpenApiExample))][OpenApiResponseWithoutBody(statusCode:HttpStatusCode.NotFound,Description="Non alpha name is not allowed.")]publicIActionResultRun([HttpTrigger(AuthorizationLevel.Anonymous,"get",Route="hello/{name:alpha}")]HttpRequestreq,stringname){_logger.LogInformation("Going to say GM to {name}.",name);returnnewOkObjectResult(newHello($"GM, {name}!"));}}publicclassHelloOpenApiExample:OpenApiExample<Hello>{publicoverrideIOpenApiExample<Hello>Build(NamingStrategy?namingStrategy=null){Examples.Add(OpenApiExampleResolver.Resolve("{name=John}","John appears!",newHello("GM, John!"),namingStrategy));Examples.Add(OpenApiExampleResolver.Resolve("{name=Sandy}","Sandy appears!",newHello("GM, Sandy!"),namingStrategy));returnthis;}}publicrecordHello(stringMessage);
outputs
openapi: 3.0.1info:
title: OpenAPI Document on Azure Functionsdescription: This is the OpenAPI Document on Azure Functionsversion: 1.0.0servers:
- url: https://poc-apim-function.azurewebsites.net/apipaths:
'/hello/{name}':
get:
tags:
- GMoperationId: Greetingparameters:
- name: namein: pathdescription: The name of the person.required: trueschema:
type: stringresponses:
'200':
description: It is always a great day to have a great day!content:
application/json:
schema:
$ref: '#/components/schemas/hello'example: '{"message":"GM, John!"}'examples:
'{name=John}':
summary: John appears!value: '{"message":"GM, John!"}''{name=Sandy}':
summary: Sandy appears!value: '{"message":"GM, Sandy!"}''404':
description: Non alpha name is not allowed.components:
schemas:
hello:
type: objectproperties:
message:
type: string
The text was updated successfully, but these errors were encountered:
Given the function
outputs
The text was updated successfully, but these errors were encountered: