openapi: "3.0.1"
info:
version: 1.0.0
title: Swagger Petstore
paths:
/pet:
get:
description: |
Returns pet from the system that the user has access to
responses:
'200':
description: pet response
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Pets'
- $ref: '#/components/schemas/Pets2'
components:
schemas:
Pets:
type: array
items:
$ref: '#/components/schemas/Pet'
Pets2:
type: array
items:
$ref: '#/components/schemas/Pet2'
Pet:
type: object
required:
- name
properties:
name:
type: string
tag:
type: string
Pet2:
type: object
required:
- name
properties:
name:
type: string
tag:
type: integer
func TestCanParsePet(t *testing.T) {
test := `[{
"name": "foo",
"tag": "foo"
}]`
r := ioutil.NopCloser(bytes.NewReader([]byte(test)))
res := &http.Response{
StatusCode: 200,
Body: r,
Header: make(http.Header),
}
res.Header.Set("content-type", "application/json")
petResponse, err := ParseGetPetResponse(res)
require.NoError(t, err)
require.NotNil(t, petResponse.JSON200)
}
--- FAIL: TestCanParsePet (0.00s)
issue_test.go:26:
Error Trace: /home/test/test/issue_test.go:26
Error: Received unexpected error:
json: cannot unmarshal array into Go value of type struct { union json.RawMessage }
Test: TestCanParsePet
FAIL
exit status 1
FAIL example.com/test 0.002s
The following schema:
Then a simple test:
Results in :