简体   繁体   中英

Azure Pipeline - build and gen swagger doc

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! 在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM