Skip to content

Commit f7570df

Browse files
authored
[Aspnetcore] use the term openapi (#7540)
* use openapi in aspnetcore * move back to other * add back file
1 parent 2d30714 commit f7570df

21 files changed

Lines changed: 179 additions & 86 deletions

File tree

bin/configs/other/aspnetcore-3.1.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ templateDir: modules/openapi-generator/src/main/resources/aspnetcore/3.0
55
additionalProperties:
66
packageGuid: '{3C799344-F285-4669-8FD5-7ED9B795D5C5}'
77
aspnetCoreVersion: "3.1"
8+
userSecretsGuid: "76e9e993-9159-441c-9c5b-fe95e7f4f020"

modules/openapi-generator/src/main/resources/aspnetcore/3.0/Filters/BasePathFilter.mustache

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using Swashbuckle.AspNetCore.SwaggerGen;
66
namespace {{packageName}}.Filters
77
{
88
/// <summary>
9-
/// BasePath Document Filter sets BasePath property of Swagger and removes it from the individual URL paths
9+
/// BasePath Document Filter sets BasePath property of OpenAPI and removes it from the individual URL paths
1010
/// </summary>
1111
public class BasePathFilter : IDocumentFilter
1212
{
@@ -20,29 +20,29 @@ namespace {{packageName}}.Filters
2020
}
2121

2222
/// <summary>
23-
/// Gets the BasePath of the Swagger Doc
23+
/// Gets the BasePath of the OpenAPI Doc
2424
/// </summary>
25-
/// <returns>The BasePath of the Swagger Doc</returns>
25+
/// <returns>The BasePath of the OpenAPI Doc</returns>
2626
public string BasePath { get; }
2727

2828
/// <summary>
2929
/// Apply the filter
3030
/// </summary>
31-
/// <param name="swaggerDoc">OpenApiDocument</param>
31+
/// <param name="openapiDoc">OpenApiDocument</param>
3232
/// <param name="context">FilterContext</param>
33-
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
33+
public void Apply(OpenApiDocument openapiDoc, DocumentFilterContext context)
3434
{
35-
//swaggerDoc.BasePath = BasePath;
35+
//openapiDoc.BasePath = BasePath;
3636
37-
var pathsToModify = swaggerDoc.Paths.Where(p => p.Key.StartsWith(BasePath)).ToList();
37+
var pathsToModify = openapiDoc.Paths.Where(p => p.Key.StartsWith(BasePath)).ToList();
3838
3939
foreach (var (key, value) in pathsToModify)
4040
{
4141
if (key.StartsWith(BasePath))
4242
{
4343
var newKey = Regex.Replace(key, $"^{BasePath}", string.Empty);
44-
swaggerDoc.Paths.Remove(key);
45-
swaggerDoc.Paths.Add(newKey, value);
44+
openapiDoc.Paths.Remove(key);
45+
openapiDoc.Paths.Add(newKey, value);
4646
}
4747
}
4848
}

modules/openapi-generator/src/main/resources/aspnetcore/3.0/Filters/GeneratePathParamsValidationFilter.mustache

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,28 @@ namespace {{packageName}}.Filters
2222
2323
foreach (var par in pars)
2424
{
25-
var swaggerParam = operation.Parameters.SingleOrDefault(p => p.Name == par.Name);
25+
var openapiParam = operation.Parameters.SingleOrDefault(p => p.Name == par.Name);
2626
2727
var attributes = ((ControllerParameterDescriptor)par.ParameterDescriptor).ParameterInfo.CustomAttributes.ToList();
2828
2929
// See https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1147
3030
// and https://mikeralphson.github.io/openapi/2017/03/15/openapi3.0.0-rc0
3131
// Basically OpenAPI v3 body parameters are split out into RequestBody and the properties have moved to schema
32-
if (attributes.Any() && swaggerParam != null)
32+
if (attributes.Any() && openapiParam != null)
3333
{
3434
// Required - [Required]
3535
var requiredAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RequiredAttribute));
3636
if (requiredAttr != null)
3737
{
38-
swaggerParam.Required = true;
38+
openapiParam.Required = true;
3939
}
4040

4141
// Regex Pattern [RegularExpression]
4242
var regexAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RegularExpressionAttribute));
4343
if (regexAttr != null)
4444
{
4545
var regex = (string)regexAttr.ConstructorArguments[0].Value;
46-
swaggerParam.Schema.Pattern = regex;
46+
openapiParam.Schema.Pattern = regex;
4747
}
4848

