-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce abstraction to describe operation and reflector (#65)
- Loading branch information
Showing
20 changed files
with
2,352 additions
and
453 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Package internal keeps reusable internal code. | ||
package internal | ||
|
||
import "github.com/swaggest/openapi-go" | ||
|
||
// NewOperationContext creates OperationContext. | ||
func NewOperationContext(method, pathPattern string) *OperationContext { | ||
return &OperationContext{ | ||
method: method, | ||
pathPattern: pathPattern, | ||
} | ||
} | ||
|
||
// OperationContext implements openapi.OperationContext. | ||
type OperationContext struct { | ||
method string | ||
pathPattern string | ||
req []openapi.ContentUnit | ||
resp []openapi.ContentUnit | ||
|
||
isProcessingResponse bool | ||
processingIn openapi.In | ||
} | ||
|
||
// Method returns HTTP method of an operation. | ||
func (o *OperationContext) Method() string { | ||
return o.method | ||
} | ||
|
||
// PathPattern returns operation HTTP URL path pattern. | ||
func (o *OperationContext) PathPattern() string { | ||
return o.pathPattern | ||
} | ||
|
||
// Request returns list of operation request content schemas. | ||
func (o *OperationContext) Request() []openapi.ContentUnit { | ||
return o.req | ||
} | ||
|
||
// Response returns list of operation response content schemas. | ||
func (o *OperationContext) Response() []openapi.ContentUnit { | ||
return o.resp | ||
} | ||
|
||
// SetIsProcessingResponse sets current processing state. | ||
func (o *OperationContext) SetIsProcessingResponse(is bool) { | ||
o.isProcessingResponse = is | ||
} | ||
|
||
// IsProcessingResponse indicates if response is being processed. | ||
func (o *OperationContext) IsProcessingResponse() bool { | ||
return o.isProcessingResponse | ||
} | ||
|
||
// SetProcessingIn sets current content location being processed. | ||
func (o *OperationContext) SetProcessingIn(in openapi.In) { | ||
o.processingIn = in | ||
} | ||
|
||
// ProcessingIn return which content location is being processed now. | ||
func (o *OperationContext) ProcessingIn() openapi.In { | ||
return o.processingIn | ||
} | ||
|
||
// SetMethod sets HTTP method of an operation. | ||
func (o *OperationContext) SetMethod(method string) { | ||
o.method = method | ||
} | ||
|
||
// SetPathPattern sets URL path pattern of an operation. | ||
func (o *OperationContext) SetPathPattern(pattern string) { | ||
o.pathPattern = pattern | ||
} | ||
|
||
// AddReqStructure adds request content schema. | ||
func (o *OperationContext) AddReqStructure(s interface{}, options ...openapi.ContentOption) { | ||
c := openapi.ContentUnit{} | ||
c.Structure = s | ||
|
||
for _, o := range options { | ||
o(&c) | ||
} | ||
|
||
o.req = append(o.req, c) | ||
} | ||
|
||
// AddRespStructure adds response content schema. | ||
func (o *OperationContext) AddRespStructure(s interface{}, options ...openapi.ContentOption) { | ||
c := openapi.ContentUnit{} | ||
c.Structure = s | ||
|
||
for _, o := range options { | ||
o(&c) | ||
} | ||
|
||
o.resp = append(o.resp, c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package openapi | ||
|
||
// RequestBodyEnforcer enables request body for GET and HEAD methods. | ||
// | ||
// Should be implemented on input structure, function body can be empty. | ||
// Forcing request body is not recommended and should only be used for backwards compatibility. | ||
type RequestBodyEnforcer interface { | ||
ForceRequestBody() | ||
} | ||
|
||
// RequestJSONBodyEnforcer enables JSON request body for structures with `formData` tags. | ||
// | ||
// Should be implemented on input structure, function body can be empty. | ||
type RequestJSONBodyEnforcer interface { | ||
ForceJSONRequestBody() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module swgui | ||
|
||
go 1.19 | ||
|
||
require github.com/swaggest/swgui v1.6.4 | ||
|
||
require ( | ||
github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0 // indirect | ||
golang.org/x/net v0.8.0 // indirect | ||
golang.org/x/text v0.8.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
github.com/bool64/dev v0.2.29 h1:x+syGyh+0eWtOzQ1ItvLzOGIWyNWnyjXpHIcpF2HvL4= | ||
github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0 h1:mj/nMDAwTBiaCqMEs4cYCqF7pO6Np7vhy1D1wcQGz+E= | ||
github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0/go.mod h1:919LwcH0M7/W4fcZ0/jy0qGght1GIhqyS/EgWGH2j5Q= | ||
github.com/swaggest/swgui v1.6.4 h1:9G7HTUMOAu/Y9YF2wDvoq9GXFlV4BH5y8BSOl4MWfl8= | ||
github.com/swaggest/swgui v1.6.4/go.mod h1:xsfGb4NtnBspBXKXtlPdVrvoqzCIZ338Aj3tHNikz2Q= | ||
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= | ||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= | ||
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= | ||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= | ||
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.