-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from go-andiamo/path-auto-options
Add `Path.AutoOptionsMethod`
- Loading branch information
Showing
5 changed files
with
235 additions
and
25 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
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,35 @@ | ||
package chioas | ||
|
||
// OptionsMethodPayloadBuilder is an interface that can be provided to Definition.OptionsMethodPayloadBuilder and | ||
// allows automatically created OPTIONS methods to return a body payload | ||
type OptionsMethodPayloadBuilder interface { | ||
BuildPayload(path string, pathDef *Path, def *Definition) (data []byte, headers map[string]string) | ||
} | ||
|
||
// NewRootOptionsMethodPayloadBuilder provides an OptionsMethodPayloadBuilder that can be used for Definition.OptionsMethodPayloadBuilder | ||
// and provides the OPTIONS payload body on API root as the OAS spec | ||
func NewRootOptionsMethodPayloadBuilder() OptionsMethodPayloadBuilder { | ||
return &rootOptionsPayload{} | ||
} | ||
|
||
type rootOptionsPayload struct{} | ||
|
||
func (r *rootOptionsPayload) BuildPayload(path string, pathDef *Path, def *Definition) (data []byte, headers map[string]string) { | ||
data = make([]byte, 0) | ||
headers = map[string]string{} | ||
if path == root { | ||
if def.DocOptions.AsJson { | ||
headers[hdrContentType] = contentTypeJson | ||
} else { | ||
headers[hdrContentType] = contentTypeYaml | ||
} | ||
if def.DocOptions.specData != nil { | ||
data = def.DocOptions.specData | ||
} else if def.DocOptions.AsJson { | ||
data, _ = def.AsJson() | ||
} else { | ||
data, _ = def.AsYaml() | ||
} | ||
} | ||
return | ||
} |
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