This repository has been archived by the owner on Sep 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from neotoolkit/feat/extension
feat(extension): add extension
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
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,22 @@ | ||
package openapi_test | ||
|
||
import ( | ||
"github.com/neotoolkit/openapi" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestGetExtensions(t *testing.T) { | ||
s := openapi.Extensions{} | ||
|
||
s.Extensions = map[string]interface{}{ | ||
"test": "test", | ||
} | ||
|
||
e, err := s.GetExtensions() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
require.Equal(t, "test", e["test"]) | ||
} |
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,24 @@ | ||
package openapi | ||
|
||
import "github.com/goccy/go-yaml" | ||
|
||
// Extensions -. | ||
type Extensions struct { | ||
Extensions map[string]interface{} `json:"-" yaml:"-"` | ||
} | ||
|
||
// GetExtensions -. | ||
func (e Extensions) GetExtensions() (map[string]interface{}, error) { | ||
bytes, err := yaml.Marshal(e.Extensions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var extensions map[string]interface{} | ||
|
||
if err := yaml.Unmarshal(bytes, &extensions); err != nil { | ||
return nil, err | ||
} | ||
|
||
return extensions, nil | ||
} |
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