Skip to content

Generated Swagger is Empty #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
VTR-AReed opened this issue Sep 2, 2021 · 9 comments
Closed

Generated Swagger is Empty #225

VTR-AReed opened this issue Sep 2, 2021 · 9 comments

Comments

@VTR-AReed
Copy link

VTR-AReed commented Sep 2, 2021

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": { }
}
@choipureum
Copy link
Contributor

I understand that NET.6 is not yet supported. You can run it in a NET.5 environment.

@VTR-AReed
Copy link
Author

I understand that NET.6 is not yet supported. You can run it in a NET.5 environment.

There are many .NET 6 examples linked on the main readme, and downloading and building any of them they work, (and have identical setups to my project) for whatever reason my specific project continues to generate a blank one :(

@justinyoo
Copy link
Contributor

@VTR-AReed How many *.deps.json files does your Debug/net6.0/ or Debug/net6.0/bin directory have? If there are multiple *.deps.json files, it's causing the issue.

Could you confirm that on your end?

@level120
Copy link
Contributor

level120 commented Sep 3, 2021

I think this issue similar #217
There is a bug and fixed recently but not deployed now.

@VTR-AReed
Copy link
Author

@VTR-AReed How many *.deps.json files does your Debug/net6.0/ or Debug/net6.0/bin directory have? If there are multiple *.deps.json files, it's causing the issue.

Could you confirm that on your end?

This is the results of looking for *.deps.json
image

@VTR-AReed
Copy link
Author

@VTR-AReed How many *.deps.json files does your Debug/net6.0/ or Debug/net6.0/bin directory have? If there are multiple *.deps.json files, it's causing the issue.

Could you confirm that on your end?

I have confirmed this to be the case, I removed the *.deps.json produced by my referenced libraries and the spec started working!

@justinyoo
Copy link
Contributor

@VTR-AReed Glad it's sorted out! Please wait for a few more days until the fix #217 is released to v0.9.0-preview

@dominicusmento
Copy link

When will this new version be released? this fix is really needed.. at least as v0.8.2-preview

@janhjordie
Copy link

I'm also looking forward to get this fix. I also face the same issue on Azure

Thanks
Jan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants