Skip to content

Commit

Permalink
Merge pull request #857 from baranacikgoz/main
Browse files Browse the repository at this point in the history
Added Guid schema processor
  • Loading branch information
iammukeshm committed Apr 27, 2023
2 parents a2788bd + 07052bf commit 2a5f327
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Infrastructure/OpenApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ internal static IServiceCollection AddOpenApiDocumentation(this IServiceCollecti
document.OperationProcessors.Add(new SwaggerHeaderAttributeProcessor());
document.SchemaProcessors.Add(new SwaggerGuidSchemaProcessor());
var fluentValidationSchemaProcessor = serviceProvider.CreateScope().ServiceProvider.GetService<FluentValidationSchemaProcessor>();
document.SchemaProcessors.Add(fluentValidationSchemaProcessor);
});
Expand Down
19 changes: 19 additions & 0 deletions src/Infrastructure/OpenApi/SwaggerGuidSchemaProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using NJsonSchema;
using NJsonSchema.Generation;

namespace FSH.WebApi.Infrastructure.OpenApi;
public class SwaggerGuidSchemaProcessor : ISchemaProcessor
{
public void Process(SchemaProcessorContext context)
{
var type = context.ContextualType;
var schema = context.Schema;

// Check if the type is a Guid
if (type == typeof(Guid))
{
schema.Type = JsonObjectType.String;
schema.Format = "uuid";
}
}
}

0 comments on commit 2a5f327

Please sign in to comment.