Skip to content

Generated Swagger is Empty #225

@VTR-AReed

Description

@VTR-AReed

I have an existing .NET 6 Project I've been working on, and I decided to add the OpenAPI Extension and generate a swagger, however the swagger generated is empty. I have cleaned and rebuilt, I have deleted obj and bin, I have tried everything, but my same functions copied to another project work just fine, but for some reason in this project, which has no build errors whatsoever (with all trace logs on), continues to generate an empty swagger.json.

CSPROJ:

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <AssemblyName>myname.Functions</AssemblyName>
    <RootNamespace>myname.Functions</RootNamespace>
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
    <DocumentationFile>myname.Functions.xml</DocumentationFile>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.7.2-preview" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
    <PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.12.2" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
    <PackageReference Include="Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration" Version="2.0.0-beta02" />
    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.12.2" />
  </ItemGroup>

One of my test functions:

    {
        [FunctionName("OpenAPI")]
        [OpenApiOperation(operationId: "Run", tags: new[] { "name" })]
        [OpenApiParameter(name: "name", In = ParameterLocation.Query, Required = true, Type = typeof(string), Description = "The Name parameter")]
        [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "text/plain", bodyType: typeof(string), Description = "The OK response")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string name = req.Query["name"];

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = name ?? data?.name;

            string responseMessage = string.IsNullOrEmpty(name)
                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This HTTP triggered function executed successfully.";

            return new OkObjectResult(responseMessage);
        }
    }

Generated Swagger.Json:

{
  "swagger": "2.0",
  "info": {
    "title": "Azure Functions OpenAPI Extension",
    "version": "1.0.0"
  },
  "host": "localhost:7071",
  "basePath": "/api",
  "schemes": [
    "http"
  ],
  "paths": { }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions