1

My project is an AspNet Core 2.2 Api, I am building it in Azure Pipelines (classic) I want to generate the swagger document during an azure pipeline build - for this I am using Swashbuckle.AspNetCore.Cli and the documents in Retrieve Swagger Directly from a Startup Assembly

  1. I have a Use .NET Core task set to 2.2 at the beginning of the job
  2. I have installed the tools using .NET Core task with custom tool command with arguments install swashbuckle.aspnetcore.cli --version 5.0.0-rc4 --global, this seemed to work; If I run this task again it fails with message that tool is already installed.
  3. Then in my CI Build, I added a .NET Core task with settings

    • command to Custom
    • Path to Project(s) to the path csproj file
    • Custom command to swagger
    • Arguments to tofile --output $(Build.ArtifactStagingDirectory)/swagger.json $($(Build.ArtifactStagingDirectory)_Dxxxxx.Api.dll v1

I'm getting this error No executable found matching command "dotnet-swagger"

Help! enter image description here

Sherif Botros
  • 105
  • 1
  • 7
  • Try to add in your `.csproj` this: ` ` – Shayki Abramczyk Jan 08 '20 at 07:57
  • Have you tried in your local vs? This error seems has no relation to Azure DevOps, please follow https://github.com/domaindrivendev/Swashbuckle.AspNetCore#swashbuckleaspnetcorecli and do this in local vs see if you can reproduce the problem. Most likely the cli tool is not installed correctly or there's a version conflict between this tool and your core sdk. – mbb5079 Jan 08 '20 at 08:46
  • I have not found a specific resolution to the issue - I have added the `DotNetCliToolRefernce` per @ShaykiAbramczyk comments. However I worked around it by adding a Command Line Task and executed the swagger.exe directly from this task – Sherif Botros Jan 10 '20 at 03:17

1 Answers1

0

Here is a working example using the JAR maintained by the Swagger Codegen team.

I used the public microsoft speech-to-text-api-v3 API but feel free to change it.

trigger:
  - master

variables:
  jar_version: 3.0.29


- job: swagger_client
  pool:
    vmImage: 'ubuntu-latest'
  steps:
  - task: JavaToolInstaller@0
    inputs:
      versionSpec: '11'
      jdkArchitectureOption: 'x64'
      jdkSourceOption: 'PreInstalled'
    displayName: 'Set-up Java'
  - script: |
      java -version
      wget https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/$(jar_version)/swagger-codegen-cli-$(jar_version).jar -O swagger-codegen-cli.jar
      java -jar swagger-codegen-cli.jar generate \
        -i https://westus.dev.cognitive.microsoft.com/docs/services/speech-to-text-api-v3-0/export\?DocumentFormat\=Swagger\&ApiName\=Speech%20to%20Text%20API%20v3.0 \
        -l python \
        -o lib/python-client
  - task: DownloadPipelineArtifact@2
    inputs:
      patterns: 'python-client/**'
      path: $(Build.SourcesDirectory)/lib/python-client
Michel Hua
  • 1,614
  • 2
  • 23
  • 44