Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...