Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend operation info #97

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions openapi3/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,54 @@
o.op.WithTags(tags...)
}

func (o operationContext) Tags() []string {
return o.op.Tags

Check warning on line 132 in openapi3/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi3/reflect.go#L132

Added line #L132 was not covered by tests
}

Check notice on line 133 in openapi3/reflect.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

1 statement(s) are not covered by tests.

func (o operationContext) SetIsDeprecated(isDeprecated bool) {
o.op.WithDeprecated(isDeprecated)
}

func (o operationContext) IsDeprecated() bool {
return o.op.Deprecated != nil && *o.op.Deprecated

Check warning on line 140 in openapi3/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi3/reflect.go#L140

Added line #L140 was not covered by tests
}

Check notice on line 141 in openapi3/reflect.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

1 statement(s) are not covered by tests.

func (o operationContext) SetSummary(summary string) {
o.op.WithSummary(summary)
}

func (o operationContext) Summary() string {
if o.op.Summary == nil {
return ""

Check warning on line 149 in openapi3/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi3/reflect.go#L148-L149

Added lines #L148 - L149 were not covered by tests
}

Check notice on line 150 in openapi3/reflect.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

2 statement(s) are not covered by tests.

return *o.op.Summary

Check notice on line 152 in openapi3/reflect.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

1 statement(s) are not covered by tests.

Check warning on line 152 in openapi3/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi3/reflect.go#L152

Added line #L152 was not covered by tests
}

func (o operationContext) SetDescription(description string) {
o.op.WithDescription(description)
}

func (o operationContext) Description() string {
if o.op.Description == nil {
return ""

Check warning on line 161 in openapi3/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi3/reflect.go#L160-L161

Added lines #L160 - L161 were not covered by tests
}

Check notice on line 162 in openapi3/reflect.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

2 statement(s) are not covered by tests.

return *o.op.Description

Check notice on line 164 in openapi3/reflect.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

1 statement(s) are not covered by tests.

Check warning on line 164 in openapi3/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi3/reflect.go#L164

Added line #L164 was not covered by tests
}

func (o operationContext) SetID(operationID string) {
o.op.WithID(operationID)
}

func (o operationContext) ID() string {
if o.op.ID == nil {
return ""

Check warning on line 173 in openapi3/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi3/reflect.go#L172-L173

Added lines #L172 - L173 were not covered by tests
}

Check notice on line 174 in openapi3/reflect.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

2 statement(s) are not covered by tests.

return *o.op.ID

Check notice on line 176 in openapi3/reflect.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

1 statement(s) are not covered by tests.

Check warning on line 176 in openapi3/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi3/reflect.go#L176

Added line #L176 was not covered by tests
}

func (o operationContext) UnknownParamsAreForbidden(in openapi.In) bool {
return o.op.UnknownParamIsForbidden(ParameterIn(in))
}
Expand Down
32 changes: 32 additions & 0 deletions openapi31/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,54 @@
o.op.WithTags(tags...)
}

func (o operationContext) Tags() []string {
return o.op.Tags

Check warning on line 140 in openapi31/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi31/reflect.go#L140

Added line #L140 was not covered by tests
}

Check notice on line 141 in openapi31/reflect.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

1 statement(s) are not covered by tests.

func (o operationContext) SetIsDeprecated(isDeprecated bool) {
o.op.WithDeprecated(isDeprecated)
}

func (o operationContext) IsDeprecated() bool {
return o.op.Deprecated != nil && *o.op.Deprecated

Check warning on line 148 in openapi31/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi31/reflect.go#L148

Added line #L148 was not covered by tests
}

Check notice on line 149 in openapi31/reflect.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

1 statement(s) are not covered by tests.

func (o operationContext) SetSummary(summary string) {
o.op.WithSummary(summary)
}

func (o operationContext) Summary() string {
if o.op.Summary == nil {
return ""

Check warning on line 157 in openapi31/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi31/reflect.go#L156-L157

Added lines #L156 - L157 were not covered by tests
}

return *o.op.Summary

Check warning on line 160 in openapi31/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi31/reflect.go#L160

Added line #L160 was not covered by tests
}

func (o operationContext) SetDescription(description string) {
o.op.WithDescription(description)
}

func (o operationContext) Description() string {
if o.op.Description == nil {
return ""

Check warning on line 169 in openapi31/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi31/reflect.go#L168-L169

Added lines #L168 - L169 were not covered by tests
}

return *o.op.Description

Check warning on line 172 in openapi31/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi31/reflect.go#L172

Added line #L172 was not covered by tests
}

func (o operationContext) SetID(operationID string) {
o.op.WithID(operationID)
}

func (o operationContext) ID() string {
if o.op.ID == nil {
return ""

Check warning on line 181 in openapi31/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi31/reflect.go#L180-L181

Added lines #L180 - L181 were not covered by tests
}

return *o.op.ID

Check warning on line 184 in openapi31/reflect.go

View check run for this annotation

Codecov / codecov/patch

openapi31/reflect.go#L184

Added line #L184 was not covered by tests
}

func (o operationContext) UnknownParamsAreForbidden(in openapi.In) bool {
return o.op.UnknownParamIsForbidden(ParameterIn(in))
}
Expand Down
10 changes: 10 additions & 0 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading