mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-14 06:17:11 +01:00
Mapping headers in OpenAPI (#644)
* Support edge case: first object, next an array. * Add mapping to header parameters. * Refactor the method MapHeadersParameters to MapHeaders
This commit is contained in:
@@ -45,6 +45,8 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
{
|
||||
var queryParameters = operation.Parameters.Where(p => p.In == ParameterLocation.Query);
|
||||
var pathParameters = operation.Parameters.Where(p => p.In == ParameterLocation.Path);
|
||||
var headers = operation.Parameters.Where(p => p.In == ParameterLocation.Header);
|
||||
|
||||
var response = operation.Responses.FirstOrDefault();
|
||||
|
||||
TryGetContent(response.Value?.Content, out OpenApiMediaType responseContent, out string responseContentType);
|
||||
@@ -65,7 +67,8 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
{
|
||||
Methods = new[] { httpMethod },
|
||||
Path = MapPathWithParameters(path, pathParameters),
|
||||
Params = MapQueryParameters(queryParameters)
|
||||
Params = MapQueryParameters(queryParameters),
|
||||
Headers = MapHeaders(headers)
|
||||
},
|
||||
Response = new ResponseModel
|
||||
{
|
||||
@@ -251,6 +254,26 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
return list.Any() ? list : null;
|
||||
}
|
||||
|
||||
private IList<HeaderModel> MapHeaders(IEnumerable<OpenApiParameter> headers)
|
||||
{
|
||||
var list = headers
|
||||
.Select(qp => new HeaderModel
|
||||
{
|
||||
Name = qp.Name,
|
||||
Matchers = new[]
|
||||
{
|
||||
new MatcherModel
|
||||
{
|
||||
Name = "ExactMatcher",
|
||||
Pattern = GetDefaultValueAsStringForSchemaType(qp.Schema)
|
||||
}
|
||||
}
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return list.Any() ? list : null;
|
||||
}
|
||||
|
||||
private string GetDefaultValueAsStringForSchemaType(OpenApiSchema schema)
|
||||
{
|
||||
var value = _exampleValueGenerator.GetExampleValue(schema);
|
||||
|
||||
Reference in New Issue
Block a user