Skip to content

Commit

Permalink
Libraries updates & improvements (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcominerva authored Dec 11, 2024
2 parents ca6602c + 404a9c9 commit e4de061
Show file tree
Hide file tree
Showing 14 changed files with 266 additions and 154 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- cron: '0 0 1,15 * *'

env:
NET_VERSION: '7.x'
NET_VERSION: '9.x'

jobs:
analyze:
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -57,7 +57,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ?? Command-line programs to run using the OS shell.
# ?? See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -70,4 +70,4 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
# Run Linter against code base #
################################
- name: Lint Code Base
uses: github/super-linter@v4
uses: super-linter/super-linter@v7.2.0
env:
LINTER_RULES_PATH: '.'
EDITORCONFIG_FILE_NAME: '.editorconfig'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="7.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="7.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.11" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions src/TinyHelpers.AspNetCore.Swashbuckle/OpenApiOperationOptions.cs
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; } = [];
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace TinyHelpers.AspNetCore.Swagger;
Expand All @@ -8,7 +7,7 @@ internal class OpenApiParametersOperationFilter(OpenApiOperationOptions options)
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (options?.Parameters.Count > 0)
if (options.Parameters.Count > 0)
{
operation.Parameters ??= [];

Expand All @@ -18,74 +17,4 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
}
}
}
}

public class OpenApiOperationOptions
{
internal OpenApiOperationOptions()
{
}

public IList<OpenApiParameter> Parameters { get; init; } = [];
}

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;
}
}
65 changes: 65 additions & 0 deletions src/TinyHelpers.AspNetCore.Swashbuckle/OpenApiSchemaHelper.cs
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="7.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="7.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 16 additions & 0 deletions src/TinyHelpers.AspNetCore/OpenApi/OpenApiOperationOptions.cs
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#if NET9_0_OR_GREATER

using Microsoft.AspNetCore.OpenApi;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;

namespace TinyHelpers.AspNetCore.OpenApi;
Expand All @@ -10,7 +9,7 @@ internal class OpenApiParametersOperationFilter(OpenApiOperationOptions options)
{
public Task TransformAsync(OpenApiOperation operation, OpenApiOperationTransformerContext context, CancellationToken cancellationToken)
{
if (options?.Parameters.Count > 0)
if (options.Parameters.Count > 0)
{
operation.Parameters ??= [];

Expand All @@ -24,74 +23,4 @@ public Task TransformAsync(OpenApiOperation operation, OpenApiOperationTransform
}
}

public class OpenApiOperationOptions
{
internal OpenApiOperationOptions()
{
}

public IList<OpenApiParameter> Parameters { get; init; } = [];
}

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;
}
}

#endif
Loading

0 comments on commit e4de061

Please sign in to comment.