Skip to content

Commit cda74b5

Browse files
authored
Merge pull request #22 from rpagyc/master
Added ContentType field in RequestBody attribute
2 parents 6856689 + c883bf4 commit cda74b5

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

src/Simplify.Web.Swagger/CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [1.1.0] - 2025-10-02
4+
5+
### Added
6+
7+
- ContentType field in RequestBody attribute
8+
39
## [1.0.0] - 2024-06-05
410

511
### Dependencies
@@ -53,4 +59,4 @@
5359

5460
### Added
5561

56-
- Initial version with controllers list including response types handling
62+
- Initial version with controllers list including response types handling

src/Simplify.Web.Swagger/ControllerActionsFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private static OpenApiRequestBody CreateRequestBody(Type controllerType, Documen
137137

138138
request.Content = new Dictionary<string, OpenApiMediaType>
139139
{
140-
["application/json"] = new() { Schema = context.SchemaGenerator.GenerateSchema(item.Model, context.SchemaRepository) }
140+
[item.ContentType] = new() { Schema = context.SchemaGenerator.GenerateSchema(item.Model, context.SchemaRepository) }
141141
};
142142

143143
return request;
@@ -164,4 +164,4 @@ private static OpenApiResponse CreateResponse(ProducesResponseAttribute produces
164164

165165
return response;
166166
}
167-
}
167+
}

src/Simplify.Web.Swagger/RequestBodyAttribute.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ namespace Simplify.Web.Swagger;
1010
/// Initializes an instance of <see cref="RequestBodyAttribute" />.
1111
/// </remarks>
1212
/// <param name="model">The request body model type.</param>
13+
/// <param name="contentType">The content type associated with the request.</param>
1314
[AttributeUsage(AttributeTargets.Class)]
14-
public class RequestBodyAttribute(Type model) : Attribute
15+
public class RequestBodyAttribute(Type model, string contentType = "application/json") : Attribute
1516
{
1617
/// <summary>
1718
/// Request body model type
@@ -20,4 +21,12 @@ public class RequestBodyAttribute(Type model) : Attribute
2021
/// The model.
2122
/// </value>
2223
public Type Model { get; private set; } = model ?? throw new ArgumentNullException(nameof(model));
23-
}
24+
25+
/// <summary>
26+
/// Gets the type of the content.
27+
/// </summary>
28+
/// <value>
29+
/// The type of the content.
30+
/// </value>
31+
public string ContentType { get; private set; } = contentType;
32+
}

src/Simplify.Web.Swagger/Simplify.Web.Swagger.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
1010
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1111

12-
<Version>1.0</Version>
12+
<Version>1.1</Version>
1313

1414
<Description>Swagger extensions for Simplify.Web web-framework</Description>
1515
<Product>Simplify</Product>
@@ -39,4 +39,4 @@
3939
<None Include="CHANGELOG.md" Pack="true" PackagePath="\" />
4040
<None Include="..\..\LICENSE.txt" Pack="true" PackagePath="\" />
4141
</ItemGroup>
42-
</Project>
42+
</Project>

0 commit comments

Comments
 (0)