Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to parse Swagger adaptation virtual directory and secondary directory

Shulou Source: shulou.com Published: 2022-06-01 03:29:57 11月15日 Update

Xiaobian today takes you to understand how to parse Swagger adaptation virtual directory and secondary directory. The knowledge points introduced in this article are very detailed. Friends who feel helpful can browse the content of the article together with Xiaobian, hoping to help more friends who want to solve this problem find the answer to the question. Let's learn more about "how to parse Swagger adaptation virtual directory and secondary directory" together with Xiaobian.

preface

With the advent of front-end separation patterns and microservice architectures, Web APIs have become increasingly important and pervasive. Gateway technology, which emerged later, made developers more inclined to use secondary/multi-level directories to expose Web APIs, one is to expose fewer ports and facilitate management; the other is to handle some common transactions in the gateway, such as authentication. However, swagger is adapted to the root directory by default. To adapt to the secondary/multi-level directory, additional processing is required, and the development environment must be distinguished from other environments. One idea is to let the Web API be in the secondary directory in the development environment, which can be simulated locally through nginx and iis virtual directories, but this idea is obviously a little troublesome. Another idea is to configure multiple environments.

step

1. Install Swagger

Install-Package Swashbuckle.AspNetCore

2. Configuring Swagger Services

services.AddSwaggerGen(c =>{ c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });});

3. Configuring swagger middleware

4. Configure appsettings.json

Add virtualPath configuration to appsettings.json:

in appsettings. Add virtualpath configuration to Development.json:

test

1. Development environment testing

2. Simulated production environment test

Modify launchSettings.json to change environment variable parameters:

Prepare nginx.conf and start nginx.

Access to secondary directories

Thank you for reading, the above is "how to parse Swagger adaptation virtual directory and secondary directory" all the content, learn friends to quickly operate it. I believe that Xiaobian will definitely bring you better quality articles. Thank you for your support of the website!

Tags: Catalog environment configuration adaptation development ideas friends tests content articles is in knowledge gateway follow problem processing help service obvious important Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Apple Microsoft Shulou Technology Shulou Tech Info