Skip to content

Commit 86fa8cc

Browse files
committed
Merge branch 'main' into v2
2 parents 7b79548 + 8dcd5c9 commit 86fa8cc

File tree

15 files changed

+153
-19
lines changed

15 files changed

+153
-19
lines changed

docs/openapi-core.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public class MyOpenApiConfigurationOptions : IOpenApiConfigurationOptions
117117
```
118118

119119
> **NOTE**:
120-
>
120+
>
121121
> * If no base URL is declared, the Azure Functions app's URL will be added as a default.
122122
> * The OpenAPI v2 (Swagger) document only shows the the first server name on both UI and document, while the OpenAPI v3 document shows the first server name on the UI and all server names on the document.
123123
@@ -896,7 +896,7 @@ Properties decorated with the `JsonIgnoreAttribute` attribute class will not be
896896

897897
### `JsonPropertyAttribute` ###
898898

899-
Properties decorated with `JsonPropertyAttribute` attribute class will use `JsonProperty.Name` value instead of their property names. In addition to this, if `JsonProperty.Required` property has `Required.Always` or `Required.DisallowNull`, the property will be recognised as the `required` field.
899+
Properties decorated with `JsonPropertyAttribute` attribute class will use `JsonProperty.Name` value instead of their property names. In addition to this, if `JsonProperty.Required` property has `Required.Always` or `Required.AllowNull`, the property will be recognised as the `required` field.
900900

901901

902902
### `JsonRequiredAttribute` ###

src/Microsoft.Azure.Functions.Worker.Extensions.OpenApi/Extensions/DocumentHelperExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public static List<OpenApiParameter> GetOpenApiParameters(this IDocumentHelper h
157157
{
158158
var parameters = element.GetCustomAttributes<OpenApiParameterAttribute>(inherit: false)
159159
.Where(p => p.Deprecated == false)
160-
.Select(p => p.ToOpenApiParameter(namingStrategy, collection))
160+
.Select(p => p.ToOpenApiParameter(namingStrategy, collection, version))
161161
.ToList();
162162

163163
// This is the interim solution to resolve:

src/Microsoft.Azure.Functions.Worker.Extensions.OpenApi/Extensions/OpenApiHttpRequestDataExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
using System.Linq;
33

44
using Microsoft.AspNetCore.Http;
5+
6+
#if NETSTANDARD2_0
7+
58
using Microsoft.AspNetCore.Http.Internal;
9+
10+
#endif
11+
612
using Microsoft.AspNetCore.WebUtilities;
713
using Microsoft.Azure.Functions.Worker.Http;
814
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions;

src/Microsoft.Azure.Functions.Worker.Extensions.OpenApi/Microsoft.Azure.Functions.Worker.Extensions.OpenApi.csproj

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="..\..\builds\worker.props" />
44

55
<PropertyGroup>
6-
<TargetFramework>netstandard2.0</TargetFramework>
6+
<TargetFrameworks>netstandard2.0;net6.0;net7.0</TargetFrameworks>
77
<IsPackable>true</IsPackable>
88
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
99
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
@@ -21,13 +21,29 @@
2121
<VersionSuffix></VersionSuffix> -->
2222
</PropertyGroup>
2323

24-
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
24+
<PropertyGroup Condition="'$(Configuration)'=='Debug' And '$(TargetFramework)'=='netstandard2.0'">
2525
<DocumentationFile>bin\Debug\netstandard2.0\Microsoft.Azure.Functions.Worker.Extensions.OpenApi.xml</DocumentationFile>
2626
</PropertyGroup>
27+
<PropertyGroup Condition="'$(Configuration)'=='Debug' And '$(TargetFramework)'=='net6.0'">
28+
<DocumentationFile>bin\Debug\net6.0\Microsoft.Azure.Functions.Worker.Extensions.OpenApi.xml</DocumentationFile>
29+
</PropertyGroup>
30+
<PropertyGroup Condition="'$(Configuration)'=='Debug' And '$(TargetFramework)'=='net7.0'">
31+
<DocumentationFile>bin\Debug\net7.0\Microsoft.Azure.Functions.Worker.Extensions.OpenApi.xml</DocumentationFile>
32+
</PropertyGroup>
2733

28-
<PropertyGroup Condition="'$(Configuration)'=='Release'">
34+
<PropertyGroup Condition="'$(Configuration)'=='Release' And '$(TargetFramework)'=='netstandard2.0'">
2935
<DocumentationFile>bin\Release\netstandard2.0\Microsoft.Azure.Functions.Worker.Extensions.OpenApi.xml</DocumentationFile>
3036
</PropertyGroup>
37+
<PropertyGroup Condition="'$(Configuration)'=='Release' And '$(TargetFramework)'=='net6.0'">
38+
<DocumentationFile>bin\Release\net6.0\Microsoft.Azure.Functions.Worker.Extensions.OpenApi.xml</DocumentationFile>
39+
</PropertyGroup>
40+
<PropertyGroup Condition="'$(Configuration)'=='Release' And '$(TargetFramework)'=='net7.0'">
41+
<DocumentationFile>bin\Release\net7.0\Microsoft.Azure.Functions.Worker.Extensions.OpenApi.xml</DocumentationFile>
42+
</PropertyGroup>
43+
44+
<ItemGroup Condition=" '$(TargetFramework)'!='netstandard2.0' ">
45+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
46+
</ItemGroup>
3147

3248
<ItemGroup>
3349
<!--<FrameworkReference Include="Microsoft.AspNetCore.App" />-->

src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Extensions/DocumentHelperExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public static List<OpenApiParameter> GetOpenApiParameters(this IDocumentHelper h
152152
{
153153
var parameters = element.GetCustomAttributes<OpenApiParameterAttribute>(inherit: false)
154154
.Where(p => p.Deprecated == false)
155-
.Select(p => p.ToOpenApiParameter(namingStrategy, collection))
155+
.Select(p => p.ToOpenApiParameter(namingStrategy, collection, version))
156156
.ToList();
157157

158158
// This is the interim solution to resolve:

src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Visitors/ObjectTypeVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private void ProcessProperties(IOpenApiSchemaAcceptor instance, string schemaNam
189189
// Add required properties to schema.
190190
var jsonPropertyAttributes = properties.Where(p => !p.Value.GetCustomAttribute<JsonPropertyAttribute>(inherit: false).IsNullOrDefault())
191191
.Select(p => new KeyValuePair<string, JsonPropertyAttribute>(p.Key, p.Value.GetCustomAttribute<JsonPropertyAttribute>(inherit: false)))
192-
.Where(p => p.Value.Required == Required.Always || p.Value.Required == Required.DisallowNull);
192+
.Where(p => p.Value.Required == Required.Always || p.Value.Required == Required.AllowNull);
193193
foreach (var attribute in jsonPropertyAttributes)
194194
{
195195
instance.Schemas[schemaName].Required.Add(attribute.Key);

src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Visitors/OpenApiSchemaAcceptor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions;
99
using Microsoft.OpenApi.Models;
1010

11+
using Newtonsoft.Json;
1112
using Newtonsoft.Json.Serialization;
1213

1314
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors
@@ -63,6 +64,7 @@ public void Accept(VisitorCollection collection, NamingStrategy namingStrategy)
6364
property.Value.GetCustomAttribute<OpenApiPropertyAttribute>(inherit: false),
6465
};
6566
attributes.AddRange(property.Value.GetCustomAttributes<ValidationAttribute>(inherit: false));
67+
attributes.AddRange(property.Value.GetCustomAttributes<JsonPropertyAttribute>(inherit: false));
6668

6769
foreach (var visitor in collection.Visitors)
6870
{

src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Visitors/RecursiveObjectTypeVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private void ProcessProperties(IOpenApiSchemaAcceptor instance, string schemaNam
195195
// Add required properties to schema.
196196
var jsonPropertyAttributes = properties.Where(p => !p.Value.GetCustomAttribute<JsonPropertyAttribute>(inherit: false).IsNullOrDefault())
197197
.Select(p => new KeyValuePair<string, JsonPropertyAttribute>(p.Key, p.Value.GetCustomAttribute<JsonPropertyAttribute>(inherit: false)))
198-
.Where(p => p.Value.Required == Required.Always || p.Value.Required == Required.DisallowNull);
198+
.Where(p => p.Value.Required == Required.Always || p.Value.Required == Required.AllowNull);
199199
foreach (var attribute in jsonPropertyAttributes)
200200
{
201201
instance.Schemas[schemaName].Required.Add(attribute.Key);

src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Visitors/TypeVisitor.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.OpenApi.Any;
1010
using Microsoft.OpenApi.Models;
1111

12+
using Newtonsoft.Json;
1213
using Newtonsoft.Json.Serialization;
1314

1415
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors
@@ -148,9 +149,9 @@ protected string Visit(IAcceptor acceptor, string name, string title, string dat
148149
{
149150
if (dataType != "object")
150151
{
151-
schema.Nullable = this.GetOpenApiPropertyNullable(attr as OpenApiPropertyAttribute);
152152
schema.Default = this.GetOpenApiPropertyDefault(attr as OpenApiPropertyAttribute);
153153
}
154+
schema.Nullable = this.GetOpenApiPropertyNullable(attr as OpenApiPropertyAttribute);
154155
schema.Description = this.GetOpenApiPropertyDescription(attr as OpenApiPropertyAttribute);
155156
schema.Deprecated = this.GetOpenApiPropertyDeprecated(attr as OpenApiPropertyAttribute);
156157
}
@@ -163,6 +164,12 @@ protected string Visit(IAcceptor acceptor, string name, string title, string dat
163164
schema.Extensions.Add("x-ms-visibility", extension);
164165
}
165166

167+
attr = attributes.OfType<JsonPropertyAttribute>().SingleOrDefault();
168+
if (!attr.IsNullOrDefault())
169+
{
170+
schema.Nullable = this.GetNewtonsoftPropertNullable(attr as JsonPropertyAttribute);
171+
}
172+
166173
schema.ApplyValidationAttributes(attributes.OfType<ValidationAttribute>());
167174
}
168175

@@ -375,7 +382,6 @@ protected string GetOpenApiPropertyDescription(OpenApiPropertyAttribute attr)
375382
return attr.Description;
376383
}
377384

378-
379385
/// <summary>
380386
/// Gets the property deprecated.
381387
/// </summary>
@@ -385,5 +391,15 @@ protected bool GetOpenApiPropertyDeprecated(OpenApiPropertyAttribute attr)
385391
{
386392
return attr.Deprecated;
387393
}
394+
395+
/// <summary>
396+
/// Gets whether Newtonsoft Serialization allows nullability based on the JsonPropertyAttribute
397+
/// </summary>
398+
/// <param name="attr"><see cref="JsonPropertyAttribute"/> instance.</param>
399+
/// <returns>Returns the property deprecated.</returns>
400+
private bool GetNewtonsoftPropertNullable(JsonPropertyAttribute attr)
401+
{
402+
return attr.Required == Required.AllowNull || attr.Required == Required.Default;
403+
}
388404
}
389405
}

test/Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Tests/Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net7.0</TargetFrameworks>
4+
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77

0 commit comments

Comments
 (0)