Skip to content

Commit

Permalink
Merge pull request #3593 from microsoft/bugfix/form-data-warning
Browse files Browse the repository at this point in the history
- fixes an issue where the validation rule would warn for arrays in forms
  • Loading branch information
baywet authored Oct 30, 2023
2 parents aff7f98 + e131ea3 commit cc1c376
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed parameters that are in camelcase to snakecase in Python. [#3525](https://github.com/microsoft/kiota/issues/3525
- Fixed missing imports for method parameters that are query parameters.
- Replaces the use of "new" by "override" and "virtual" in CSharp models.
- Fixed a bug in validation rules where form data would wrongfully warn for arrays. [#3569](https://github.com/microsoft/kiota/issues/3569)
- Fixed query parameters type mapping for arrays. [#3354](https://github.com/microsoft/kiota/issues/3354)
- The lock file now contains the relative path to the description in case of local path. [#3151](https://github.com/microsoft/kiota/issues/3151)
- Fixes a bug where query parameters would be missing in CSharp for ebc clients. [#3583](https://github.com/microsoft/kiota/issues/3583)
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Validation/UrlFormEncodedComplex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private static void ValidateSchema(OpenApiSchema schema, IValidationContext cont
if (schema == null) return;
if (!schema.IsObject())
context.CreateWarning(nameof(UrlFormEncodedComplex), $"The operation {operationId} has a {schemaName} which is not an object type. This is not supported by Kiota and serialization will fail.");
if (schema.Properties.Any(static x => x.Value.IsObject() || x.Value.IsArray()))
if (schema.Properties.Any(static x => x.Value.IsObject()))
context.CreateWarning(nameof(UrlFormEncodedComplex), $"The operation {operationId} has a {schemaName} with a complex properties and the url form encoded content type. This is not supported by Kiota and serialization of complex properties will fail.");
}
}
40 changes: 40 additions & 0 deletions tests/Kiota.Builder.Tests/Validation/UrlFormEncodedComplexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,46 @@ public void DoesntAddAWarningWhenUrlEncoded()
Assert.Empty(diag.Warnings);
}
[Fact]
public void DoesntAddAWarningOnArrayProperty()
{
var rule = new UrlFormEncodedComplex();
var documentTxt = @"openapi: 3.0.1
info:
title: OData Service for namespace microsoft.graph
description: This OData service is located at https://graph.microsoft.com/v1.0
version: 1.0.1
paths:
/enumeration:
post:
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
filters:
type: array
items:
type: integer
format: int32
responses:
'200':
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
prop:
type: string";
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(documentTxt));
var reader = new OpenApiStreamReader(new OpenApiReaderSettings
{
RuleSet = new(new ValidationRule[] { rule }),
});
var doc = reader.Read(stream, out var diag);
Assert.Empty(diag.Warnings);
}
[Fact]
public void DoesntAddAWarningWhenNotUrlEncoded()
{
var rule = new UrlFormEncodedComplex();
Expand Down

0 comments on commit cc1c376

Please sign in to comment.