mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
render examples as JSON added
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/pb33f/libopenapi/datamodel/high"
|
||||
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
@@ -56,6 +57,13 @@ func (e *Example) MarshalYAML() (interface{}, error) {
|
||||
return nb.Render(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON will marshal this into a JSON byte slice
|
||||
func (e *Example) MarshalJSON() ([]byte, error) {
|
||||
var g map[string]any
|
||||
e.Value.Decode(&g)
|
||||
return json.Marshal(g)
|
||||
}
|
||||
|
||||
// ExtractExamples will convert a low-level example map, into a high level one that is simple to navigate.
|
||||
// no fidelity is lost, everything is still available via GoLow()
|
||||
func ExtractExamples(elements *orderedmap.Map[lowmodel.KeyReference[string], lowmodel.ValueReference[*low.Example]]) *orderedmap.Map[string, *Example] {
|
||||
|
||||
Reference in New Issue
Block a user