Skip to content

Commit

Permalink
Renaming JSONSchemaPost to JSONSchemaExtend
Browse files Browse the repository at this point in the history
  • Loading branch information
webdestroya committed Nov 8, 2022
1 parent bd9a931 commit b32bc83
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ type customSchemaImpl interface {

// Function to be run after the schema has been generated.
// this will let you modify a schema afterwards
type postSchemaImpl interface {
JSONSchemaPost(*Schema)
type extendSchemaImpl interface {
JSONSchemaExtend(*Schema)
}

var customType = reflect.TypeOf((*customSchemaImpl)(nil)).Elem()
var postType = reflect.TypeOf((*postSchemaImpl)(nil)).Elem()
var extendType = reflect.TypeOf((*extendSchemaImpl)(nil)).Elem()

// customSchemaGetFieldDocString
type customSchemaGetFieldDocString interface {
Expand Down Expand Up @@ -402,7 +402,7 @@ func (r *Reflector) reflectTypeToSchema(definitions Definitions, t reflect.Type)
panic("unsupported type " + t.String())
}

r.reflectSchemaPost(definitions, t, st)
r.reflectSchemaExtend(definitions, t, st)

// Always try to reference the definition which may have just been created
if def := r.refDefinition(definitions, t); def != nil {
Expand Down Expand Up @@ -431,11 +431,11 @@ func (r *Reflector) reflectCustomSchema(definitions Definitions, t reflect.Type)
return nil
}

func (r *Reflector) reflectSchemaPost(definitions Definitions, t reflect.Type, s *Schema) *Schema {
if t.Implements(postType) {
func (r *Reflector) reflectSchemaExtend(definitions Definitions, t reflect.Type, s *Schema) *Schema {
if t.Implements(extendType) {
v := reflect.New(t)
o := v.Interface().(postSchemaImpl)
o.JSONSchemaPost(s)
o := v.Interface().(extendSchemaImpl)
o.JSONSchemaExtend(s)
if ref := r.refDefinition(definitions, t); ref != nil {
return ref
}
Expand Down
2 changes: 1 addition & 1 deletion reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ type SchemaPostTest struct {
SchemaPostTestBase `json:",inline"`
}

func (SchemaPostTest) JSONSchemaPost(base *Schema) {
func (SchemaPostTest) JSONSchemaExtend(base *Schema) {
base.Properties.Delete("FirstName")
base.Properties.Delete("age")
val, _ := base.Properties.Get("LastName")
Expand Down

0 comments on commit b32bc83

Please sign in to comment.