Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
815 views
in Technique[技术] by (71.8m points)

dotnet core 3.1 swagger documentation

i'm working on dotnet core web api back end application and using swagger for endpoints documentation. i want to customize swagger.json endpoint to diffrent path so it could be accessible in our server and our angular fornt-end could consume that endpoint after deloy. i'm using this code in startup.cs in ConfigureServices

services.AddSwaggerGen(c => {

        c.SwaggerDoc("v1", new OpenApiInfo { Title = "Criistal API v1.0", Version = "v1.0" });
        /////////////////////
        c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
        {
            Description ="JWT Authorization header using the Bearer scheme. 

 Enter 'Bearer' [space] and then your token in the text input below.

Example: "Bearer 12345abcdef"",
            Name = "Authorization",
            In = ParameterLocation.Header,
            Type = SecuritySchemeType.ApiKey,
            Scheme = "Bearer"
        });

        c.AddSecurityRequirement(new OpenApiSecurityRequirement()
        {
            {
                new OpenApiSecurityScheme
                {
                    Reference = new OpenApiReference
                    {
                        Type = ReferenceType.SecurityScheme,
                        Id = "Bearer"
                    },
                    Scheme = "oauth2",
                    Name = "Bearer",
                    In = ParameterLocation.Header,

                },
                new List<string>()
            }
        });

        ////////////////////
    });

and in configure

app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Criistal API v1.0");
                c.RoutePrefix = string.Empty;
            });
question from:https://stackoverflow.com/questions/65934585/dotnet-core-3-1-swagger-documentation

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...