Fixed JSON rendering for example object

This commit is contained in:
quobix
2024-07-05 13:34:58 -04:00
parent c2b58717b8
commit bdee05a412
2 changed files with 19 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ package base
import (
"context"
"encoding/json"
"fmt"
"strings"
"testing"
@@ -53,6 +54,21 @@ x-hack: code`
// render the example as YAML
rendered, _ := highExample.Render()
assert.Equal(t, yml, strings.TrimSpace(string(rendered)))
// render the example as JSON
var err error
rendered, err = json.Marshal(highExample)
assert.NoError(t, err)
var j map[string]any
_ = json.Unmarshal(rendered, &j)
assert.Equal(t, "an example", j["summary"])
assert.Equal(t, "something more", j["description"])
assert.Equal(t, "https://pb33f.io", j["externalValue"])
assert.Equal(t, "code", j["x-hack"])
assert.Equal(t, "a thing", j["value"])
}
func TestExtractExamples(t *testing.T) {