Skip to content

Commit e35da84

Browse files
verdie-gbkoelman
andauthored
openapi: support validation attributes (#1477)
* openapi: support validation attributes * wip * Improve NSwag tests * Fix some warnings * Address some comments * more stuff * Discard unrelated changes * Discard more unrealted changes * Add test for length attribute on collection * Address PR comments * stuff * More stuff * Fix .NET 8 things * Fix coding style * Set ConvertValueInInvariantCulture * Add Kiota tests * Address some PR comments * Add missing properties in happy test * Fix CS * Convert DateTime to UTC server-side * Seal classes * Apply suggestions from code review Co-authored-by: Bart Koelman <[email protected]> * Address PR comments * Update test/OpenApiTests/ModelStateValidation/ModelStateValidationTests.cs Co-authored-by: Bart Koelman <[email protected]> * Address comments * Add back exclusive range * Address comment --------- Co-authored-by: Bart Koelman <[email protected]>
1 parent 459ced3 commit e35da84

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+6237
-1
lines changed

Diff for: package-versions.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<CodeAnalysisFrozenVersion>4.1.0</CodeAnalysisFrozenVersion>
55
<DemystifierFrozenVersion>0.4.1</DemystifierFrozenVersion>
66
<HumanizerFrozenVersion>2.14.1</HumanizerFrozenVersion>
7-
<SwashbuckleFrozenVersion>6.6.1</SwashbuckleFrozenVersion>
7+
<SwashbuckleFrozenVersion>6.6.2</SwashbuckleFrozenVersion>
88
<NewtonsoftJsonFrozenVersion>13.0.3</NewtonsoftJsonFrozenVersion>
99

1010
<!-- Non-published dependencies (these are safe to update, won't cause a breaking change) -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// <auto-generated/>
2+
using Microsoft.Kiota.Abstractions.Extensions;
3+
using Microsoft.Kiota.Abstractions.Store;
4+
using Microsoft.Kiota.Abstractions;
5+
using Microsoft.Kiota.Serialization.Form;
6+
using Microsoft.Kiota.Serialization.Json;
7+
using Microsoft.Kiota.Serialization.Multipart;
8+
using Microsoft.Kiota.Serialization.Text;
9+
using OpenApiKiotaEndToEndTests.ModelStateValidation.GeneratedCode.SocialMediaAccounts;
10+
using System.Collections.Generic;
11+
using System.IO;
12+
using System.Linq;
13+
using System.Threading.Tasks;
14+
using System;
15+
namespace OpenApiKiotaEndToEndTests.ModelStateValidation.GeneratedCode {
16+
/// <summary>
17+
/// The main entry point of the SDK, exposes the configuration and the fluent API.
18+
/// </summary>
19+
public class ModelStateValidationClient : BaseRequestBuilder
20+
{
21+
/// <summary>The socialMediaAccounts property</summary>
22+
public SocialMediaAccountsRequestBuilder SocialMediaAccounts
23+
{
24+
get => new SocialMediaAccountsRequestBuilder(PathParameters, RequestAdapter);
25+
}
26+
/// <summary>
27+
/// Instantiates a new <see cref="ModelStateValidationClient"/> and sets the default values.
28+
/// </summary>
29+
/// <param name="backingStore">The backing store to use for the models.</param>
30+
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
31+
public ModelStateValidationClient(IRequestAdapter requestAdapter, IBackingStoreFactory backingStore = default) : base(requestAdapter, "{+baseurl}", new Dictionary<string, object>())
32+
{
33+
ApiClientBuilder.RegisterDefaultSerializer<JsonSerializationWriterFactory>();
34+
ApiClientBuilder.RegisterDefaultSerializer<TextSerializationWriterFactory>();
35+
ApiClientBuilder.RegisterDefaultSerializer<FormSerializationWriterFactory>();
36+
ApiClientBuilder.RegisterDefaultSerializer<MultipartSerializationWriterFactory>();
37+
ApiClientBuilder.RegisterDefaultDeserializer<JsonParseNodeFactory>();
38+
ApiClientBuilder.RegisterDefaultDeserializer<TextParseNodeFactory>();
39+
ApiClientBuilder.RegisterDefaultDeserializer<FormParseNodeFactory>();
40+
if (string.IsNullOrEmpty(RequestAdapter.BaseUrl))
41+
{
42+
RequestAdapter.BaseUrl = "http://localhost";
43+
}
44+
PathParameters.TryAdd("baseurl", RequestAdapter.BaseUrl);
45+
RequestAdapter.EnableBackingStore(backingStore);
46+
}
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// <auto-generated/>
2+
using Microsoft.Kiota.Abstractions.Serialization;
3+
using Microsoft.Kiota.Abstractions.Store;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
using System;
8+
namespace OpenApiKiotaEndToEndTests.ModelStateValidation.GeneratedCode.Models {
9+
#pragma warning disable CS1591
10+
public class DataInResponse : IBackedModel, IParsable
11+
#pragma warning restore CS1591
12+
{
13+
/// <summary>Stores model information.</summary>
14+
public IBackingStore BackingStore { get; private set; }
15+
/// <summary>The id property</summary>
16+
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
17+
#nullable enable
18+
public string? Id {
19+
get { return BackingStore?.Get<string?>("id"); }
20+
set { BackingStore?.Set("id", value); }
21+
}
22+
#nullable restore
23+
#else
24+
public string Id {
25+
get { return BackingStore?.Get<string>("id"); }
26+
set { BackingStore?.Set("id", value); }
27+
}
28+
#endif
29+
/// <summary>The type property</summary>
30+
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
31+
#nullable enable
32+
public string? Type {
33+
get { return BackingStore?.Get<string?>("type"); }
34+
set { BackingStore?.Set("type", value); }
35+
}
36+
#nullable restore
37+
#else
38+
public string Type {
39+
get { return BackingStore?.Get<string>("type"); }
40+
set { BackingStore?.Set("type", value); }
41+
}
42+
#endif
43+
/// <summary>
44+
/// Instantiates a new <see cref="DataInResponse"/> and sets the default values.
45+
/// </summary>
46+
public DataInResponse()
47+
{
48+
BackingStore = BackingStoreFactorySingleton.Instance.CreateBackingStore();
49+
}
50+
/// <summary>
51+
/// Creates a new instance of the appropriate class based on discriminator value
52+
/// </summary>
53+
/// <returns>A <see cref="DataInResponse"/></returns>
54+
/// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
55+
public static DataInResponse CreateFromDiscriminatorValue(IParseNode parseNode)
56+
{
57+
_ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
58+
var mappingValue = parseNode.GetChildNode("type")?.GetStringValue();
59+
return mappingValue switch
60+
{
61+
"socialMediaAccounts" => new SocialMediaAccountDataInResponse(),
62+
_ => new DataInResponse(),
63+
};
64+
}
65+
/// <summary>
66+
/// The deserialization information for the current model
67+
/// </summary>
68+
/// <returns>A IDictionary&lt;string, Action&lt;IParseNode&gt;&gt;</returns>
69+
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
70+
{
71+
return new Dictionary<string, Action<IParseNode>>
72+
{
73+
{"id", n => { Id = n.GetStringValue(); } },
74+
{"type", n => { Type = n.GetStringValue(); } },
75+
};
76+
}
77+
/// <summary>
78+
/// Serializes information the current object
79+
/// </summary>
80+
/// <param name="writer">Serialization writer to use to serialize this model</param>
81+
public virtual void Serialize(ISerializationWriter writer)
82+
{
83+
_ = writer ?? throw new ArgumentNullException(nameof(writer));
84+
writer.WriteStringValue("id", Id);
85+
writer.WriteStringValue("type", Type);
86+
}
87+
}
88+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// <auto-generated/>
2+
using Microsoft.Kiota.Abstractions.Serialization;
3+
using Microsoft.Kiota.Abstractions.Store;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
using System;
8+
namespace OpenApiKiotaEndToEndTests.ModelStateValidation.GeneratedCode.Models {
9+
#pragma warning disable CS1591
10+
public class ErrorLinks : IBackedModel, IParsable
11+
#pragma warning restore CS1591
12+
{
13+
/// <summary>The about property</summary>
14+
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
15+
#nullable enable
16+
public string? About {
17+
get { return BackingStore?.Get<string?>("about"); }
18+
set { BackingStore?.Set("about", value); }
19+
}
20+
#nullable restore
21+
#else
22+
public string About {
23+
get { return BackingStore?.Get<string>("about"); }
24+
set { BackingStore?.Set("about", value); }
25+
}
26+
#endif
27+
/// <summary>Stores model information.</summary>
28+
public IBackingStore BackingStore { get; private set; }
29+
/// <summary>The type property</summary>
30+
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
31+
#nullable enable
32+
public string? Type {
33+
get { return BackingStore?.Get<string?>("type"); }
34+
set { BackingStore?.Set("type", value); }
35+
}
36+
#nullable restore
37+
#else
38+
public string Type {
39+
get { return BackingStore?.Get<string>("type"); }
40+
set { BackingStore?.Set("type", value); }
41+
}
42+
#endif
43+
/// <summary>
44+
/// Instantiates a new <see cref="ErrorLinks"/> and sets the default values.
45+
/// </summary>
46+
public ErrorLinks()
47+
{
48+
BackingStore = BackingStoreFactorySingleton.Instance.CreateBackingStore();
49+
}
50+
/// <summary>
51+
/// Creates a new instance of the appropriate class based on discriminator value
52+
/// </summary>
53+
/// <returns>A <see cref="ErrorLinks"/></returns>
54+
/// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
55+
public static ErrorLinks CreateFromDiscriminatorValue(IParseNode parseNode)
56+
{
57+
_ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
58+
return new ErrorLinks();
59+
}
60+
/// <summary>
61+
/// The deserialization information for the current model
62+
/// </summary>
63+
/// <returns>A IDictionary&lt;string, Action&lt;IParseNode&gt;&gt;</returns>
64+
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
65+
{
66+
return new Dictionary<string, Action<IParseNode>>
67+
{
68+
{"about", n => { About = n.GetStringValue(); } },
69+
{"type", n => { Type = n.GetStringValue(); } },
70+
};
71+
}
72+
/// <summary>
73+
/// Serializes information the current object
74+
/// </summary>
75+
/// <param name="writer">Serialization writer to use to serialize this model</param>
76+
public virtual void Serialize(ISerializationWriter writer)
77+
{
78+
_ = writer ?? throw new ArgumentNullException(nameof(writer));
79+
writer.WriteStringValue("about", About);
80+
writer.WriteStringValue("type", Type);
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)