mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 12:37:49 +00:00
Swagger 2.0 high level model going in now
Shifting a few high level models around that are also shared. now it's just a churn game to flesh the high level model and test it up.
This commit is contained in:
42
datamodel/high/base/example.go
Normal file
42
datamodel/high/base/example.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// 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
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user