-
-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: issue unmarshalling when discriminator field is set in openapi2.0
- Loading branch information
1 parent
c606b55
commit e17e91d
Showing
3 changed files
with
139 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package openapi2 | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIssue1010(t *testing.T) { | ||
v2 := []byte(` | ||
{ | ||
"basePath": "/v2", | ||
"host": "test.example.com", | ||
"info": { | ||
"title": "MyAPI", | ||
"version": "0.1", | ||
"x-info": "info extension" | ||
}, | ||
"paths": { | ||
"/foo": { | ||
"get": { | ||
"operationId": "getFoo", | ||
"responses": { | ||
"200": { | ||
"description": "returns all information", | ||
"schema": { | ||
"$ref": "#/definitions/Pet" | ||
} | ||
}, | ||
"default": { | ||
"description": "OK" | ||
} | ||
}, | ||
"summary": "get foo" | ||
} | ||
} | ||
}, | ||
"schemes": [ | ||
"http" | ||
], | ||
"swagger": "2.0", | ||
"definitions": { | ||
"Pet": { | ||
"type": "object", | ||
"required": ["petType"], | ||
"properties": { | ||
"petType": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"age": { | ||
"type": "integer" | ||
} | ||
}, | ||
"discriminator": "petType" | ||
}, | ||
"Dog": { | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/Pet" | ||
}, | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"breed": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"Cat": { | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/Pet" | ||
}, | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"color": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
`) | ||
|
||
var doc2 T | ||
err := json.Unmarshal(v2, &doc2) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters