Skip to content
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

Generated swagger works locally, but is empty when deployed in Azure #359

Closed
SamVanhoutte opened this issue Feb 10, 2022 · 3 comments
Closed
Labels
investigating Need time to investigating

Comments

@SamVanhoutte
Copy link

Describe the issue
I leverage the OpenApiOperation attribute, and the related attributes, to describe several HttpTrigger functions in my netcoreapp3.1 Azure Functions project.
It works successfully, when I navigate to my local swagger endpoint: 'http://localhost:7071/api/swagger/ui', but when I have deployed it (through Github Actions), the generated Swagger on the endpoint 'https://mysite-tst.azurewebsites.net/api/swagger.json' is empty and does not contain operations.
The UI page indicates: No operations defined in spec!

To Reproduce
Steps to reproduce the behavior:

  1. Add relevant attributes such as OpenApiOperation, OpenApiSecurity, OpenApiResponseWithBody... to functions that contain a HttpTrigger binding.
  2. Run the Azure Functions project locally
  3. Navigate to http://localhost:7071/api/swagger/ui - see relevant and correct Swagger UI
  4. Deploy the Azure Functions project to Azure through CI/CD (using RELEASE version, zip deployment)
  5. Navigate to https://mysite-tst.azurewebsites.net/api/swagger.json - see empty json file
{
  "swagger": "2.0",
  "info": {
    "title": "OpenAPI Document on Azure Functions",
    "version": "1.0.0"
  },
  "host": "mysite-tst.azurewebsites.net",
  "basePath": "/api",
  "schemes": [
    "https"
  ],
  "paths": { }
}

Expected behavior
Swagger file should be the same , regardless of hosting environment

@RealGoodAnthony
Copy link

From the FAQ: #306

@justinyoo
Copy link
Contributor

@SamVanhoutte Thanks for the issue! Do you happen to have a sharable GitHub repository that I can reproduce the same error on my end?

@justinyoo justinyoo added the investigating Need time to investigating label Feb 11, 2022
@SamVanhoutte
Copy link
Author

Hello @justinyoo
Thanks to the suggestion of @RealGoodAnthony , I changed my build so that the dotnet publish was not using the .sln , but was pointing to the specific csproj project file. And that seemed to solve the problem.

So, I did the following steps:

  1. Created a copy of the .sln file and removed the test project from that
  2. Updated the csproj file of the Test project to include the following line:
    <IsPublishable>false</IsPublishable>
  3. Changed the following line:
    dotnet publish ${{ env.SOLUTION }} -c ${{ env.BUILD_CONFIG }} -o ${{env.DOTNET_ROOT}}/myapp
    to
    dotnet publish ${{ env.WORKER_PROJECT }} -c ${{ env.BUILD_CONFIG }} -o ${{env.DOTNET_ROOT}}/myapp
    in my .yaml workflow

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

No branches or pull requests

3 participants