Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
performance
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zry
performance
Commits
2c602f14
Commit
2c602f14
authored
Nov 13, 2024
by
wyc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SwaggerOpen
parent
a7e048c2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
32 deletions
+36
-32
performance/Performance.Api/Configurations/SwaggerConfig.cs
+35
-31
performance/Performance.Api/Startup.cs
+1
-1
No files found.
performance/Performance.Api/Configurations/SwaggerConfig.cs
View file @
2c602f14
...
@@ -10,32 +10,34 @@ namespace Performance.Api.Configurations
...
@@ -10,32 +10,34 @@ namespace Performance.Api.Configurations
{
{
public
static
class
SwaggerConfig
public
static
class
SwaggerConfig
{
{
public
static
void
AddSwaggerConfiguration
(
this
IServiceCollection
services
)
public
static
void
AddSwaggerConfiguration
(
this
IServiceCollection
services
,
IConfiguration
configuration
)
{
{
if
(
services
==
null
)
throw
new
ArgumentNullException
(
nameof
(
services
));
if
(
configuration
.
GetValue
(
"SwaggerOpen"
,
true
))
services
.
AddSwaggerGen
(
c
=>
{
{
c
.
SwaggerDoc
(
"v1"
,
new
OpenApiInfo
{
Version
=
"v1.0"
,
Title
=
"绩效API接口"
}
);
if
(
services
==
null
)
throw
new
ArgumentNullException
(
nameof
(
services
)
);
var
xmlPath
=
new
string
[]
services
.
AddSwaggerGen
(
c
=>
{
{
c
.
SwaggerDoc
(
"v1"
,
new
OpenApiInfo
{
Version
=
"v1.0"
,
Title
=
"绩效API接口"
});
var
xmlPath
=
new
string
[]
{
Path
.
Combine
(
AppDomain
.
CurrentDomain
.
BaseDirectory
,
"wwwroot"
,
"Performance.Api.xml"
),
Path
.
Combine
(
AppDomain
.
CurrentDomain
.
BaseDirectory
,
"wwwroot"
,
"Performance.Api.xml"
),
Path
.
Combine
(
AppDomain
.
CurrentDomain
.
BaseDirectory
,
"wwwroot"
,
"Performance.DtoModels.xml"
),
Path
.
Combine
(
AppDomain
.
CurrentDomain
.
BaseDirectory
,
"wwwroot"
,
"Performance.DtoModels.xml"
),
Path
.
Combine
(
AppDomain
.
CurrentDomain
.
BaseDirectory
,
"wwwroot"
,
"Performance.EntityModels.xml"
),
Path
.
Combine
(
AppDomain
.
CurrentDomain
.
BaseDirectory
,
"wwwroot"
,
"Performance.EntityModels.xml"
),
};
};
foreach
(
var
item
in
xmlPath
)
foreach
(
var
item
in
xmlPath
)
{
{
c
.
IncludeXmlComments
(
item
,
true
);
c
.
IncludeXmlComments
(
item
,
true
);
}
}
//var xmlPathsss = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot", "Performance.Api.xml");
//var xmlPathsss = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot", "Performance.Api.xml");
//c.IncludeXmlComments(xmlPathsss, true);
//c.IncludeXmlComments(xmlPathsss, true);
// Token绑定到ConfigureServices
// Token绑定到ConfigureServices
var
security
=
new
OpenApiSecurityRequirement
var
security
=
new
OpenApiSecurityRequirement
{
{
{
{
new
OpenApiSecurityScheme
new
OpenApiSecurityScheme
{
{
...
@@ -43,28 +45,30 @@ public static void AddSwaggerConfiguration(this IServiceCollection services)
...
@@ -43,28 +45,30 @@ public static void AddSwaggerConfiguration(this IServiceCollection services)
},
},
new
List
<
string
>()
new
List
<
string
>()
}
}
};
};
c
.
AddSecurityRequirement
(
security
);
c
.
AddSecurityRequirement
(
security
);
c
.
AddSecurityDefinition
(
"Bearer"
,
new
OpenApiSecurityScheme
c
.
AddSecurityDefinition
(
"Bearer"
,
new
OpenApiSecurityScheme
{
{
Description
=
"JWT授权(数据将在请求头中进行传输) 直接在下框中输入Bearer {token}(注意两者之间是一个空格)"
,
Description
=
"JWT授权(数据将在请求头中进行传输) 直接在下框中输入Bearer {token}(注意两者之间是一个空格)"
,
Name
=
"Authorization"
,
Name
=
"Authorization"
,
In
=
ParameterLocation
.
Header
In
=
ParameterLocation
.
Header
});
});
});
});
}
}
}
public
static
void
UseSwaggerSetup
(
this
IApplicationBuilder
app
,
IConfiguration
configuration
)
public
static
void
UseSwaggerSetup
(
this
IApplicationBuilder
app
,
IConfiguration
configuration
)
{
{
if
(
app
==
null
)
throw
new
ArgumentNullException
(
nameof
(
app
));
if
(
app
==
null
)
throw
new
ArgumentNullException
(
nameof
(
app
));
if
(
configuration
.
GetValue
(
"SwaggerOpen"
,
true
))
app
.
UseSwagger
();
app
.
UseSwaggerUI
(
c
=>
{
{
c
.
SwaggerEndpoint
(
configuration
[
"Application:SwaggerEndpoint"
],
"v1.0"
);
app
.
UseSwagger
();
c
.
RoutePrefix
=
string
.
Empty
;
app
.
UseSwaggerUI
(
c
=>
});
{
c
.
SwaggerEndpoint
(
configuration
[
"Application:SwaggerEndpoint"
],
"v1.0"
);
c
.
RoutePrefix
=
string
.
Empty
;
});
}
}
}
}
}
}
}
performance/Performance.Api/Startup.cs
View file @
2c602f14
...
@@ -81,7 +81,7 @@ public void ConfigureServices(IServiceCollection services)
...
@@ -81,7 +81,7 @@ public void ConfigureServices(IServiceCollection services)
services
.
AddAutoMapperConfiguration
();
services
.
AddAutoMapperConfiguration
();
// swagger
// swagger
services
.
AddSwaggerConfiguration
();
services
.
AddSwaggerConfiguration
(
Configuration
);
// service repository
// service repository
services
.
AddDependencyInjectionConfiguration
();
services
.
AddDependencyInjectionConfiguration
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment