Files
libopenapi/datamodel/high/v2/examples.go
Dave Shanley c3cf5f1e38 Added support for unevaluatedProperties as Schema and bool #118
Also ran `gofmt` across the entire project. Things need cleaning up.

Signed-off-by: Dave Shanley <dave@quobix.com>
2023-06-17 14:12:27 -04:00

34 lines
928 B
Go

// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v2
import low "github.com/pb33f/libopenapi/datamodel/low/v2"
// Example represents a high-level Swagger / OpenAPI 2 Example object, backed by a low level one.
// Allows sharing examples for operation responses
// - https://swagger.io/specification/v2/#exampleObject
type Example struct {
Values map[string]any
low *low.Examples
}
// NewExample creates a new high-level Example instance from a low-level one.
func NewExample(examples *low.Examples) *Example {
e := new(Example)
e.low = examples
if len(examples.Values) > 0 {
values := make(map[string]any)
for k := range examples.Values {
values[k.Value] = examples.Values[k].Value
}
e.Values = values
}
return e
}
// GoLow returns the low-level Example used to create the high-level one.
func (e *Example) GoLow() *low.Examples {
return e.low
}