Files
libopenapi/datamodel/high/base/example.go
Dave Shanley 02633ad333 Adding high base model tests
these were covered when used by v3 models, but need new tests when moved into a seperate package.
2022-09-11 13:10:32 -04:00

43 lines
1.1 KiB
Go

// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package base
import (
"github.com/pb33f/libopenapi/datamodel/high"
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
low "github.com/pb33f/libopenapi/datamodel/low/base"
)
type Example struct {
Summary string
Description string
Value any
ExternalValue string
Extensions map[string]any
low *low.Example
}
func NewExample(example *low.Example) *Example {
e := new(Example)
e.low = example
e.Summary = example.Summary.Value
e.Description = example.Description.Value
e.Value = example.Value.Value
e.ExternalValue = example.ExternalValue.Value
e.Extensions = high.ExtractExtensions(example.Extensions)
return e
}
func (e *Example) GoLow() *low.Example {
return e.low
}
func ExtractExamples(elements map[lowmodel.KeyReference[string]]lowmodel.ValueReference[*low.Example]) map[string]*Example {
extracted := make(map[string]*Example)
for k, v := range elements {
extracted[k.Value] = NewExample(v.Value)
}
return extracted
}