Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Array in OpenApiParser #664

Merged
merged 1 commit into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
openapi: 3.0.1
info:
title: API_Test
version: v1
paths:
/WeatherForecast:
get:
tags:
- WeatherForecast
parameters:
- in: "header"
name: X-Correlation-ID
type: "string"
required: true
responses:
'200':
description: Success
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/WeatherForecast'
/leolplex:
get:
tags:
- WeatherForecast
parameters:
- in: "header"
name: X-Correlation-ID
type: "string"
required: true
responses:
'200':
description: Success
content:
application/json:
example:
- date: 2021-10-21T09:13:00.552+00:00
temperatureC: 111
temperatureF: 111
summary: Just-summary
- date: 2021-10-21T09:13:00.000+00:00
temperatureC: 222
temperatureF: 222
summary: Just-summary2
schema:
type: array
items:
$ref: '#/components/schemas/WeatherForecast'
/exampleop:
get:
responses:
"200":
description: OK
content:
application/json:
example:
id: 1
name: get food
completed: false
schema:
properties:
id:
type: integer
name:
type: string
completed:
type: boolean
completed_at:
type: string
format: date-time
nullable: true
required:
- id
- name
- completed
components:
schemas:
WeatherForecast:
type: object
properties:
date:
type: string
format: date-time
temperatureC:
type: integer
format: int32
temperatureF:
type: integer
format: int32
readOnly: true
summary:
type: string
nullable: true
additionalProperties: false
9 changes: 8 additions & 1 deletion src/WireMock.Net.OpenApiParser/Mappers/OpenApiPathsMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,14 @@ private JToken MapOpenApiAnyToJToken(IOpenApiAny any)
var writer = new OpenApiJsonWriter(outputString);
any.Write(writer, OpenApiSpecVersion.OpenApi3_0);

return JObject.Parse(outputString.ToString());
if (any.AnyType == AnyType.Array)
{
return JArray.Parse(outputString.ToString());
}
else
{
return JObject.Parse(outputString.ToString());
}
}

private IDictionary<string, object> MapHeaders(string responseContentType, IDictionary<string, OpenApiHeader> headers)
Expand Down