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 #1 from go-dummy/refactor/schema
Browse files Browse the repository at this point in the history
refactor(schema): Sort custom field and rename Ref field
  • Loading branch information
sashamelentyev authored Jan 23, 2022
2 parents c0cde4f + ffce6f8 commit c3dd82f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ type Schema struct {
Format string `json:"format,omitempty" yaml:"format,omitempty"`
Default interface{} `json:"default,omitempty" yaml:"default,omitempty"`
Example interface{} `json:"example,omitempty" yaml:"example,omitempty"`
Faker string `json:"x-faker,omitempty" yaml:"x-faker,omitempty"`
Required []string `json:"required,omitempty" yaml:"required,omitempty"`
Items *Schema `json:"items,omitempty" yaml:"items,omitempty"`
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`

Items *Schema `json:"items,omitempty" yaml:"items,omitempty"`

Reference string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
// Dummy custom field
Faker string `json:"x-faker,omitempty" yaml:"x-faker,omitempty"`
}

// Schemas -.
Expand All @@ -27,8 +27,8 @@ type SchemaContext interface {

// ResponseByExample -.
func (s Schema) ResponseByExample(schemaContext SchemaContext) (interface{}, error) {
if s.Reference != "" {
schema, err := schemaContext.LookupByReference(s.Reference)
if s.Ref != "" {
schema, err := schemaContext.LookupByReference(s.Ref)
if err != nil {
return nil, fmt.Errorf("lookup: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestSchema_ResponseByExample(t *testing.T) {
fields: fields{
Type: "array",
Items: &openapi.Schema{
Reference: "#/components/schemas/User",
Ref: "#/components/schemas/User",
},
},
args: args{
Expand All @@ -140,7 +140,7 @@ func TestSchema_ResponseByExample(t *testing.T) {
fields: fields{
Properties: openapi.Schemas{
"id": &openapi.Schema{
Reference: "#/components/schemas/UUID",
Ref: "#/components/schemas/UUID",
},
"firstName": &openapi.Schema{
Type: "string",
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestSchema_ResponseByExample(t *testing.T) {
Example: tc.fields.Example,
Faker: tc.fields.Faker,
Items: tc.fields.Items,
Reference: tc.fields.Reference,
Ref: tc.fields.Reference,
}
gotRes, err := s.ResponseByExample(tc.args.schemaContext)

Expand Down

0 comments on commit c3dd82f

Please sign in to comment.