-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Libraries updates & improvements (#237)
- Loading branch information
Showing
14 changed files
with
266 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/TinyHelpers.AspNetCore.Swashbuckle/OpenApiOperationOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.OpenApi.Models; | ||
|
||
namespace TinyHelpers.AspNetCore.Swagger; | ||
|
||
public class OpenApiOperationOptions | ||
{ | ||
internal OpenApiOperationOptions() | ||
{ | ||
} | ||
|
||
public IList<OpenApiParameter> Parameters { get; } = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/TinyHelpers.AspNetCore.Swashbuckle/OpenApiSchemaHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Microsoft.OpenApi.Any; | ||
using Microsoft.OpenApi.Models; | ||
|
||
namespace TinyHelpers.AspNetCore.Swagger; | ||
|
||
public static class OpenApiSchemaHelper | ||
{ | ||
public static OpenApiSchema CreateStringSchema(string? defaultValue = null) | ||
{ | ||
var schema = new OpenApiSchema | ||
{ | ||
Type = "string", | ||
Default = defaultValue is not null ? new OpenApiString(defaultValue.ToString()) : null | ||
}; | ||
|
||
return schema; | ||
} | ||
|
||
public static OpenApiSchema CreateSchema<TValue>(string type, string? format = null) | ||
{ | ||
var schema = new OpenApiSchema | ||
{ | ||
Type = type, | ||
Format = format | ||
}; | ||
|
||
return schema; | ||
} | ||
|
||
public static OpenApiSchema CreateSchema<TValue>(string type, string? format, TValue? defaultValue = null) where TValue : struct | ||
{ | ||
var schema = new OpenApiSchema | ||
{ | ||
Type = type, | ||
Format = format, | ||
Default = defaultValue is not null ? new OpenApiString(defaultValue.ToString()) : null | ||
}; | ||
|
||
return schema; | ||
} | ||
|
||
public static OpenApiSchema CreateSchema(IEnumerable<string> values, string? defaultValue = null) | ||
{ | ||
var schema = new OpenApiSchema | ||
{ | ||
Type = "string", | ||
Enum = values.Select(v => new OpenApiString(v)).Cast<IOpenApiAny>().ToList(), | ||
Default = defaultValue is not null ? new OpenApiString(defaultValue.ToString()) : null | ||
}; | ||
|
||
return schema; | ||
} | ||
|
||
public static OpenApiSchema CreateSchema<TEnum>(TEnum? defaultValue = null) where TEnum : struct, Enum | ||
{ | ||
var schema = new OpenApiSchema | ||
{ | ||
Type = "string", | ||
Enum = Enum.GetValues<TEnum>().Select(e => new OpenApiString(e.ToString())).Cast<IOpenApiAny>().ToList(), | ||
Default = defaultValue.HasValue ? new OpenApiString(defaultValue.ToString()) : null | ||
}; | ||
|
||
return schema; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/TinyHelpers.AspNetCore/OpenApi/OpenApiOperationOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#if NET9_0_OR_GREATER | ||
|
||
using Microsoft.OpenApi.Models; | ||
|
||
namespace TinyHelpers.AspNetCore.OpenApi; | ||
|
||
public class OpenApiOperationOptions | ||
{ | ||
internal OpenApiOperationOptions() | ||
{ | ||
} | ||
|
||
public IList<OpenApiParameter> Parameters { get; } = []; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.