-
-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openapi2: fix un/marshalling discriminator field (#1011)
* fix: issue unmarshalling when discriminator field is set in openapi2.0 * revert original approach * update with different approach * Revert "update with different approach" This reverts commit 2db2b39. * v2 schema with discriminator field set as string * update ref link and comment * run docs.sh
- Loading branch information
1 parent
c606b55
commit 1eeb41c
Showing
11 changed files
with
838 additions
and
136 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package openapi2 | ||
|
||
import ( | ||
"net/url" | ||
) | ||
|
||
// copyURI makes a copy of the pointer. | ||
func copyURI(u *url.URL) *url.URL { | ||
if u == nil { | ||
return nil | ||
} | ||
|
||
c := *u // shallow-copy | ||
return &c | ||
} |
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,98 @@ | ||
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) | ||
require.Equal(t, "petType", doc2.Definitions["Pet"].Value.Discriminator) | ||
} |
Oops, something went wrong.