Skip to content

Commit

Permalink
Fix OpenApiPathsMapper (#1122)
Browse files Browse the repository at this point in the history
* Fix OpenApiPathsMapper

* utc

* s
  • Loading branch information
StefH authored Jul 22, 2024
1 parent 422e7c9 commit d79f6f1
Show file tree
Hide file tree
Showing 7 changed files with 38,777 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright © WireMock.Net

using System.Linq;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
Expand All @@ -16,7 +17,7 @@ public static bool TryGetXNullable(this OpenApiSchema schema, out bool value)
{
value = false;

if (schema.Extensions.TryGetValue("x-nullable", out IOpenApiExtension e) && e is OpenApiBoolean openApiBoolean)
if (schema.Extensions.TryGetValue("x-nullable", out var e) && e is OpenApiBoolean openApiBoolean)
{
value = openApiBoolean.Value;
return true;
Expand All @@ -27,32 +28,30 @@ public static bool TryGetXNullable(this OpenApiSchema schema, out bool value)

public static SchemaType GetSchemaType(this OpenApiSchema? schema)
{
switch (schema?.Type)
if (schema == null)
{
case "object":
return SchemaType.Object;

case "array":
return SchemaType.Array;

case "integer":
return SchemaType.Integer;

case "number":
return SchemaType.Number;

case "boolean":
return SchemaType.Boolean;

case "string":
return SchemaType.String;

case "file":
return SchemaType.File;
return SchemaType.Unknown;
}

default:
return SchemaType.Unknown;
if (schema.Type == null)
{
if (schema.AllOf.Any() || schema.AnyOf.Any())
{
return SchemaType.Object;
}
}

return schema.Type switch
{
"object" => SchemaType.Object,
"array" => SchemaType.Array,
"integer" => SchemaType.Integer,
"number" => SchemaType.Number,
"boolean" => SchemaType.Boolean,
"string" => SchemaType.String,
"file" => SchemaType.File,
_ => SchemaType.Unknown
};
}

public static SchemaFormat GetSchemaFormat(this OpenApiSchema? schema)
Expand Down
10 changes: 4 additions & 6 deletions src/WireMock.Net.OpenApiParser/Mappers/OpenApiPathsMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ private static bool TryGetContent(IDictionary<string, OpenApiMediaType>? content
}
else
{
jArray.Add(MapSchemaToObject(schema.Items, name));
var arrayItem = MapSchemaToObject(schema.Items, name: null); // Set name to null to force JObject instead of JProperty
jArray.Add(arrayItem);
}
}

Expand All @@ -219,12 +220,9 @@ private static bool TryGetContent(IDictionary<string, OpenApiMediaType>? content

if (schema.AllOf.Count > 0)
{
foreach (var property in schema.AllOf)
foreach (var group in schema.AllOf.SelectMany(p => p.Properties).GroupBy(x => x.Key))
{
foreach (var item in property.Properties)
{
propertyAsJObject.Add(MapPropertyAsJObject(item.Value, item.Key));
}
propertyAsJObject.Add(MapPropertyAsJObject(group.First().Value, group.Key));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,35 @@ public class WireMockOpenApiParserSettings
public IWireMockOpenApiParserExampleValues? ExampleValues { get; set; }

/// <summary>
/// Is a Header match case insensitive? (default is true).
/// Is a Header match case-insensitive?
///
/// Default is <c>true</c>.
/// </summary>
public bool HeaderPatternIgnoreCase { get; set; } = true;

/// <summary>
/// Is a Query Parameter match case insensitive? (default is true).
/// Is a Query Parameter match case-insensitive?
///
/// Default is <c>true</c>.
/// </summary>
public bool QueryParameterPatternIgnoreCase { get; set; } = true;

/// <summary>
/// Is a Request Body match case insensitive? (default is true).
/// Is a Request Body match case-insensitive?
///
/// Default is <c>true</c>.
/// </summary>
public bool RequestBodyIgnoreCase { get; set; } = true;

/// <summary>
/// Is a ExampleValue match case insensitive? (default is true).
/// Is a ExampleValue match case-insensitive?
///
/// Default is <c>true</c>.
/// </summary>
public bool IgnoreCaseExampleValues { get; set; } = true;

/// <summary>
/// Are examples generated dynamically? (default is false).
/// Are examples generated dynamically?
/// </summary>
public bool DynamicExamples { get; set; } = false;
public bool DynamicExamples { get; set; }
}
Loading

0 comments on commit d79f6f1

Please sign in to comment.