diff --git a/internal/json_schema.go b/internal/json_schema.go index 9b3fdbb..4bcda10 100644 --- a/internal/json_schema.go +++ b/internal/json_schema.go @@ -142,8 +142,8 @@ func ReflectRequestBody( // ReflectJSONResponse reflects JSON schema of response. func ReflectJSONResponse( r *jsonschema.Reflector, - reflOption func(rc *jsonschema.ReflectContext), output interface{}, + reflOptions ...func(rc *jsonschema.ReflectContext), ) (schema *jsonschema.Schema, err error) { if output == nil { return nil, nil @@ -154,18 +154,12 @@ func ReflectJSONResponse( return nil, nil } - if reflOption == nil { - reflOption = func(rc *jsonschema.ReflectContext) {} - } - - sch, err := r.Reflect(output, - reflOption, - // openapi.WithOperationCtx(oc, true, openapi.InBody), + reflOptions = append(reflOptions, jsonschema.RootRef, - // jsonschema.DefinitionsPrefix(componentsSchemas), - // jsonschema.CollectDefinitions(r.collectDefinition()), sanitizeDefName, ) + + sch, err := r.Reflect(output, reflOptions...) if err != nil { return nil, err } diff --git a/openapi3/reflect.go b/openapi3/reflect.go index 702820e..a05a5d4 100644 --- a/openapi3/reflect.go +++ b/openapi3/reflect.go @@ -670,11 +670,13 @@ func (r *Reflector) ensureResponseContentType(resp *Response, contentType string } func (r *Reflector) parseJSONResponse(resp *Response, oc openapi.OperationContext, cu openapi.ContentUnit) error { - sch, err := internal.ReflectJSONResponse(r.JSONSchemaReflector(), func(rc *jsonschema.ReflectContext) { - openapi.WithOperationCtx(oc, true, openapi.InBody)(rc) - jsonschema.DefinitionsPrefix(componentsSchemas)(rc) - jsonschema.CollectDefinitions(r.collectDefinition())(rc) - }, cu.Structure) + sch, err := internal.ReflectJSONResponse( + r.JSONSchemaReflector(), + cu.Structure, + openapi.WithOperationCtx(oc, true, openapi.InBody), + jsonschema.DefinitionsPrefix(componentsSchemas), + jsonschema.CollectDefinitions(r.collectDefinition()), + ) if err != nil || sch == nil { return err diff --git a/openapi31/reflect.go b/openapi31/reflect.go index f986a1a..11a66b2 100644 --- a/openapi31/reflect.go +++ b/openapi31/reflect.go @@ -630,12 +630,10 @@ func (r *Reflector) ensureResponseContentType(resp *Response, contentType string func (r *Reflector) parseJSONResponse(resp *Response, oc openapi.OperationContext, cu openapi.ContentUnit) error { sch, err := internal.ReflectJSONResponse( r.JSONSchemaReflector(), - func(rc *jsonschema.ReflectContext) { - openapi.WithOperationCtx(oc, true, openapi.InBody)(rc) - jsonschema.DefinitionsPrefix(componentsSchemas)(rc) - jsonschema.CollectDefinitions(r.collectDefinition())(rc) - }, cu.Structure, + openapi.WithOperationCtx(oc, true, openapi.InBody), + jsonschema.DefinitionsPrefix(componentsSchemas), + jsonschema.CollectDefinitions(r.collectDefinition()), ) if err != nil || sch == nil {