render examples as JSON added

This commit is contained in:
quobix
2024-07-02 11:13:32 -04:00
parent 8506d1dc86
commit 246ad9faee

View File

@@ -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] {