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

Commit 8d02568

Browse files
Merge pull request #13 from neotoolkit/feat/extension
feat(extension): add hardcode extensions back
2 parents 70c9f96 + 852eae0 commit 8d02568

3 files changed

Lines changed: 10 additions & 32 deletions

File tree

extensions.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package openapi
2+
3+
type Extensions struct {
4+
Example string `json:"x-example,omitempty" yaml:"x-example,omitempty"`
5+
Faker string `json:"x-faker,omitempty" yaml:"x-faker,omitempty"`
6+
}

schema.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package openapi
22

33
import (
44
"fmt"
5-
6-
"github.com/goccy/go-yaml"
75
)
86

97
// Schema -.
108
type Schema struct {
11-
Extensions map[string]interface{} `json:"-" yaml:"-"`
9+
Extensions
1210

1311
Properties Schemas `json:"properties,omitempty" yaml:"properties,omitempty"`
1412
Type string `json:"type,omitempty" yaml:"type,omitempty"`
@@ -20,20 +18,9 @@ type Schema struct {
2018
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
2119
}
2220

23-
// GetExtensions -.
24-
func (s *Schema) GetExtensions() (map[string]interface{}, error) {
25-
bytes, err := yaml.Marshal(s.Extensions)
26-
if err != nil {
27-
return nil, err
28-
}
29-
30-
var extensions map[string]interface{}
31-
32-
if err := yaml.Unmarshal(bytes, &extensions); err != nil {
33-
return nil, err
34-
}
35-
36-
return extensions, nil
21+
// IsRef -.
22+
func (s Schema) IsRef() bool {
23+
return s.Ref != ""
3724
}
3825

3926
// Schemas -.

schema_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,3 @@ func TestSchema_ResponseByExample(t *testing.T) {
183183
})
184184
}
185185
}
186-
187-
func TestGetExtensions(t *testing.T) {
188-
s := openapi.Schema{
189-
Extensions: map[string]interface{}{
190-
"x-example": "x-example",
191-
},
192-
}
193-
194-
e, err := s.GetExtensions()
195-
if err != nil {
196-
t.Fatal(err)
197-
}
198-
199-
require.IsType(t, map[string]interface{}{}, e)
200-
}

0 commit comments

Comments
 (0)