Fix DisableSchemaProperty

This commit is contained in:
Justin Hammond 2022-08-19 23:49:30 +08:00
parent f77335beb1
commit debf767a6c
3 changed files with 15 additions and 14 deletions

View file

@ -91,12 +91,13 @@ type hcontext struct {
func (c *hcontext) WithValue(key, value interface{}) Context {
r := c.r.WithContext(context.WithValue(c.r.Context(), key, value))
return &hcontext{
Context: context.WithValue(c.Context, key, value),
ResponseWriter: c.ResponseWriter,
r: r,
errors: append([]error{}, c.errors...),
op: c.op,
closed: c.closed,
Context: context.WithValue(c.Context, key, value),
ResponseWriter: c.ResponseWriter,
r: r,
errors: append([]error{}, c.errors...),
op: c.op,
closed: c.closed,
disableSchemaProperty: c.disableSchemaProperty,
}
}

View file

@ -54,8 +54,8 @@ type oaComponents struct {
}
// AddSchema creates and adds a new schema from a type.
func (c *oaComponents) AddSchema(t reflect.Type, mode schema.Mode, hint string) string {
return c.addSchema(t, mode, hint, true)
func (c *oaComponents) AddSchema(t reflect.Type, mode schema.Mode, hint string, generateSchemaField bool) string {
return c.addSchema(t, mode, hint, generateSchemaField)
}
func (c *oaComponents) addSchema(t reflect.Type, mode schema.Mode, hint string, generateSchemaField bool) string {
@ -103,9 +103,9 @@ func (c *oaComponents) addSchema(t reflect.Type, mode schema.Mode, hint string,
return c.addExistingSchema(s, name, generateSchemaField)
}
// AddExistingSchema adds an existing schema instance under the given name.
func (c *oaComponents) AddExistingSchema(s *schema.Schema, name string) string {
return c.addExistingSchema(s, name, true)
//AddExistingSchema adds an existing schema instance under the given name.
func (c *oaComponents) AddExistingSchema(s *schema.Schema, name string, generateSchemaField bool) string {
return c.addExistingSchema(s, name, generateSchemaField)
}
func (c *oaComponents) addExistingSchema(s *schema.Schema, name string, generateSchemaField bool) string {

View file

@ -99,11 +99,11 @@ func (o *Operation) toOpenAPI(components *oaComponents) *gabs.Container {
}
ref := ""
if o.requestSchemaOverride {
ref = components.AddExistingSchema(o.requestSchema, o.id+"-request")
ref = components.AddExistingSchema(o.requestSchema, o.id+"-request", !o.resource.router.disableSchemaProperty)
} else {
// Regenerate with ModeAll so the same model can be used for both the
// input and output when possible.
ref = components.AddSchema(o.requestModel, schema.ModeAll, o.id+"-request")
ref = components.AddSchema(o.requestModel, schema.ModeAll, o.id+"-request", !o.resource.router.disableSchemaProperty)
}
doc.Set(ref, "requestBody", "content", ct, "schema", "$ref")
}
@ -136,7 +136,7 @@ func (o *Operation) toOpenAPI(components *oaComponents) *gabs.Container {
}
if resp.model != nil {
ref := components.AddSchema(resp.model, schema.ModeAll, o.id+"-response")
ref := components.AddSchema(resp.model, schema.ModeAll, o.id+"-response", !o.resource.router.disableSchemaProperty)
o.responses[i].modelRef = ref
doc.Set(ref, "responses", status, "content", resp.contentType, "schema", "$ref")
}