diff --git a/openapi3/reflect.go b/openapi3/reflect.go index c584e7c..783c7c0 100644 --- a/openapi3/reflect.go +++ b/openapi3/reflect.go @@ -128,22 +128,54 @@ func (o operationContext) SetTags(tags ...string) { o.op.WithTags(tags...) } +func (o operationContext) Tags() []string { + return o.op.Tags +} + func (o operationContext) SetIsDeprecated(isDeprecated bool) { o.op.WithDeprecated(isDeprecated) } +func (o operationContext) IsDeprecated() bool { + return o.op.Deprecated != nil && *o.op.Deprecated +} + func (o operationContext) SetSummary(summary string) { o.op.WithSummary(summary) } +func (o operationContext) Summary() string { + if o.op.Summary == nil { + return "" + } + + return *o.op.Summary +} + func (o operationContext) SetDescription(description string) { o.op.WithDescription(description) } +func (o operationContext) Description() string { + if o.op.Description == nil { + return "" + } + + return *o.op.Description +} + func (o operationContext) SetID(operationID string) { o.op.WithID(operationID) } +func (o operationContext) ID() string { + if o.op.ID == nil { + return "" + } + + return *o.op.ID +} + func (o operationContext) UnknownParamsAreForbidden(in openapi.In) bool { return o.op.UnknownParamIsForbidden(ParameterIn(in)) } diff --git a/openapi31/reflect.go b/openapi31/reflect.go index 2f1c927..90fb130 100644 --- a/openapi31/reflect.go +++ b/openapi31/reflect.go @@ -136,22 +136,54 @@ func (o operationContext) SetTags(tags ...string) { o.op.WithTags(tags...) } +func (o operationContext) Tags() []string { + return o.op.Tags +} + func (o operationContext) SetIsDeprecated(isDeprecated bool) { o.op.WithDeprecated(isDeprecated) } +func (o operationContext) IsDeprecated() bool { + return o.op.Deprecated != nil && *o.op.Deprecated +} + func (o operationContext) SetSummary(summary string) { o.op.WithSummary(summary) } +func (o operationContext) Summary() string { + if o.op.Summary == nil { + return "" + } + + return *o.op.Summary +} + func (o operationContext) SetDescription(description string) { o.op.WithDescription(description) } +func (o operationContext) Description() string { + if o.op.Description == nil { + return "" + } + + return *o.op.Description +} + func (o operationContext) SetID(operationID string) { o.op.WithID(operationID) } +func (o operationContext) ID() string { + if o.op.ID == nil { + return "" + } + + return *o.op.ID +} + func (o operationContext) UnknownParamsAreForbidden(in openapi.In) bool { return o.op.UnknownParamIsForbidden(ParameterIn(in)) } diff --git a/operation.go b/operation.go index ee81c76..057e9ef 100644 --- a/operation.go +++ b/operation.go @@ -81,6 +81,7 @@ func (c ContentUnit) FieldMapping(in In) map[string]string { // OperationContext defines operation and processing state. type OperationContext interface { OperationInfo + OperationInfoReader OperationState Method() string @@ -106,6 +107,15 @@ type OperationInfo interface { AddSecurity(securityName string, scopes ...string) } +// OperationInfoReader exposes current state of operation context. +type OperationInfoReader interface { + Tags() []string + IsDeprecated() bool + Summary() string + Description() string + ID() string +} + // OperationState extends OperationContext with processing state information. type OperationState interface { IsProcessingResponse() bool