Refactoring core structure of datamodel to accomodate v2 model.

There is a lot of overlap on these models, to create a much more sensible design, a new 'base' package has been added which contains shared models that both versions make use of.
This commit is contained in:
Dave Shanley
2022-09-01 08:53:16 -04:00
parent 990ba78ca8
commit 68743113ed
45 changed files with 246 additions and 125 deletions

View File

@@ -7,7 +7,7 @@ import (
"github.com/pb33f/libopenapi/datamodel/high"
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
low "github.com/pb33f/libopenapi/datamodel/low/3.0"
"github.com/pb33f/libopenapi/datamodel/low/shared"
"github.com/pb33f/libopenapi/datamodel/low/base"
)
const (
@@ -72,7 +72,7 @@ func NewComponents(comp *low.Components) *Components {
go buildComponent[*Parameter, *low.Parameter](parameters, k.Value, v.Value, paramChan, NewParameter)
}
for k, v := range comp.Examples.Value {
go buildComponent[*Example, *low.Example](parameters, k.Value, v.Value, exampleChan, NewExample)
go buildComponent[*Example, *base.Example](parameters, k.Value, v.Value, exampleChan, NewExample)
}
for k, v := range comp.RequestBodies.Value {
go buildComponent[*RequestBody, *low.RequestBody](requestBodies, k.Value, v.Value,
@@ -147,9 +147,9 @@ func buildComponent[N any, O any](comp int, key string, orig O, c chan component
c <- componentResult[N]{comp: comp, res: f(orig), key: key}
}
func buildSchema(key lowmodel.KeyReference[string], orig lowmodel.ValueReference[*shared.SchemaProxy], c chan componentResult[*SchemaProxy]) {
func buildSchema(key lowmodel.KeyReference[string], orig lowmodel.ValueReference[*base.SchemaProxy], c chan componentResult[*SchemaProxy]) {
var sch *SchemaProxy
sch = &SchemaProxy{schema: &lowmodel.NodeReference[*shared.SchemaProxy]{
sch = &SchemaProxy{schema: &lowmodel.NodeReference[*base.SchemaProxy]{
Value: orig.Value,
ValueNode: orig.ValueNode,
}}

View File

@@ -4,7 +4,7 @@
package v3
import (
low "github.com/pb33f/libopenapi/datamodel/low/shared"
low "github.com/pb33f/libopenapi/datamodel/low/base"
)
type Contact struct {

View File

@@ -3,7 +3,9 @@
package v3
import low "github.com/pb33f/libopenapi/datamodel/low/3.0"
import (
low "github.com/pb33f/libopenapi/datamodel/low/base"
)
type Discriminator struct {
PropertyName string

View File

@@ -6,7 +6,7 @@ package v3
import (
"github.com/pb33f/libopenapi/datamodel/high"
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
low "github.com/pb33f/libopenapi/datamodel/low/3.0"
low "github.com/pb33f/libopenapi/datamodel/low/base"
)
type Example struct {

View File

@@ -5,7 +5,7 @@ package v3
import (
"github.com/pb33f/libopenapi/datamodel/high"
low "github.com/pb33f/libopenapi/datamodel/low/3.0"
low "github.com/pb33f/libopenapi/datamodel/low/base"
)
type ExternalDoc struct {

View File

@@ -6,7 +6,7 @@ package v3
import (
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
low "github.com/pb33f/libopenapi/datamodel/low/3.0"
"github.com/pb33f/libopenapi/datamodel/low/shared"
"github.com/pb33f/libopenapi/datamodel/low/base"
)
type Header struct {
@@ -36,7 +36,7 @@ func NewHeader(header *low.Header) *Header {
h.Explode = header.Explode.Value
h.AllowReserved = header.AllowReserved.Value
if !header.Schema.IsEmpty() {
h.Schema = &SchemaProxy{schema: &lowmodel.NodeReference[*shared.SchemaProxy]{
h.Schema = &SchemaProxy{schema: &lowmodel.NodeReference[*base.SchemaProxy]{
Value: header.Schema.Value,
KeyNode: header.Schema.KeyNode,
ValueNode: header.Schema.ValueNode,

View File

@@ -4,7 +4,7 @@
package v3
import (
low "github.com/pb33f/libopenapi/datamodel/low/shared"
low "github.com/pb33f/libopenapi/datamodel/low/base"
)
type Info struct {

View File

@@ -4,7 +4,7 @@
package v3
import (
low "github.com/pb33f/libopenapi/datamodel/low/shared"
low "github.com/pb33f/libopenapi/datamodel/low/base"
)
type License struct {

View File

@@ -6,7 +6,7 @@ package v3
import (
"github.com/pb33f/libopenapi/datamodel/high"
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/shared"
"github.com/pb33f/libopenapi/datamodel/low/base"
"sync"
)
@@ -47,10 +47,10 @@ type Schema struct {
Example any
Deprecated bool
Extensions map[string]any
low *shared.Schema
low *base.Schema
}
func NewSchema(schema *shared.Schema) *Schema {
func NewSchema(schema *base.Schema) *Schema {
s := new(Schema)
s.low = schema
s.Title = schema.Title.Value
@@ -108,13 +108,13 @@ func NewSchema(schema *shared.Schema) *Schema {
errChan := make(chan error)
// schema async
buildOutSchema := func(schemas []lowmodel.ValueReference[*shared.SchemaProxy], items *[]*SchemaProxy,
buildOutSchema := func(schemas []lowmodel.ValueReference[*base.SchemaProxy], items *[]*SchemaProxy,
doneChan chan bool, e chan error) {
bChan := make(chan *SchemaProxy)
// for every item, build schema async
buildSchemaChild := func(sch lowmodel.ValueReference[*shared.SchemaProxy], bChan chan *SchemaProxy) {
p := &SchemaProxy{schema: &lowmodel.NodeReference[*shared.SchemaProxy]{
buildSchemaChild := func(sch lowmodel.ValueReference[*base.SchemaProxy], bChan chan *SchemaProxy) {
p := &SchemaProxy{schema: &lowmodel.NodeReference[*base.SchemaProxy]{
ValueNode: sch.ValueNode,
Value: sch.Value,
}}
@@ -137,11 +137,11 @@ func NewSchema(schema *shared.Schema) *Schema {
// props async
plock := sync.RWMutex{}
var buildProps = func(k lowmodel.KeyReference[string], v lowmodel.ValueReference[*shared.SchemaProxy], c chan bool,
var buildProps = func(k lowmodel.KeyReference[string], v lowmodel.ValueReference[*base.SchemaProxy], c chan bool,
props map[string]*SchemaProxy) {
defer plock.Unlock()
plock.Lock()
props[k.Value] = &SchemaProxy{schema: &lowmodel.NodeReference[*shared.SchemaProxy]{
props[k.Value] = &SchemaProxy{schema: &lowmodel.NodeReference[*base.SchemaProxy]{
Value: v.Value,
KeyNode: k.KeyNode,
ValueNode: v.ValueNode,
@@ -208,6 +208,6 @@ func NewSchema(schema *shared.Schema) *Schema {
return s
}
func (s *Schema) GoLow() *shared.Schema {
func (s *Schema) GoLow() *base.Schema {
return s.low
}

View File

@@ -5,7 +5,7 @@ package v3
import (
"github.com/pb33f/libopenapi/datamodel/low"
v3 "github.com/pb33f/libopenapi/datamodel/low/shared"
v3 "github.com/pb33f/libopenapi/datamodel/low/base"
)
type SchemaProxy struct {

View File

@@ -5,7 +5,7 @@ package v3
import (
"github.com/pb33f/libopenapi/datamodel/low"
v3 "github.com/pb33f/libopenapi/datamodel/low/shared"
v3 "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/index"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"

View File

@@ -5,7 +5,7 @@ package v3
import (
"github.com/pb33f/libopenapi/datamodel/high"
low "github.com/pb33f/libopenapi/datamodel/low/3.0"
low "github.com/pb33f/libopenapi/datamodel/low/base"
)
type Tag struct {

View File

@@ -5,7 +5,7 @@ package v3
import (
"github.com/pb33f/libopenapi/datamodel/high"
low "github.com/pb33f/libopenapi/datamodel/low/3.0"
low "github.com/pb33f/libopenapi/datamodel/low/base"
)
type XML struct {

View File

@@ -5,13 +5,21 @@ package v2
import (
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/shared"
"github.com/pb33f/libopenapi/datamodel/low/base"
)
type Definitions struct {
Schemas low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*shared.SchemaProxy]]
type ParameterDefinitions struct {
Parameters low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Parameter]]
}
func (d *Definitions) FindSchema(schema string) *low.ValueReference[*shared.SchemaProxy] {
return low.FindItemInMap[*shared.SchemaProxy](schema, d.Schemas.Value)
type Definitions struct {
Schemas low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*base.SchemaProxy]]
}
func (d *Definitions) FindSchema(schema string) *low.ValueReference[*base.SchemaProxy] {
return low.FindItemInMap[*base.SchemaProxy](schema, d.Schemas.Value)
}
func (pd *ParameterDefinitions) FindSchema(schema string) *low.ValueReference[*Parameter] {
return low.FindItemInMap[*Parameter](schema, pd.Parameters.Value)
}

View File

@@ -0,0 +1,45 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v2
import (
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/index"
"gopkg.in/yaml.v3"
)
type Header struct {
Type low.NodeReference[string]
Format low.NodeReference[string]
Description low.NodeReference[string]
Items low.NodeReference[*Items]
CollectionFormat low.NodeReference[string]
Default low.NodeReference[any]
Maximum low.NodeReference[int]
ExclusiveMaximum low.NodeReference[bool]
Minimum low.NodeReference[int]
ExclusiveMinimum low.NodeReference[bool]
MaxLength low.NodeReference[int]
MinLength low.NodeReference[int]
Pattern low.NodeReference[string]
MaxItems low.NodeReference[int]
MinItems low.NodeReference[int]
UniqueItems low.NodeReference[bool]
Enum low.NodeReference[[]string]
MultipleOf low.NodeReference[int]
Extensions map[low.KeyReference[string]]low.ValueReference[any]
}
func (h *Header) FindExtension(ext string) *low.ValueReference[any] {
return low.FindItemInMap[any](ext, h.Extensions)
}
func (h *Header) Build(root *yaml.Node, idx *index.SpecIndex) error {
h.Extensions = low.ExtractExtensions(root)
// TODO: build items.
return nil
}

View File

@@ -0,0 +1,16 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v2
import (
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/base"
)
type Response struct {
Description low.NodeReference[string]
Schema low.NodeReference[*base.SchemaProxy]
Headers low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Header]]
Examples low.NodeReference[map[low.KeyReference[string]]low.ValueReference[any]]
}

View File

@@ -0,0 +1,11 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v2
import "github.com/pb33f/libopenapi/datamodel/low"
type Scopes struct {
Values low.NodeReference[map[low.KeyReference[string]]low.ValueReference[string]]
Extensions map[low.KeyReference[string]]low.ValueReference[any]
}

View File

@@ -0,0 +1,10 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v2
import "github.com/pb33f/libopenapi/datamodel/low"
type SecurityRequirement struct {
Values low.NodeReference[[]low.ValueReference[string]]
}

View File

@@ -0,0 +1,18 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v2
import "github.com/pb33f/libopenapi/datamodel/low"
type SecurityScheme struct {
Type low.NodeReference[string]
Description low.NodeReference[string]
Name low.NodeReference[string]
In low.NodeReference[string]
Flow low.NodeReference[string]
AuthorizationUrl low.NodeReference[string]
TokenUrl low.NodeReference[string]
Scopes low.NodeReference[*Scopes]
Extensions map[low.KeyReference[string]]low.ValueReference[any]
}

View File

@@ -5,15 +5,26 @@ package v2
import (
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/shared"
"github.com/pb33f/libopenapi/datamodel/low/base"
)
type Swagger struct {
Swagger low.NodeReference[string]
Info low.NodeReference[*shared.Info]
Info low.NodeReference[*base.Info]
Host low.NodeReference[string]
BasePath low.NodeReference[string]
Schemes low.KeyReference[[]low.ValueReference[string]]
Consumes low.KeyReference[[]low.ValueReference[string]]
Produces low.KeyReference[[]low.ValueReference[string]]
Schemes low.NodeReference[[]low.ValueReference[string]]
Consumes low.NodeReference[[]low.ValueReference[string]]
Produces low.NodeReference[[]low.ValueReference[string]]
// TODO: paths
Definitions low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*base.SchemaProxy]]
Parameters low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Parameter]]
Responses low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Response]]
SecurityDefinitions low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*SecurityScheme]]
Security low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*SecurityRequirement]]
Tags low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*base.Tag]]
ExternalDocs low.NodeReference[*base.ExternalDoc]
Extensions map[low.KeyReference[string]]low.ValueReference[any]
}

View File

@@ -6,7 +6,7 @@ package v3
import (
"fmt"
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/shared"
"github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/utils"
"gopkg.in/yaml.v3"
@@ -19,10 +19,10 @@ const (
)
type Components struct {
Schemas low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*shared.SchemaProxy]]
Schemas low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*base.SchemaProxy]]
Responses low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Response]]
Parameters low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Parameter]]
Examples low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Example]]
Examples low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*base.Example]]
RequestBodies low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*RequestBody]]
Headers low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Header]]
SecuritySchemes low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*SecurityScheme]]
@@ -35,8 +35,8 @@ func (co *Components) FindExtension(ext string) *low.ValueReference[any] {
return low.FindItemInMap[any](ext, co.Extensions)
}
func (co *Components) FindSchema(schema string) *low.ValueReference[*shared.SchemaProxy] {
return low.FindItemInMap[*shared.SchemaProxy](schema, co.Schemas.Value)
func (co *Components) FindSchema(schema string) *low.ValueReference[*base.SchemaProxy] {
return low.FindItemInMap[*base.SchemaProxy](schema, co.Schemas.Value)
}
func (co *Components) FindResponse(response string) *low.ValueReference[*Response] {
@@ -51,8 +51,8 @@ func (co *Components) FindSecurityScheme(sScheme string) *low.ValueReference[*Se
return low.FindItemInMap[*SecurityScheme](sScheme, co.SecuritySchemes.Value)
}
func (co *Components) FindExample(example string) *low.ValueReference[*Example] {
return low.FindItemInMap[*Example](example, co.Examples.Value)
func (co *Components) FindExample(example string) *low.ValueReference[*base.Example] {
return low.FindItemInMap[*base.Example](example, co.Examples.Value)
}
func (co *Components) FindRequestBody(requestBody string) *low.ValueReference[*RequestBody] {
@@ -78,19 +78,19 @@ func (co *Components) Build(root *yaml.Node, idx *index.SpecIndex) error {
skipChan := make(chan bool)
errorChan := make(chan error)
paramChan := make(chan low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Parameter]])
schemaChan := make(chan low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*shared.SchemaProxy]])
schemaChan := make(chan low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*base.SchemaProxy]])
responsesChan := make(chan low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Response]])
examplesChan := make(chan low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Example]])
examplesChan := make(chan low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*base.Example]])
requestBodiesChan := make(chan low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*RequestBody]])
headersChan := make(chan low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Header]])
securitySchemesChan := make(chan low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*SecurityScheme]])
linkChan := make(chan low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Link]])
callbackChan := make(chan low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Callback]])
go extractComponentValues[*shared.SchemaProxy](SchemasLabel, root, skipChan, errorChan, schemaChan, idx)
go extractComponentValues[*base.SchemaProxy](SchemasLabel, root, skipChan, errorChan, schemaChan, idx)
go extractComponentValues[*Parameter](ParametersLabel, root, skipChan, errorChan, paramChan, idx)
go extractComponentValues[*Response](ResponsesLabel, root, skipChan, errorChan, responsesChan, idx)
go extractComponentValues[*Example](ExamplesLabel, root, skipChan, errorChan, examplesChan, idx)
go extractComponentValues[*base.Example](base.ExamplesLabel, root, skipChan, errorChan, examplesChan, idx)
go extractComponentValues[*RequestBody](RequestBodiesLabel, root, skipChan, errorChan, requestBodiesChan, idx)
go extractComponentValues[*Header](HeadersLabel, root, skipChan, errorChan, headersChan, idx)
go extractComponentValues[*SecurityScheme](SecuritySchemesLabel, root, skipChan, errorChan, securitySchemesChan, idx)

