Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #8 from neotoolkit/feat/extension
Browse files Browse the repository at this point in the history
feat(extension): add extension
  • Loading branch information
sashamelentyev authored Feb 9, 2022
2 parents 8baf8cf + 9f91f22 commit d41d978
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
22 changes: 22 additions & 0 deletions extension_test.go
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"])
}
24 changes: 24 additions & 0 deletions extensions.go
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
}
2 changes: 1 addition & 1 deletion schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "fmt"

// Schema -.
type Schema struct {
Extensions map[string]interface{} `json:"-" yaml:"-"`
Extensions

Properties Schemas `json:"properties,omitempty" yaml:"properties,omitempty"`
Type string `json:"type,omitempty" yaml:"type,omitempty"`
Expand Down

0 comments on commit d41d978

Please sign in to comment.