4949
// String Length [StringLength]
@@ -72,12 +72,12 @@ namespace {{packageName}}.Filters
7272

7373
if (minLength != null)
7474
{
75-
swaggerParam.Schema.MinLength = minLength;
75+
openapiParam.Schema.MinLength = minLength;
7676
}
7777

7878
if (maxLength != null)
7979
{
80-
swaggerParam.Schema.MaxLength = maxLength;
80+
openapiParam.Schema.MaxLength = maxLength;
8181
}
8282

8383
// Range [Range]
@@ -87,8 +87,8 @@ namespace {{packageName}}.Filters
8787
var rangeMin = (int)rangeAttr.ConstructorArguments[0].Value;
8888
var rangeMax = (int)rangeAttr.ConstructorArguments[1].Value;
8989
90-
swaggerParam.Schema.MinLength = rangeMin;
91-
swaggerParam.Schema.MaxLength = rangeMax;
90+
openapiParam.Schema.MinLength = rangeMin;
91+
openapiParam.Schema.MaxLength = rangeMax;
9292
}
9393
}
9494
}

modules/openapi-generator/src/main/resources/aspnetcore/3.0/Properties/launchSettings.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
"IIS Express": {
1313
"commandName": "IISExpress",
1414
"launchBrowser": true,
15-
"launchUrl": "swagger",
15+
"launchUrl": "openapi",
1616
"environmentVariables": {
1717
"ASPNETCORE_ENVIRONMENT": "Development"
1818
}
1919
},
2020
"OpenAPI": {
2121
"commandName": "Project",
2222
"launchBrowser": true,
23-
"launchUrl": "swagger",
23+
"launchUrl": "openapi",
2424
"applicationUrl": "https://localhost:5001;http://localhost:5000",
2525
"environmentVariables": {
2626
"ASPNETCORE_ENVIRONMENT": "Development"
@@ -29,9 +29,9 @@
2929
"Docker": {
3030
"commandName": "Docker",
3131
"launchBrowser": true,
32-
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
32+
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/openapi",
3333
"publishAllPorts": true,
3434
"useSSL": true
3535
}
3636
}
37-
}
37+
}