View File

@@ -3,7 +3,7 @@ package v3
import (
"github.com/pb33f/libopenapi/datamodel"
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/shared"
"github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/resolver"
"github.com/pb33f/libopenapi/utils"
@@ -57,12 +57,12 @@ func CreateDocument(info *datamodel.SpecInfo) (*Document, []error) {
}
func extractInfo(info *datamodel.SpecInfo, doc *Document, idx *index.SpecIndex) error {
_, ln, vn := utils.FindKeyNodeFull(shared.InfoLabel, info.RootNode.Content)
_, ln, vn := utils.FindKeyNodeFull(base.InfoLabel, info.RootNode.Content)
if vn != nil {
ir := shared.Info{}
ir := base.Info{}
_ = low.BuildModel(vn, &ir)
_ = ir.Build(vn, idx)
nr := low.NodeReference[*shared.Info]{Value: &ir, ValueNode: vn, KeyNode: ln}
nr := low.NodeReference[*base.Info]{Value: &ir, ValueNode: vn, KeyNode: ln}
doc.Info = nr
}
return nil
@@ -78,7 +78,7 @@ func extractSecurity(info *datamodel.SpecInfo, doc *Document, idx *index.SpecInd
}
func extractExternalDocs(info *datamodel.SpecInfo, doc *Document, idx *index.SpecIndex) error {
extDocs, dErr := low.ExtractObject[*ExternalDoc](ExternalDocsLabel, info.RootNode, idx)
extDocs, dErr := low.ExtractObject[*base.ExternalDoc](base.ExternalDocsLabel, info.RootNode, idx)
if dErr != nil {
return dErr
}
@@ -128,24 +128,24 @@ func extractServers(info *datamodel.SpecInfo, doc *Document, idx *index.SpecInde
}
func extractTags(info *datamodel.SpecInfo, doc *Document, idx *index.SpecIndex) error {
_, ln, vn := utils.FindKeyNodeFull(TagsLabel, info.RootNode.Content)
_, ln, vn := utils.FindKeyNodeFull(base.TagsLabel, info.RootNode.Content)
if vn != nil {
if utils.IsNodeArray(vn) {
var tags []low.ValueReference[*Tag]
var tags []low.ValueReference[*base.Tag]
for _, tagN := range vn.Content {
if utils.IsNodeMap(tagN) {
tag := Tag{}
tag := base.Tag{}
_ = low.BuildModel(tagN, &tag)
if err := tag.Build(tagN, idx); err != nil {
return err
}
tags = append(tags, low.ValueReference[*Tag]{
tags = append(tags, low.ValueReference[*base.Tag]{
Value: &tag,
ValueNode: tagN,
})
}
}
doc.Tags = low.NodeReference[[]low.ValueReference[*Tag]]{
doc.Tags = low.NodeReference[[]low.ValueReference[*base.Tag]]{
Value: tags,
KeyNode: ln,
ValueNode: vn,

View File

@@ -2,7 +2,7 @@ package v3
import (
"github.com/pb33f/libopenapi/datamodel"
"github.com/pb33f/libopenapi/datamodel/low/shared"
"github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/stretchr/testify/assert"
"io/ioutil"
"testing"
@@ -470,7 +470,7 @@ func TestCreateDocument_CheckAdditionalProperties_Schema(t *testing.T) {
components := doc.Components.Value
d := components.FindSchema("Dressing")
assert.NotNil(t, d.Value.Schema().AdditionalProperties.Value)
if n, ok := d.Value.Schema().AdditionalProperties.Value.(*shared.Schema); ok {
if n, ok := d.Value.Schema().AdditionalProperties.Value.(*base.Schema); ok {
assert.Equal(t, "something in here.", n.Description.Value)
} else {
assert.Fail(t, "should be a schema")

View File

@@ -5,19 +5,19 @@ package v3
import (
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/shared"
"github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/index"
)
type Document struct {
Version low.ValueReference[string]
Info low.NodeReference[*shared.Info]
Info low.NodeReference[*base.Info]
Servers low.NodeReference[[]low.ValueReference[*Server]]
Paths low.NodeReference[*Paths]
Components low.NodeReference[*Components]
Security low.NodeReference[*SecurityRequirement]
Tags low.NodeReference[[]low.ValueReference[*Tag]]
ExternalDocs low.NodeReference[*ExternalDoc]
Tags low.NodeReference[[]low.ValueReference[*base.Tag]]
ExternalDocs low.NodeReference[*base.ExternalDoc]
Extensions map[low.KeyReference[string]]low.ValueReference[any]
Index *index.SpecIndex
}

View File

@@ -5,7 +5,7 @@ package v3
import (
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/shared"
"github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/utils"
"gopkg.in/yaml.v3"
@@ -23,9 +23,9 @@ type Header struct {
Style low.NodeReference[string]
Explode low.NodeReference[bool]
AllowReserved low.NodeReference[bool]
Schema low.NodeReference[*shared.SchemaProxy]
Schema low.NodeReference[*base.SchemaProxy]
Example low.NodeReference[any]
Examples low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Example]]
Examples low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*base.Example]]
Content low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*MediaType]]
Extensions map[low.KeyReference[string]]low.ValueReference[any]
}
@@ -34,8 +34,8 @@ func (h *Header) FindExtension(ext string) *low.ValueReference[any] {
return low.FindItemInMap[any](ext, h.Extensions)
}
func (h *Header) FindExample(eType string) *low.ValueReference[*Example] {
return low.FindItemInMap[*Example](eType, h.Examples.Value)
func (h *Header) FindExample(eType string) *low.ValueReference[*base.Example] {
return low.FindItemInMap[*base.Example](eType, h.Examples.Value)
}
func (h *Header) FindContent(ext string) *low.ValueReference[*MediaType] {
@@ -46,18 +46,18 @@ func (h *Header) Build(root *yaml.Node, idx *index.SpecIndex) error {
h.Extensions = low.ExtractExtensions(root)
// handle example if set.
_, expLabel, expNode := utils.FindKeyNodeFull(ExampleLabel, root.Content)
_, expLabel, expNode := utils.FindKeyNodeFull(base.ExampleLabel, root.Content)
if expNode != nil {
h.Example = low.ExtractExample(expNode, expLabel)
}
// handle examples if set.
exps, expsL, expsN, eErr := low.ExtractMapFlat[*Example](ExamplesLabel, root, idx)
exps, expsL, expsN, eErr := low.ExtractMapFlat[*base.Example](base.ExamplesLabel, root, idx)
if eErr != nil {
return eErr
}
if exps != nil {
h.Examples = low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Example]]{
h.Examples = low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*base.Example]]{
Value: exps,
KeyNode: expsL,
ValueNode: expsN,
@@ -65,7 +65,7 @@ func (h *Header) Build(root *yaml.Node, idx *index.SpecIndex) error {
}
// handle schema
sch, sErr := shared.ExtractSchema(root, idx)
sch, sErr := base.ExtractSchema(root, idx)
if sErr != nil {
return sErr
}

View File

@@ -5,16 +5,16 @@ package v3
import (
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/shared"
"github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/utils"
"gopkg.in/yaml.v3"
)
type MediaType struct {
Schema low.NodeReference[*shared.SchemaProxy]
Schema low.NodeReference[*base.SchemaProxy]
Example low.NodeReference[any]
Examples low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Example]]
Examples low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*base.Example]]
Encoding low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Encoding]]
Extensions map[low.KeyReference[string]]low.ValueReference[any]
}
@@ -27,11 +27,11 @@ func (mt *MediaType) FindPropertyEncoding(eType string) *low.ValueReference[*Enc
return low.FindItemInMap[*Encoding](eType, mt.Encoding.Value)
}
func (mt *MediaType) FindExample(eType string) *low.ValueReference[*Example] {
return low.FindItemInMap[*Example](eType, mt.Examples.Value)
func (mt *MediaType) FindExample(eType string) *low.ValueReference[*base.Example] {
return low.FindItemInMap[*base.Example](eType, mt.Examples.Value)
}
func (mt *MediaType) GetAllExamples() map[low.KeyReference[string]]low.ValueReference[*Example] {
func (mt *MediaType) GetAllExamples() map[low.KeyReference[string]]low.ValueReference[*base.Example] {
return mt.Examples.Value
}
@@ -39,13 +39,13 @@ func (mt *MediaType) Build(root *yaml.Node, idx *index.SpecIndex) error {
mt.Extensions = low.ExtractExtensions(root)
// handle example if set.
_, expLabel, expNode := utils.FindKeyNodeFull(ExampleLabel, root.Content)
_, expLabel, expNode := utils.FindKeyNodeFull(base.ExampleLabel, root.Content)
if expNode != nil {
mt.Example = low.NodeReference[any]{Value: expNode.Value, KeyNode: expLabel, ValueNode: expNode}
}
//handle schema
sch, sErr := shared.ExtractSchema(root, idx)
sch, sErr := base.ExtractSchema(root, idx)
if sErr != nil {
return sErr
}
@@ -54,12 +54,12 @@ func (mt *MediaType) Build(root *yaml.Node, idx *index.SpecIndex) error {
}
// handle examples if set.
exps, expsL, expsN, eErr := low.ExtractMapFlat[*Example](ExamplesLabel, root, idx)
exps, expsL, expsN, eErr := low.ExtractMapFlat[*base.Example](base.ExamplesLabel, root, idx)
if eErr != nil {
return eErr
}
if exps != nil {
mt.Examples = low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Example]]{
mt.Examples = low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*base.Example]]{
Value: exps,
KeyNode: expsL,
ValueNode: expsN,

View File

@@ -5,6 +5,7 @@ package v3
import (
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/index"
"gopkg.in/yaml.v3"
)
@@ -21,7 +22,7 @@ type Operation struct {
Tags low.NodeReference[[]low.ValueReference[string]]
Summary low.NodeReference[string]
Description low.NodeReference[string]
ExternalDocs low.NodeReference[*ExternalDoc]
ExternalDocs low.NodeReference[*base.ExternalDoc]
OperationId low.NodeReference[string]
Parameters low.NodeReference[[]low.ValueReference[*Parameter]]
RequestBody low.NodeReference[*RequestBody]
@@ -41,7 +42,7 @@ func (o *Operation) Build(root *yaml.Node, idx *index.SpecIndex) error {
o.Extensions = low.ExtractExtensions(root)
// extract externalDocs
extDocs, dErr := low.ExtractObject[*ExternalDoc](ExternalDocsLabel, root, idx)
extDocs, dErr := low.ExtractObject[*base.ExternalDoc](base.ExternalDocsLabel, root, idx)
if dErr != nil {
return dErr
}

View File

@@ -5,14 +5,13 @@ package v3
import (
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/shared"
"github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/utils"
"gopkg.in/yaml.v3"
)
const (
SchemaLabel = "schema"
ContentLabel = "content"
)
@@ -26,9 +25,9 @@ type Parameter struct {
Style low.NodeReference[string]
Explode low.NodeReference[bool]
AllowReserved low.NodeReference[bool]
Schema low.NodeReference[*shared.SchemaProxy]
Schema low.NodeReference[*base.SchemaProxy]
Example low.NodeReference[any]
Examples low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Example]]
Examples low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*base.Example]]
Content low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*MediaType]]
Extensions map[low.KeyReference[string]]low.ValueReference[any]
}
@@ -37,8 +36,8 @@ func (p *Parameter) FindContent(cType string) *low.ValueReference[*MediaType] {
return low.FindItemInMap[*MediaType](cType, p.Content.Value)
}
func (p *Parameter) FindExample(eType string) *low.ValueReference[*Example] {
return low.FindItemInMap[*Example](eType, p.Examples.Value)
func (p *Parameter) FindExample(eType string) *low.ValueReference[*base.Example] {
return low.FindItemInMap[*base.Example](eType, p.Examples.Value)
}
func (p *Parameter) FindExtension(ext string) *low.ValueReference[any] {
@@ -49,13 +48,13 @@ func (p *Parameter) Build(root *yaml.Node, idx *index.SpecIndex) error {
p.Extensions = low.ExtractExtensions(root)
// handle example if set.
_, expLabel, expNode := utils.FindKeyNodeFull(ExampleLabel, root.Content)
_, expLabel, expNode := utils.FindKeyNodeFull(base.ExampleLabel, root.Content)
if expNode != nil {
p.Example = low.ExtractExample(expNode, expLabel)
}
// handle schema
sch, sErr := shared.ExtractSchema(root, idx)
sch, sErr := base.ExtractSchema(root, idx)
if sErr != nil {
return sErr
}
@@ -64,12 +63,12 @@ func (p *Parameter) Build(root *yaml.Node, idx *index.SpecIndex) error {
}
// handle examples if set.
exps, expsL, expsN, eErr := low.ExtractMapFlat[*Example](ExamplesLabel, root, idx)
exps, expsL, expsN, eErr := low.ExtractMapFlat[*base.Example](base.ExamplesLabel, root, idx)
if eErr != nil {
return eErr
}
if exps != nil {
p.Examples = low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*Example]]{
p.Examples = low.NodeReference[map[low.KeyReference[string]]low.ValueReference[*base.Example]]{
Value: exps,
KeyNode: expsL,
ValueNode: expsN,

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package shared
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v3
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v3
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v3
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v3
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v3
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v3
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package shared
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package shared
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package shared
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -1,9 +1,8 @@
package shared
package base
import (
"fmt"
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/3.0"
"github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/utils"
"gopkg.in/yaml.v3"
@@ -20,6 +19,7 @@ const (
OneOfLabel = "oneOf"
NotLabel = "not"
DiscriminatorLabel = "discriminator"
SchemaLabel = "schema"
)
type Schema struct {
@@ -51,11 +51,11 @@ type Schema struct {
Description low.NodeReference[string]
Default low.NodeReference[any]
Nullable low.NodeReference[bool]
Discriminator low.NodeReference[*v3.Discriminator]
Discriminator low.NodeReference[*Discriminator]
ReadOnly low.NodeReference[bool]
WriteOnly low.NodeReference[bool]
XML low.NodeReference[*v3.XML]
ExternalDocs low.NodeReference[*v3.ExternalDoc]
XML low.NodeReference[*XML]
ExternalDocs low.NodeReference[*ExternalDoc]
Example low.NodeReference[any]
Deprecated low.NodeReference[bool]
Extensions map[low.KeyReference[string]]low.ValueReference[any]
@@ -84,9 +84,9 @@ func (s *Schema) Build(root *yaml.Node, idx *index.SpecIndex) error {
s.extractExtensions(root)
// handle example if set.
_, expLabel, expNode := utils.FindKeyNodeFull(v3.ExampleLabel, root.Content)
_, expLabel, expNode := utils.FindKeyNodeFull(ExampleLabel, root.Content)
if expNode != nil {
s.Example = low.NodeReference[any]{Value: v3.ExtractExampleValue(expNode), KeyNode: expLabel, ValueNode: expNode}
s.Example = low.NodeReference[any]{Value: ExtractExampleValue(expNode), KeyNode: expLabel, ValueNode: expNode}
}
_, addPLabel, addPNode := utils.FindKeyNodeFull(AdditionalPropertiesLabel, root.Content)
@@ -108,28 +108,28 @@ func (s *Schema) Build(root *yaml.Node, idx *index.SpecIndex) error {
// handle discriminator if set.
_, discLabel, discNode := utils.FindKeyNodeFull(DiscriminatorLabel, root.Content)
if discNode != nil {
var discriminator v3.Discriminator
var discriminator Discriminator
_ = low.BuildModel(discNode, &discriminator)
s.Discriminator = low.NodeReference[*v3.Discriminator]{Value: &discriminator, KeyNode: discLabel, ValueNode: discNode}
s.Discriminator = low.NodeReference[*Discriminator]{Value: &discriminator, KeyNode: discLabel, ValueNode: discNode}
}
// handle externalDocs if set.
_, extDocLabel, extDocNode := utils.FindKeyNodeFull(v3.ExternalDocsLabel, root.Content)
_, extDocLabel, extDocNode := utils.FindKeyNodeFull(ExternalDocsLabel, root.Content)
if extDocNode != nil {
var exDoc v3.ExternalDoc
var exDoc ExternalDoc
_ = low.BuildModel(extDocNode, &exDoc)
_ = exDoc.Build(extDocNode, idx) // throws no errors, can't check for one.
s.ExternalDocs = low.NodeReference[*v3.ExternalDoc]{Value: &exDoc, KeyNode: extDocLabel, ValueNode: extDocNode}
s.ExternalDocs = low.NodeReference[*ExternalDoc]{Value: &exDoc, KeyNode: extDocLabel, ValueNode: extDocNode}
}
// handle xml if set.
_, xmlLabel, xmlNode := utils.FindKeyNodeFull(XMLLabel, root.Content)
if xmlNode != nil {
var xml v3.XML
var xml XML
_ = low.BuildModel(xmlNode, &xml)
// extract extensions if set.
_ = xml.Build(xmlNode) // returns no errors, can't check for one.
s.XML = low.NodeReference[*v3.XML]{Value: &xml, KeyNode: xmlLabel, ValueNode: xmlNode}
s.XML = low.NodeReference[*XML]{Value: &xml, KeyNode: xmlLabel, ValueNode: xmlNode}
}
// for property, build in a new thread!
@@ -406,7 +406,7 @@ func ExtractSchema(root *yaml.Node, idx *index.SpecIndex) (*low.NodeReference[*S
root.Content[1].Value, root.Content[1].Line, root.Content[1].Column)
}
} else {
_, schLabel, schNode = utils.FindKeyNodeFull(v3.SchemaLabel, root.Content)
_, schLabel, schNode = utils.FindKeyNodeFull(SchemaLabel, root.Content)
if schNode != nil {
if h, _, _ := utils.IsNodeRefValue(schNode); h {
ref, _ := low.LocateRefNode(schNode, idx)

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package shared
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -1,4 +1,4 @@
package shared
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v3
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v3
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -1,4 +1,4 @@
package v3
package base
import (
"github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -8729,7 +8729,7 @@ components:
nullable: true
type: string
team:
description: "*Create-only*. The team that this project is shared with. This field only exists for projects in organizations."
description: "*Create-only*. The team that this project is base with. This field only exists for projects in organizations."
example: "12345"
type: string
type: object
@@ -8800,7 +8800,7 @@ components:
team:
allOf:
- $ref: "#/components/schemas/TeamCompact"
- description: "*Create-only*. The team that this project is shared with. This field only exists for projects in organizations."
- description: "*Create-only*. The team that this project is base with. This field only exists for projects in organizations."
type: object
type: object
ProjectSectionInsertRequest: