Files
libopenapi/datamodel/high/v3/security_scheme_test.go
quobix 8717b3cd33 An enormous amount of surgery on the low level model.
Every `Build()` method now requires a `context.Context`. This is so the rolodex knows where to resolve from when locating relative links. Without knowing where we are, there is no way to resolve anything. This new mechanism allows the model to recurse across as many files as required to locate references, without loosing track of where we are in the process.

Signed-off-by: quobix <dave@quobix.com>
2023-10-23 15:04:34 -04:00

49 lines
1.1 KiB
Go

// Copyright 2023 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v3
import (
"context"
"github.com/pb33f/libopenapi/datamodel/low"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/index"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"strings"
"testing"
)
func TestSecurityScheme_MarshalYAML(t *testing.T) {
ss := &SecurityScheme{
Type: "apiKey",
Description: "this is a description",
Name: "superSecret",
In: "header",
Scheme: "https",
}
dat, _ := ss.Render()
var idxNode yaml.Node
_ = yaml.Unmarshal(dat, &idxNode)
idx := index.NewSpecIndexWithConfig(&idxNode, index.CreateOpenAPIIndexConfig())
var n v3.SecurityScheme
_ = low.BuildModel(idxNode.Content[0], &n)
_ = n.Build(context.Background(), nil, idxNode.Content[0], idx)
r := NewSecurityScheme(&n)
dat, _ = r.Render()
desired := `type: apiKey
description: this is a description
name: superSecret
in: header
scheme: https`
assert.Equal(t, desired, strings.TrimSpace(string(dat)))
}