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

Empty swagger when using v0.9.0 with solution that includes a test project #306

Open
buntagonalprism opened this issue Nov 3, 2021 · 8 comments
Labels
documentation Improvements or additions to documentation

Comments

@buntagonalprism
Copy link

Documentation / Feature Proposal
The fix in #217 to detect the root project has definitely resolved some of the issues with the generated swagger document being empty.

However immediately after upgrading to v0.9.0-preview, using .NET 5 isolated functions, our swagger was empty when our function app was built and deployed from Azure Pipelines. The root cause turned out to be that the fix in #217 was treating our test project as the root project. I suppose this is technically correct since the test project referenced all our other projects.

We were able to work around the issue by updating the build task in our Azure Pipelines yaml file to skip building test projects, so there was no .deps.json produced to be incorrectly detected as the root project.

  - task: DotNetCoreCLI@2
    displayName: Build project
    inputs:
      projects: |
        **/*.csproj
        !**/*Test.csproj   

I thought I'd raise this issue in case anyone else was still having problems with empty swagger, and to propose either of the following solutions to help prevent others encountering the same problem:

  • A documentation update to explicitly state that test projects should not be built for swagger generation to work
  • A feature that the root project detection should ignore test projects
@justinyoo justinyoo added the documentation Improvements or additions to documentation label Nov 4, 2021
@justinyoo
Copy link
Contributor

@buntagonalprism Thanks for the tip! I will take a further look. Based on your research and suggestion, I would update the document for now so that others can avoid the similar situations.

@DanMannMann
Copy link

Facing the same issue here, using 3.1 Functions and 0.9.0

Looking over #217, it would be a little slower but I'd suggest to load the discovered runtimes and scan for an assembly attribute e.g. OpenApiRootAttribute, to allow developers to override the automatic discovery behaviour.

@Alan-Hinton
Copy link

We were able to work around the issue by updating the build task in our Azure Pipelines yaml file to skip building test projects, so there was no .deps.json produced to be incorrectly detected as the root project.

  - task: DotNetCoreCLI@2
    displayName: Build project
    inputs:
      projects: |
        **/*.csproj
        !**/*Test.csproj   

@buntagonalprism thanks for the work around for this issue. I was wondering how you run your tests in your pipeline if you are not building the test project?

@buntagonalprism
Copy link
Author

@Alan-Hinton apologies for not replying sooner, I was on holidays at the time of your message.

There is no need to build the test project, the test runner will do what it needs to in order to run the tests.

In our current pipeline rather than using the exclude rule !**\*Tests.csproj we're instead only specifying the function app source project as the input to build command; this still has the same affect of not building the test project and working around the empty swagger issue.

Extract from our YAML pipeline:

  - task: DotNetCoreCLI@2
    displayName: Build project
    inputs:
      command: 'build'
      projects: |
        SRC_PROJECT_NAME/SRC_PROJECT_NAME.csproj
      arguments: --output build_output --configuration Release

  - task: DotNetCoreCLI@2
    displayName: Run tests
    inputs:
      command: 'test'
      projects: '**/*Tests.csproj'
      publishTestResults: true
      arguments: '--collect:"XPlat Code Coverage"'

@riccardone
Copy link

please note the initial pattern specified in this issue point to **/*Test.csproj instead of **/*Tests.csproj

Just in case you copy and paste like I did :)

@jasiozet
Copy link

jasiozet commented Sep 20, 2022

The current situation feels problematic.
What about scenarios where you have to build and deploy tests, have anyone found other workarounds?

@Joeghanoe
Copy link

I agree with @jasiozet, at this point in time we are still not able to deploy our tests with our code. This remains an issue..

@HaochenQ
Copy link

HaochenQ commented Nov 4, 2023

Please fix this. Not able to access the swagger UI in 2023 because of this issue.

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

No branches or pull requests

8 participants