diff --git a/context.go b/context.go index 6280662..d6917e9 100644 --- a/context.go +++ b/context.go @@ -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, } } diff --git a/openapi.go b/openapi.go index a0c1662..37be553 100644 --- a/openapi.go +++ b/openapi.go @@ -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 { diff --git a/operation.go b/operation.go index eda6601..9ee5879 100644 --- a/operation.go +++ b/operation.go @@ -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") }