diff --git a/schema.go b/schema.go index d794bb6..71ccf0e 100644 --- a/schema.go +++ b/schema.go @@ -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 -. @@ -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) } diff --git a/schema_test.go b/schema_test.go index 9c793c3..7a248ff 100644 --- a/schema_test.go +++ b/schema_test.go @@ -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{ @@ -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", @@ -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)