mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 04:20:17 +00:00
Added support for original format rendering #105
Original input document types are now rendered automatically as JSON or YAML (vs always being YAML). This only operates at the `Document` level for rendering out entire documents. Requested in #105 Signed-off-by: Dave Shanley <dave@quobix.com>
This commit is contained in:
@@ -503,6 +503,19 @@ func ConvertYAMLtoJSON(yamlData []byte) ([]byte, error) {
|
||||
return jsonData, nil
|
||||
}
|
||||
|
||||
// ConvertYAMLtoJSONPretty will do exactly what you think it will. It will deserialize YAML into serialized JSON.
|
||||
// However, this version will a apply prefix/indentation to the JSON.
|
||||
func ConvertYAMLtoJSONPretty(yamlData []byte, prefix string, indent string) ([]byte, error) {
|
||||
var decodedYaml map[string]interface{}
|
||||
err := yaml.Unmarshal(yamlData, &decodedYaml)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// if the data can be decoded, it can be encoded (that's my view anyway). no need for an error check.
|
||||
jsonData, _ := json.MarshalIndent(decodedYaml, prefix, indent)
|
||||
return jsonData, nil
|
||||
}
|
||||
|
||||
// IsHttpVerb will check if an operation is valid or not.
|
||||
func IsHttpVerb(verb string) bool {
|
||||
verbs := []string{"get", "post", "put", "patch", "delete", "options", "trace", "head"}
|
||||
|
||||
Reference in New Issue
Block a user