modules/openapi-generator/src/main/resources/aspnetcore/3.0/Startup.mustache

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ namespace {{packageName}}
104104
c.CustomSchemaIds(type => type.FriendlyId(true));
105105
c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{Assembly.GetEntryAssembly().GetName().Name}.xml");
106106
{{#basePathWithoutHost}}
107-
// Sets the basePath property in the Swagger document generated
107+
// Sets the basePath property in the OpenAPI document generated
108108
c.DocumentFilter<BasePathFilter>("{{{basePathWithoutHost}}}");
109109
{{/basePathWithoutHost}}
110110

111-
// Include DataAnnotation attributes on Controller Action parameters as Swagger validation rules (e.g required, pattern, ..)
111+
// Include DataAnnotation attributes on Controller Action parameters as OpenAPI validation rules (e.g required, pattern, ..)
112112
// Use [ValidateModelState] on Actions to actually validate it in C# as well!
113113
c.OperationFilter<GeneratePathParamsValidationFilter>();
114114
});
@@ -141,14 +141,16 @@ namespace {{packageName}}
141141
{{#useSwashbuckle}}
142142
app.UseSwagger(c =>
143143
{
144-
c.RouteTemplate = "swagger/{documentName}/openapi.json";
144+
c.RouteTemplate = "openapi/{documentName}/openapi.json";
145145
})
146146
.UseSwaggerUI(c =>
147147
{
148-
//TODO: Either use the SwaggerGen generated Swagger contract (generated from C# classes)
149-
c.SwaggerEndpoint("/swagger/{{#version}}{{{version}}}{{/version}}{{^version}}v1{{/version}}/openapi.json", "{{#appName}}{{{appName}}}{{/appName}}{{^appName}}{{packageName}}{{/appName}}");
148+
// set route prefix to openapi, e.g. http://localhost:8080/openapi/index.html
149+
c.RoutePrefix = "openapi";
150+
//TODO: Either use the SwaggerGen generated OpenAPI contract (generated from C# classes)
151+
c.SwaggerEndpoint("/openapi/{{#version}}{{{version}}}{{/version}}{{^version}}v1{{/version}}/openapi.json", "{{#appName}}{{{appName}}}{{/appName}}{{^appName}}{{packageName}}{{/appName}}");
150152
151-
//TODO: Or alternatively use the original Swagger contract that's included in the static files
153+
//TODO: Or alternatively use the original OpenAPI contract that's included in the static files
152154
// c.SwaggerEndpoint("/openapi-original.json", "{{#appName}}{{{appName}}}{{/appName}}{{^appName}}{{packageName}}{{/appName}} Original");
153155
}){{/useSwashbuckle}};
154156
app.UseRouting();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<meta http-equiv="refresh" content="0;URL='./swagger/'" />
1+
<meta http-equiv="refresh" content="0;URL='./openapi/'" />
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Org.OpenAPITools.sln
2+
README.md
3+
build.bat
4+
build.sh
5+
src/Org.OpenAPITools/.gitignore
6+
src/Org.OpenAPITools/Attributes/ValidateModelStateAttribute.cs
7+
src/Org.OpenAPITools/Authentication/ApiAuthentication.cs
8+
src/Org.OpenAPITools/Controllers/PetApi.cs
9+
src/Org.OpenAPITools/Controllers/StoreApi.cs
10+
src/Org.OpenAPITools/Controllers/UserApi.cs
11+
src/Org.OpenAPITools/Converters/CustomEnumConverter.cs
12+
src/Org.OpenAPITools/Dockerfile
13+
src/Org.OpenAPITools/Filters/BasePathFilter.cs
14+
src/Org.OpenAPITools/Filters/GeneratePathParamsValidationFilter.cs
15+
src/Org.OpenAPITools/Models/ApiResponse.cs
16+
src/Org.OpenAPITools/Models/Category.cs
17+
src/Org.OpenAPITools/Models/Order.cs
18+
src/Org.OpenAPITools/Models/Pet.cs
19+
src/Org.OpenAPITools/Models/Tag.cs
20+
src/Org.OpenAPITools/Models/User.cs
21+
src/Org.OpenAPITools/OpenApi/TypeExtensions.cs
22+
src/Org.OpenAPITools/Org.OpenAPITools.csproj
23+
src/Org.OpenAPITools/Program.cs
24+
src/Org.OpenAPITools/Properties/launchSettings.json
25+
src/Org.OpenAPITools/Startup.cs
26+
src/Org.OpenAPITools/appsettings.json
27+
src/Org.OpenAPITools/wwwroot/README.md
28+
src/Org.OpenAPITools/wwwroot/index.html
29+
src/Org.OpenAPITools/wwwroot/openapi-original.json

samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Filters/BasePathFilter.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Org.OpenAPITools.Filters
77
{
88
/// <summary>
9-
/// BasePath Document Filter sets BasePath property of Swagger and removes it from the individual URL paths
9+
/// BasePath Document Filter sets BasePath property of OpenAPI and removes it from the individual URL paths
1010
/// </summary>
1111
public class BasePathFilter : IDocumentFilter
1212
{
@@ -20,29 +20,29 @@ public BasePathFilter(string basePath)
2020
}
2121

2222
/// <summary>
23-
/// Gets the BasePath of the Swagger Doc
23+
/// Gets the BasePath of the OpenAPI Doc
2424
/// </summary>
25-
/// <returns>The BasePath of the Swagger Doc</returns>
25+
/// <returns>The BasePath of the OpenAPI Doc</returns>
2626
public string BasePath { get; }
2727

2828
/// <summary>
2929
/// Apply the filter
3030
/// </summary>
31-
/// <param name="swaggerDoc">OpenApiDocument</param>
31+
/// <param name="openapiDoc">OpenApiDocument</param>
3232
/// <param name="context">FilterContext</param>
33-
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
33+
public void Apply(OpenApiDocument openapiDoc, DocumentFilterContext context)
3434
{
35-
//swaggerDoc.BasePath = BasePath;
35+
//openapiDoc.BasePath = BasePath;
3636

37-
var pathsToModify = swaggerDoc.Paths.Where(p => p.Key.StartsWith(BasePath)).ToList();
37+
var pathsToModify = openapiDoc.Paths.Where(p => p.Key.StartsWith(BasePath)).ToList();
3838

3939
foreach (var (key, value) in pathsToModify)
4040
{
4141
if (key.StartsWith(BasePath))
4242
{
4343
var newKey = Regex.Replace(key, $"^{BasePath}", string.Empty);
44-
swaggerDoc.Paths.Remove(key);
45-
swaggerDoc.Paths.Add(newKey, value);
44+
openapiDoc.Paths.Remove(key);
45+
openapiDoc.Paths.Add(newKey, value);
4646
}
4747
}
4848
}

samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Filters/GeneratePathParamsValidationFilter.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,28 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
2222

2323
foreach (var par in pars)
2424
{
25-
var swaggerParam = operation.Parameters.SingleOrDefault(p => p.Name == par.Name);
25+
var openapiParam = operation.Parameters.SingleOrDefault(p => p.Name == par.Name);
2626

2727
var attributes = ((ControllerParameterDescriptor)par.ParameterDescriptor).ParameterInfo.CustomAttributes.ToList();
2828

2929
// See https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1147
3030
// and https://mikeralphson.github.io/openapi/2017/03/15/openapi3.0.0-rc0
3131
// Basically OpenAPI v3 body parameters are split out into RequestBody and the properties have moved to schema
32-
if (attributes.Any() && swaggerParam != null)
32+
if (attributes.Any() && openapiParam != null)
3333
{
3434
// Required - [Required]
3535
var requiredAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RequiredAttribute));
3636
if (requiredAttr != null)
3737
{
38-
swaggerParam.Required = true;
38+
openapiParam.Required = true;
3939
}
4040

4141
// Regex Pattern [RegularExpression]
4242
var regexAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RegularExpressionAttribute));
4343
if (regexAttr != null)
4444
{
4545
var regex = (string)regexAttr.ConstructorArguments[0].Value;
46-
swaggerParam.Schema.Pattern = regex;
46+
openapiParam.Schema.Pattern = regex;
4747
}
4848

4949
// String Length [StringLength]
@@ -72,12 +72,12 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
7272

7373
if (minLength != null)
7474
{
75-
swaggerParam.Schema.MinLength = minLength;
75+
openapiParam.Schema.MinLength = minLength;
7676
}
7777

7878
if (maxLength != null)
7979
{
80-
swaggerParam.Schema.MaxLength = maxLength;
80+
openapiParam.Schema.MaxLength = maxLength;
8181
}
8282

8383
// Range [Range]
@@ -87,8 +87,8 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
8787
var rangeMin = (int)rangeAttr.ConstructorArguments[0].Value;
8888
var rangeMax = (int)rangeAttr.ConstructorArguments[1].Value;
8989

90-
swaggerParam.Schema.MinLength = rangeMin;
91-
swaggerParam.Schema.MaxLength = rangeMax;
90+
openapiParam.Schema.MinLength = rangeMin;
91+
openapiParam.Schema.MaxLength = rangeMax;
9292
}
9393
}
9494
}

samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Org.OpenAPITools.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<PreserveCompilationContext>true</PreserveCompilationContext>
88
<AssemblyName>Org.OpenAPITools</AssemblyName>
99
<PackageId>Org.OpenAPITools</PackageId>
10-
<UserSecretsId>5437bedb-0880-4b79-b60e-a06e28fd9ff2</UserSecretsId>
10+
<UserSecretsId>76e9e993-9159-441c-9c5b-fe95e7f4f020</UserSecretsId>
1111
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
1212
<DockerfileContext>..\..</DockerfileContext>
1313
</PropertyGroup>

0 commit comments

Comments
 (0)