mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 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:
@@ -1,35 +0,0 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package datamodel
|
||||
|
||||
//
|
||||
//import (
|
||||
// v2 "github.com/pb33f/libopenapi/datamodel/high/2.0"
|
||||
// v3 "github.com/pb33f/libopenapi/datamodel/high/3.0"
|
||||
//)
|
||||
//
|
||||
//type Document struct {
|
||||
// version string
|
||||
// info *SpecInfo
|
||||
//}
|
||||
//
|
||||
//func (d *Document) GetVersion() string {
|
||||
// return d.version
|
||||
//}
|
||||
//
|
||||
//func (d *Document) BuildV2Document() (*v2.Swagger, error) {
|
||||
// return nil, nil
|
||||
//}
|
||||
//
|
||||
//func (d *Document) BuildV3Document() (*v3.Document, error) {
|
||||
// return nil, nil
|
||||
//}
|
||||
//
|
||||
//func LoadDocument(specBytes []byte) (*Document, error) {
|
||||
// info, err := ExtractSpecInfo(specBytes)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return &Document{info: info, version: info.Version}, nil
|
||||
//}
|
||||
10
datamodel/high/2.0/definitions.go
Normal file
10
datamodel/high/2.0/definitions.go
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v2
|
||||
|
||||
type Definitions struct {
|
||||
}
|
||||
|
||||
type ParameterDefinitions struct {
|
||||
}
|
||||
28
datamodel/high/2.0/examples.go
Normal file
28
datamodel/high/2.0/examples.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v2
|
||||
|
||||
import low "github.com/pb33f/libopenapi/datamodel/low/2.0"
|
||||
|
||||
type Examples struct {
|
||||
Values map[string]any
|
||||
low *low.Examples
|
||||
}
|
||||
|
||||
func NewExamples(examples *low.Examples) *Examples {
|
||||
e := new(Examples)
|
||||
e.low = examples
|
||||
if len(e.Values) > 0 {
|
||||
values := make(map[string]any)
|
||||
for k := range e.Values {
|
||||
values[k] = e.Values[k]
|
||||
}
|
||||
e.Values = values
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *Examples) GoLow() *low.Examples {
|
||||
return e.low
|
||||
}
|
||||
95
datamodel/high/2.0/header.go
Normal file
95
datamodel/high/2.0/header.go
Normal file
@@ -0,0 +1,95 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v2
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/high"
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/2.0"
|
||||
)
|
||||
|
||||
type Header struct {
|
||||
Type string
|
||||
Format string
|
||||
Description string
|
||||
Items *Items
|
||||
CollectionFormat string
|
||||
Default any
|
||||
Maximum int
|
||||
ExclusiveMaximum bool
|
||||
Minimum int
|
||||
ExclusiveMinimum bool
|
||||
MaxLength int
|
||||
MinLength int
|
||||
Pattern string
|
||||
MaxItems int
|
||||
MinItems int
|
||||
UniqueItems bool
|
||||
Enum []string
|
||||
MultipleOf int
|
||||
Extensions map[string]any
|
||||
low *low.Header
|
||||
}
|
||||
|
||||
func NewHeader(header *low.Header) *Header {
|
||||
h := new(Header)
|
||||
h.low = header
|
||||
h.Extensions = high.ExtractExtensions(header.Extensions)
|
||||
if !header.Type.IsEmpty() {
|
||||
h.Type = header.Type.Value
|
||||
}
|
||||
if !header.Format.IsEmpty() {
|
||||
h.Format = header.Type.Value
|
||||
}
|
||||
if !header.Description.IsEmpty() {
|
||||
h.Description = header.Description.Value
|
||||
}
|
||||
if !header.Items.IsEmpty() {
|
||||
// TODO: items
|
||||
//h.Items =
|
||||
}
|
||||
if !header.CollectionFormat.IsEmpty() {
|
||||
h.CollectionFormat = header.CollectionFormat.Value
|
||||
}
|
||||
if !header.Default.IsEmpty() {
|
||||
h.Default = header.Default.Value
|
||||
}
|
||||
if !header.Maximum.IsEmpty() {
|
||||
h.Maximum = header.Maximum.Value
|
||||
}
|
||||
if !header.ExclusiveMaximum.IsEmpty() {
|
||||
h.ExclusiveMaximum = header.ExclusiveMaximum.Value
|
||||
}
|
||||
if !header.Minimum.IsEmpty() {
|
||||
h.Minimum = header.Minimum.Value
|
||||
}
|
||||
if !header.ExclusiveMinimum.Value {
|
||||
h.ExclusiveMinimum = header.ExclusiveMinimum.Value
|
||||
}
|
||||
if !header.MaxLength.IsEmpty() {
|
||||
h.MaxLength = header.MaxLength.Value
|
||||
}
|
||||
if !header.MinLength.IsEmpty() {
|
||||
h.MinLength = header.MinLength.Value
|
||||
}
|
||||
if !header.Pattern.IsEmpty() {
|
||||
h.Pattern = header.Pattern.Value
|
||||
}
|
||||
if !header.MinItems.IsEmpty() {
|
||||
h.MinItems = header.MinItems.Value
|
||||
}
|
||||
if !header.MaxItems.IsEmpty() {
|
||||
h.MaxItems = header.MaxItems.Value
|
||||
}
|
||||
if !header.UniqueItems.IsEmpty() {
|
||||
h.UniqueItems = header.UniqueItems.IsEmpty()
|
||||
}
|
||||
if !header.Enum.IsEmpty() {
|
||||
h.Enum = header.Enum.Value
|
||||
}
|
||||
if !header.MultipleOf.IsEmpty() {
|
||||
h.MultipleOf = header.MultipleOf.Value
|
||||
}
|
||||
|
||||
return h
|
||||
}
|
||||
88
datamodel/high/2.0/items.go
Normal file
88
datamodel/high/2.0/items.go
Normal file
@@ -0,0 +1,88 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v2
|
||||
|
||||
import low "github.com/pb33f/libopenapi/datamodel/low/2.0"
|
||||
|
||||
type Items struct {
|
||||
Type string
|
||||
Format string
|
||||
CollectionFormat string
|
||||
Items *Items
|
||||
Default any
|
||||
Maximum int
|
||||
ExclusiveMaximum bool
|
||||
Minimum int
|
||||
ExclusiveMinimum bool
|
||||
MaxLength int
|
||||
MinLength int
|
||||
Pattern string
|
||||
MaxItems int
|
||||
MinItems int
|
||||
UniqueItems bool
|
||||
Enum []string
|
||||
MultipleOf int
|
||||
low *low.Items
|
||||
}
|
||||
|
||||
func NewItems(items *low.Items) *Items {
|
||||
i := new(Items)
|
||||
i.low = items
|
||||
if !items.Type.IsEmpty() {
|
||||
i.Type = items.Type.Value
|
||||
}
|
||||
if !items.Format.IsEmpty() {
|
||||
i.Format = items.Type.Value
|
||||
}
|
||||
if !items.Items.IsEmpty() {
|
||||
i.Items = NewItems(items.Items.Value)
|
||||
}
|
||||
if !items.CollectionFormat.IsEmpty() {
|
||||
i.CollectionFormat = items.CollectionFormat.Value
|
||||
}
|
||||
if !items.Default.IsEmpty() {
|
||||
i.Default = items.Default.Value
|
||||
}
|
||||
if !items.Maximum.IsEmpty() {
|
||||
i.Maximum = items.Maximum.Value
|
||||
}
|
||||
if !items.ExclusiveMaximum.IsEmpty() {
|
||||
i.ExclusiveMaximum = items.ExclusiveMaximum.Value
|
||||
}
|
||||
if !items.Minimum.IsEmpty() {
|
||||
i.Minimum = items.Minimum.Value
|
||||
}
|
||||
if !items.ExclusiveMinimum.Value {
|
||||
i.ExclusiveMinimum = items.ExclusiveMinimum.Value
|
||||
}
|
||||
if !items.MaxLength.IsEmpty() {
|
||||
i.MaxLength = items.MaxLength.Value
|
||||
}
|
||||
if !items.MinLength.IsEmpty() {
|
||||
i.MinLength = items.MinLength.Value
|
||||
}
|
||||
if !items.Pattern.IsEmpty() {
|
||||
i.Pattern = items.Pattern.Value
|
||||
}
|
||||
if !items.MinItems.IsEmpty() {
|
||||
i.MinItems = items.MinItems.Value
|
||||
}
|
||||
if !items.MaxItems.IsEmpty() {
|
||||
i.MaxItems = items.MaxItems.Value
|
||||
}
|
||||
if !items.UniqueItems.IsEmpty() {
|
||||
i.UniqueItems = items.UniqueItems.IsEmpty()
|
||||
}
|
||||
if !items.Enum.IsEmpty() {
|
||||
i.Enum = items.Enum.Value
|
||||
}
|
||||
if !items.MultipleOf.IsEmpty() {
|
||||
i.MultipleOf = items.MultipleOf.Value
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func (i *Items) GoLow() *low.Items {
|
||||
return i.low
|
||||
}
|
||||
7
datamodel/high/2.0/paths.go
Normal file
7
datamodel/high/2.0/paths.go
Normal file
@@ -0,0 +1,7 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v2
|
||||
|
||||
type Paths struct {
|
||||
}
|
||||
38
datamodel/high/2.0/response.go
Normal file
38
datamodel/high/2.0/response.go
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v2
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/high"
|
||||
"github.com/pb33f/libopenapi/datamodel/high/base"
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/2.0"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Description string
|
||||
Schema *base.SchemaProxy
|
||||
Headers map[string]*Header
|
||||
Examples *Examples
|
||||
Extensions map[string]any
|
||||
low *low.Response
|
||||
}
|
||||
|
||||
func NewResponse(response *low.Response) *Response {
|
||||
r := new(Response)
|
||||
r.low = response
|
||||
r.Extensions = high.ExtractExtensions(response.Extensions)
|
||||
if !response.Schema.IsEmpty() {
|
||||
r.Schema = base.NewSchemaProxy(&response.Schema)
|
||||
}
|
||||
if !response.Headers.IsEmpty() {
|
||||
headers := make(map[string]*Header)
|
||||
for k := range response.Headers.Value {
|
||||
headers[k.Value] = NewHeader(response.Headers.Value[k].Value)
|
||||
}
|
||||
}
|
||||
if !response.Examples.IsEmpty() {
|
||||
r.Examples = NewExamples(response.Examples.Value)
|
||||
}
|
||||
return r
|
||||
}
|
||||
22
datamodel/high/2.0/responses_definitions.go
Normal file
22
datamodel/high/2.0/responses_definitions.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v2
|
||||
|
||||
import low "github.com/pb33f/libopenapi/datamodel/low/2.0"
|
||||
|
||||
type ResponsesDefinitions struct {
|
||||
Values map[string]*Response
|
||||
low *low.ResponsesDefinitions
|
||||
}
|
||||
|
||||
func NewResponsesDefinitions(responsesDefinitions *low.ResponsesDefinitions) *ResponsesDefinitions {
|
||||
rd := new(ResponsesDefinitions)
|
||||
rd.low = responsesDefinitions
|
||||
responses := make(map[string]*Response)
|
||||
for k := range responsesDefinitions.Definitions {
|
||||
responses[k.Value] = NewResponse(responsesDefinitions.Definitions[k].Value)
|
||||
}
|
||||
rd.Values = responses
|
||||
return rd
|
||||
}
|
||||
28
datamodel/high/2.0/scopes.go
Normal file
28
datamodel/high/2.0/scopes.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v2
|
||||
|
||||
import (
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/2.0"
|
||||
)
|
||||
|
||||
type Scopes struct {
|
||||
Values map[string]string
|
||||
low *low.Scopes
|
||||
}
|
||||
|
||||
func NewScopes(scopes *low.Scopes) *Scopes {
|
||||
s := new(Scopes)
|
||||
s.low = scopes
|
||||
scopeValues := make(map[string]string)
|
||||
for k := range scopes.Values {
|
||||
scopeValues[k.Value] = scopes.Values[k].Value
|
||||
}
|
||||
s.Values = scopeValues
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Scopes) GoLow() *low.Scopes {
|
||||
return s.low
|
||||
}
|
||||
26
datamodel/high/2.0/security_definitions.go
Normal file
26
datamodel/high/2.0/security_definitions.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v2
|
||||
|
||||
import low "github.com/pb33f/libopenapi/datamodel/low/2.0"
|
||||
|
||||
type SecurityDefinitions struct {
|
||||
Values map[string]*SecurityScheme
|
||||
low *low.SecurityDefinitions
|
||||
}
|
||||
|
||||
func NewSecurityDefinitions(definitions *low.SecurityDefinitions) *SecurityDefinitions {
|
||||
sd := new(SecurityDefinitions)
|
||||
sd.low = definitions
|
||||
schemes := make(map[string]*SecurityScheme)
|
||||
for k := range definitions.Definitions {
|
||||
schemes[k.Value] = NewSecurityScheme(definitions.Definitions[k].Value)
|
||||
}
|
||||
sd.Values = schemes
|
||||
return sd
|
||||
}
|
||||
|
||||
func (sd *SecurityDefinitions) GoLow() *low.SecurityDefinitions {
|
||||
return sd.low
|
||||
}
|
||||
31
datamodel/high/2.0/security_requirement.go
Normal file
31
datamodel/high/2.0/security_requirement.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v2
|
||||
|
||||
import low "github.com/pb33f/libopenapi/datamodel/low/2.0"
|
||||
|
||||
type SecurityRequirement struct {
|
||||
Requirements map[string][]string
|
||||
low *low.SecurityRequirement
|
||||
}
|
||||
|
||||
func NewSecurityRequirement(req *low.SecurityRequirement) *SecurityRequirement {
|
||||
r := new(SecurityRequirement)
|
||||
r.low = req
|
||||
var values map[string][]string
|
||||
// to keep things fast, avoiding copying anything - makes it a little hard to read.
|
||||
for reqK := range req.Values.Value {
|
||||
var vals []string
|
||||
for valK := range req.Values.Value[reqK].Value {
|
||||
vals = append(vals, req.Values.Value[reqK].Value[valK].Value)
|
||||
}
|
||||
values[reqK.Value] = vals
|
||||
}
|
||||
r.Requirements = values
|
||||
return r
|
||||
}
|
||||
|
||||
func (s *SecurityRequirement) GoLow() *low.SecurityRequirement {
|
||||
return s.low
|
||||
}
|
||||
53
datamodel/high/2.0/security_scheme.go
Normal file
53
datamodel/high/2.0/security_scheme.go
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v2
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/high"
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/2.0"
|
||||
)
|
||||
|
||||
type SecurityScheme struct {
|
||||
Type string
|
||||
Description string
|
||||
Name string
|
||||
In string
|
||||
Flow string
|
||||
AuthorizationUrl string
|
||||
TokenUrl string
|
||||
Scopes *Scopes
|
||||
Extensions map[string]any
|
||||
low *low.SecurityScheme
|
||||
}
|
||||
|
||||
func NewSecurityScheme(securityScheme *low.SecurityScheme) *SecurityScheme {
|
||||
s := new(SecurityScheme)
|
||||
s.low = securityScheme
|
||||
s.Extensions = high.ExtractExtensions(securityScheme.Extensions)
|
||||
if !securityScheme.Type.IsEmpty() {
|
||||
s.Type = securityScheme.Type.Value
|
||||
}
|
||||
if !securityScheme.Description.IsEmpty() {
|
||||
s.Description = securityScheme.Description.Value
|
||||
}
|
||||
if !securityScheme.Name.IsEmpty() {
|
||||
s.Name = securityScheme.Name.Value
|
||||
}
|
||||
if !securityScheme.In.IsEmpty() {
|
||||
s.In = securityScheme.In.Value
|
||||
}
|
||||
if !securityScheme.Flow.IsEmpty() {
|
||||
s.Flow = securityScheme.Flow.Value
|
||||
}
|
||||
if !securityScheme.AuthorizationUrl.IsEmpty() {
|
||||
s.AuthorizationUrl = securityScheme.AuthorizationUrl.Value
|
||||
}
|
||||
if !securityScheme.TokenUrl.IsEmpty() {
|
||||
s.TokenUrl = securityScheme.TokenUrl.Value
|
||||
}
|
||||
if !securityScheme.Scopes.IsEmpty() {
|
||||
s.Scopes = NewScopes(securityScheme.Scopes.Value)
|
||||
}
|
||||
return s
|
||||
}
|
||||
@@ -3,5 +3,93 @@
|
||||
|
||||
package v2
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/high/base"
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/2.0"
|
||||
)
|
||||
|
||||
type Swagger struct {
|
||||
Swagger string
|
||||
Info *base.Info
|
||||
Host string
|
||||
BasePath string
|
||||
Schemes []string
|
||||
Consumes []string
|
||||
Produces []string
|
||||
Paths *Paths
|
||||
Definitions *Definitions
|
||||
Parameters *ParameterDefinitions
|
||||
Responses *ResponsesDefinitions
|
||||
SecurityDefinitions *SecurityDefinitions
|
||||
Security []*SecurityRequirement
|
||||
Tags []*base.Tag
|
||||
ExternalDocs *base.ExternalDoc
|
||||
Extensions map[string]any
|
||||
low *low.Swagger
|
||||
}
|
||||
|
||||
func NewSwaggerDocument(document *low.Swagger) *Swagger {
|
||||
d := new(Swagger)
|
||||
d.low = document
|
||||
if !document.Info.IsEmpty() {
|
||||
d.Info = base.NewInfo(document.Info.Value)
|
||||
}
|
||||
if !document.Swagger.IsEmpty() {
|
||||
d.Swagger = document.Swagger.Value
|
||||
}
|
||||
if !document.Host.IsEmpty() {
|
||||
d.Host = document.Host.Value
|
||||
}
|
||||
if !document.BasePath.IsEmpty() {
|
||||
d.BasePath = document.BasePath.Value
|
||||
}
|
||||
|
||||
if !document.Schemes.IsEmpty() {
|
||||
var schemes []string
|
||||
for s := range document.Schemes.Value {
|
||||
schemes = append(schemes, document.Schemes.Value[s].Value)
|
||||
}
|
||||
d.Schemes = schemes
|
||||
}
|
||||
if !document.Consumes.IsEmpty() {
|
||||
var consumes []string
|
||||
for c := range document.Consumes.Value {
|
||||
consumes = append(consumes, document.Consumes.Value[c].Value)
|
||||
}
|
||||
d.Consumes = consumes
|
||||
}
|
||||
if !document.Produces.IsEmpty() {
|
||||
var produces []string
|
||||
for p := range document.Produces.Value {
|
||||
produces = append(produces, document.Produces.Value[p].Value)
|
||||
}
|
||||
d.Produces = produces
|
||||
}
|
||||
// TODO: Paths
|
||||
|
||||
if !document.SecurityDefinitions.IsEmpty() {
|
||||
d.SecurityDefinitions = NewSecurityDefinitions(document.SecurityDefinitions.Value)
|
||||
}
|
||||
|
||||
if !document.Security.IsEmpty() {
|
||||
var security []*SecurityRequirement
|
||||
for s := range document.Security.Value {
|
||||
security = append(security, NewSecurityRequirement(document.Security.Value[s].Value))
|
||||
}
|
||||
d.Security = security
|
||||
}
|
||||
|
||||
if !document.Tags.IsEmpty() {
|
||||
var tags []*base.Tag
|
||||
for t := range document.Tags.Value {
|
||||
tags = append(tags, base.NewTag(document.Tags.Value[t].Value))
|
||||
}
|
||||
d.Tags = tags
|
||||
}
|
||||
|
||||
if !document.ExternalDocs.IsEmpty() {
|
||||
d.ExternalDocs = base.NewExternalDoc(document.ExternalDocs.Value)
|
||||
}
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package v3
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/high"
|
||||
highbase "github.com/pb33f/libopenapi/datamodel/high/base"
|
||||
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/3.0"
|
||||
"github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
@@ -22,10 +23,10 @@ const (
|
||||
)
|
||||
|
||||
type Components struct {
|
||||
Schemas map[string]*SchemaProxy
|
||||
Schemas map[string]*highbase.SchemaProxy
|
||||
Responses map[string]*Response
|
||||
Parameters map[string]*Parameter
|
||||
Examples map[string]*Example
|
||||
Examples map[string]*highbase.Example
|
||||
RequestBodies map[string]*RequestBody
|
||||
Headers map[string]*Header
|
||||
SecuritySchemes map[string]*SecurityScheme
|
||||
@@ -45,17 +46,17 @@ func NewComponents(comp *low.Components) *Components {
|
||||
linkMap := make(map[string]*Link)
|
||||
responseMap := make(map[string]*Response)
|
||||
parameterMap := make(map[string]*Parameter)
|
||||
exampleMap := make(map[string]*Example)
|
||||
exampleMap := make(map[string]*highbase.Example)
|
||||
requestBodyMap := make(map[string]*RequestBody)
|
||||
headerMap := make(map[string]*Header)
|
||||
securitySchemeMap := make(map[string]*SecurityScheme)
|
||||
schemas := make(map[string]*SchemaProxy)
|
||||
schemaChan := make(chan componentResult[*SchemaProxy])
|
||||
schemas := make(map[string]*highbase.SchemaProxy)
|
||||
schemaChan := make(chan componentResult[*highbase.SchemaProxy])
|
||||
cbChan := make(chan componentResult[*Callback])
|
||||
linkChan := make(chan componentResult[*Link])
|
||||
responseChan := make(chan componentResult[*Response])
|
||||
paramChan := make(chan componentResult[*Parameter])
|
||||
exampleChan := make(chan componentResult[*Example])
|
||||
exampleChan := make(chan componentResult[*highbase.Example])
|
||||
requestBodyChan := make(chan componentResult[*RequestBody])
|
||||
headerChan := make(chan componentResult[*Header])
|
||||
securitySchemeChan := make(chan componentResult[*SecurityScheme])
|
||||
@@ -74,7 +75,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, *base.Example](parameters, k.Value, v.Value, exampleChan, NewExample)
|
||||
go buildComponent[*highbase.Example, *base.Example](parameters, k.Value, v.Value, exampleChan, highbase.NewExample)
|
||||
}
|
||||
for k, v := range comp.RequestBodies.Value {
|
||||
go buildComponent[*RequestBody, *low.RequestBody](requestBodies, k.Value, v.Value,
|
||||
@@ -149,13 +150,13 @@ 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[*base.SchemaProxy], c chan componentResult[*SchemaProxy]) {
|
||||
var sch *SchemaProxy
|
||||
sch = &SchemaProxy{schema: &lowmodel.NodeReference[*base.SchemaProxy]{
|
||||
func buildSchema(key lowmodel.KeyReference[string], orig lowmodel.ValueReference[*base.SchemaProxy], c chan componentResult[*highbase.SchemaProxy]) {
|
||||
var sch *highbase.SchemaProxy
|
||||
sch = highbase.NewSchemaProxy(&lowmodel.NodeReference[*base.SchemaProxy]{
|
||||
Value: orig.Value,
|
||||
ValueNode: orig.ValueNode,
|
||||
}}
|
||||
c <- componentResult[*SchemaProxy]{res: sch, key: key.Value}
|
||||
})
|
||||
c <- componentResult[*highbase.SchemaProxy]{res: sch, key: key.Value}
|
||||
}
|
||||
|
||||
func (c *Components) GoLow() *low.Components {
|
||||
|
||||
@@ -5,19 +5,20 @@ package v3
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/high"
|
||||
"github.com/pb33f/libopenapi/datamodel/high/base"
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/3.0"
|
||||
"github.com/pb33f/libopenapi/index"
|
||||
)
|
||||
|
||||
type Document struct {
|
||||
Version string
|
||||
Info *Info
|
||||
Info *base.Info
|
||||
Servers []*Server
|
||||
Paths *Paths
|
||||
Components *Components
|
||||
Security *SecurityRequirement
|
||||
Tags []*Tag
|
||||
ExternalDocs *ExternalDoc
|
||||
Tags []*base.Tag
|
||||
ExternalDocs *base.ExternalDoc
|
||||
Extensions map[string]any
|
||||
Index *index.SpecIndex
|
||||
low *low.Document
|
||||
@@ -27,7 +28,7 @@ func NewDocument(document *low.Document) *Document {
|
||||
d := new(Document)
|
||||
d.low = document
|
||||
if !document.Info.IsEmpty() {
|
||||
d.Info = NewInfo(document.Info.Value)
|
||||
d.Info = base.NewInfo(document.Info.Value)
|
||||
}
|
||||
if !document.Version.IsEmpty() {
|
||||
d.Version = document.Version.Value
|
||||
@@ -37,13 +38,13 @@ func NewDocument(document *low.Document) *Document {
|
||||
servers = append(servers, NewServer(ser.Value))
|
||||
}
|
||||
d.Servers = servers
|
||||
var tags []*Tag
|
||||
var tags []*base.Tag
|
||||
for _, tag := range document.Tags.Value {
|
||||
tags = append(tags, NewTag(tag.Value))
|
||||
tags = append(tags, base.NewTag(tag.Value))
|
||||
}
|
||||
d.Tags = tags
|
||||
if !document.ExternalDocs.IsEmpty() {
|
||||
d.ExternalDocs = NewExternalDoc(document.ExternalDocs.Value)
|
||||
d.ExternalDocs = base.NewExternalDoc(document.ExternalDocs.Value)
|
||||
}
|
||||
if len(document.Extensions) > 0 {
|
||||
d.Extensions = high.ExtractExtensions(document.Extensions)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
highbase "github.com/pb33f/libopenapi/datamodel/high/base"
|
||||
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/3.0"
|
||||
"github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
@@ -17,9 +18,9 @@ type Header struct {
|
||||
Style string
|
||||
Explode bool
|
||||
AllowReserved bool
|
||||
Schema *SchemaProxy
|
||||
Schema *highbase.SchemaProxy
|
||||
Example any
|
||||
Examples map[string]*Example
|
||||
Examples map[string]*highbase.Example
|
||||
Content map[string]*MediaType
|
||||
Extensions map[string]any
|
||||
low *low.Header
|
||||
@@ -36,15 +37,15 @@ 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[*base.SchemaProxy]{
|
||||
h.Schema = highbase.NewSchemaProxy(&lowmodel.NodeReference[*base.SchemaProxy]{
|
||||
Value: header.Schema.Value,
|
||||
KeyNode: header.Schema.KeyNode,
|
||||
ValueNode: header.Schema.ValueNode,
|
||||
}}
|
||||
})
|
||||
}
|
||||
h.Content = ExtractContent(header.Content.Value)
|
||||
h.Example = header.Example.Value
|
||||
h.Examples = ExtractExamples(header.Examples.Value)
|
||||
h.Examples = highbase.ExtractExamples(header.Examples.Value)
|
||||
return h
|
||||
}
|
||||
|
||||
|
||||
@@ -5,15 +5,16 @@ package v3
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/high"
|
||||
"github.com/pb33f/libopenapi/datamodel/high/base"
|
||||
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/3.0"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type MediaType struct {
|
||||
Schema *SchemaProxy
|
||||
Schema *base.SchemaProxy
|
||||
Example any
|
||||
Examples map[string]*Example
|
||||
Examples map[string]*base.Example
|
||||
Encoding map[string]*Encoding
|
||||
Extensions map[string]any
|
||||
low *low.MediaType
|
||||
@@ -23,10 +24,10 @@ func NewMediaType(mediaType *low.MediaType) *MediaType {
|
||||
m := new(MediaType)
|
||||
m.low = mediaType
|
||||
if !mediaType.Schema.IsEmpty() {
|
||||
m.Schema = &SchemaProxy{schema: &mediaType.Schema}
|
||||
m.Schema = base.NewSchemaProxy(&mediaType.Schema)
|
||||
}
|
||||
m.Example = mediaType.Example
|
||||
m.Examples = ExtractExamples(mediaType.Examples.Value)
|
||||
m.Examples = base.ExtractExamples(mediaType.Examples.Value)
|
||||
m.Extensions = high.ExtractExtensions(mediaType.Extensions)
|
||||
m.Encoding = ExtractEncoding(mediaType.Encoding.Value)
|
||||
return m
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/high/base"
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/3.0"
|
||||
)
|
||||
|
||||
@@ -11,7 +12,7 @@ type Operation struct {
|
||||
Tags []string
|
||||
Summary string
|
||||
Description string
|
||||
ExternalDocs *ExternalDoc
|
||||
ExternalDocs *base.ExternalDoc
|
||||
OperationId string
|
||||
Parameters []*Parameter
|
||||
RequestBody *RequestBody
|
||||
@@ -37,7 +38,7 @@ func NewOperation(operation *low.Operation) *Operation {
|
||||
o.Summary = operation.Summary.Value
|
||||
o.Description = operation.Description.Value
|
||||
if !operation.ExternalDocs.IsEmpty() {
|
||||
o.ExternalDocs = NewExternalDoc(operation.ExternalDocs.Value)
|
||||
o.ExternalDocs = base.NewExternalDoc(operation.ExternalDocs.Value)
|
||||
}
|
||||
o.OperationId = operation.OperationId.Value
|
||||
if !operation.Parameters.IsEmpty() {
|
||||
|
||||
@@ -5,6 +5,7 @@ package v3
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/high"
|
||||
"github.com/pb33f/libopenapi/datamodel/high/base"
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/3.0"
|
||||
)
|
||||
|
||||
@@ -18,9 +19,9 @@ type Parameter struct {
|
||||
Style string
|
||||
Explode bool
|
||||
AllowReserved bool
|
||||
Schema *SchemaProxy
|
||||
Schema *base.SchemaProxy
|
||||
Example any
|
||||
Examples map[string]*Example
|
||||
Examples map[string]*base.Example
|
||||
Content map[string]*MediaType
|
||||
Extensions map[string]any
|
||||
low *low.Parameter
|
||||
@@ -38,11 +39,11 @@ func NewParameter(param *low.Parameter) *Parameter {
|
||||
p.Explode = param.Explode.Value
|
||||
p.AllowReserved = param.AllowReserved.Value
|
||||
if !param.Schema.IsEmpty() {
|
||||
p.Schema = &SchemaProxy{schema: ¶m.Schema}
|
||||
p.Schema = base.NewSchemaProxy(¶m.Schema)
|
||||
}
|
||||
p.Required = param.Required.Value
|
||||
p.Example = param.Example.Value
|
||||
p.Examples = ExtractExamples(param.Examples.Value)
|
||||
p.Examples = base.ExtractExamples(param.Examples.Value)
|
||||
p.Content = ExtractContent(param.Content.Value)
|
||||
p.Extensions = high.ExtractExtensions(param.Extensions)
|
||||
return p
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v3
|
||||
package base
|
||||
|
||||
import (
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v3
|
||||
package base
|
||||
|
||||
import (
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
@@ -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/high"
|
||||
@@ -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/high"
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v3
|
||||
package base
|
||||
|
||||
import (
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v3
|
||||
package base
|
||||
|
||||
import (
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
@@ -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/high"
|
||||
@@ -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"
|
||||
@@ -13,6 +13,10 @@ type SchemaProxy struct {
|
||||
buildError error
|
||||
}
|
||||
|
||||
func NewSchemaProxy(schema *low.NodeReference[*v3.SchemaProxy]) *SchemaProxy {
|
||||
return &SchemaProxy{schema: schema}
|
||||
}
|
||||
|
||||
func (sp *SchemaProxy) Schema() *Schema {
|
||||
s := sp.schema.Value.Schema()
|
||||
if s == nil {
|
||||
@@ -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"
|
||||
@@ -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/high"
|
||||
@@ -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/high"
|
||||
@@ -6,7 +6,6 @@ package base
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/low"
|
||||
"github.com/pb33f/libopenapi/index"
|
||||
"go.uber.org/zap"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -32,10 +31,10 @@ func (sp *SchemaProxy) Schema() *Schema {
|
||||
_ = low.BuildModel(sp.vn, schema)
|
||||
err := schema.Build(sp.vn, sp.idx)
|
||||
if err != nil {
|
||||
low.Log.Error("unable to build schema",
|
||||
zap.Int("line", sp.vn.Line),
|
||||
zap.Int("column", sp.vn.Column),
|
||||
zap.String("error", err.Error()))
|
||||
//low.Log.Error("unable to build schema",
|
||||
// zap.Int("line", sp.vn.Line),
|
||||
// zap.Int("column", sp.vn.Column),
|
||||
// zap.String("error", err.Error()))
|
||||
sp.buildError = err
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/pb33f/libopenapi/index"
|
||||
"github.com/pb33f/libopenapi/utils"
|
||||
"github.com/vmware-labs/yaml-jsonpath/pkg/yamlpath"
|
||||
"go.uber.org/zap"
|
||||
"gopkg.in/yaml.v3"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -73,12 +72,12 @@ func LocateRefNode(root *yaml.Node, idx *index.SpecIndex) (*yaml.Node, error) {
|
||||
if !IsCircular(found[rv].Node, idx) {
|
||||
return LocateRefNode(found[rv].Node, idx)
|
||||
} else {
|
||||
Log.Error("circular reference found during lookup, and will remain un-resolved.",
|
||||
zap.Int("line", found[rv].Node.Line),
|
||||
zap.Int("column", found[rv].Node.Column),
|
||||
zap.String("reference", found[rv].Definition),
|
||||
zap.String("journey",
|
||||
GetCircularReferenceResult(found[rv].Node, idx).GenerateJourneyPath()))
|
||||
//Log.Error("circular reference found during lookup, and will remain un-resolved.",
|
||||
// zap.Int("line", found[rv].Node.Line),
|
||||
// zap.Int("column", found[rv].Node.Column),
|
||||
// zap.String("reference", found[rv].Definition),
|
||||
// zap.String("journey",
|
||||
// GetCircularReferenceResult(found[rv].Node, idx).GenerateJourneyPath()))
|
||||
|
||||
return found[rv].Node, fmt.Errorf("circular reference '%s' found during lookup at line %d, column %d, "+
|
||||
"It cannot be resolved",
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
package low
|
||||
|
||||
import "go.uber.org/zap"
|
||||
|
||||
var Log *zap.Logger
|
||||
|
||||
func init() {
|
||||
Log, _ = zap.NewProduction()
|
||||
}
|
||||
//import "go.uber.org/zap"
|
||||
//
|
||||
//var Log *zap.Logger
|
||||
//
|
||||
//func init() {
|
||||
// Log, _ = zap.NewProduction()
|
||||
//}
|
||||
|
||||
28
document.go
Normal file
28
document.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel"
|
||||
v2high "github.com/pb33f/libopenapi/datamodel/high/2.0"
|
||||
v3high "github.com/pb33f/libopenapi/datamodel/high/3.0"
|
||||
)
|
||||
|
||||
type Document[T any] struct {
|
||||
version string
|
||||
info *datamodel.SpecInfo
|
||||
Model T
|
||||
}
|
||||
|
||||
func (d *Document[T]) GetVersion() string {
|
||||
return d.version
|
||||
}
|
||||
|
||||
func (d *Document[T]) BuildV2Document() (*v2high.Swagger, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (d *Document[T]) BuildV3Document() (*v3high.Document, error) {
|
||||
return nil, nil
|
||||
}
|
||||
26
document_test.go
Normal file
26
document_test.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadDocument_Simple(t *testing.T) {
|
||||
//
|
||||
//yml := `openapi: 3.0.1`
|
||||
//doc, err := LoadDocument([]byte(yml))
|
||||
//assert.NoError(t, err)
|
||||
//assert.Equal(t, "3.0.1", doc.GetVersion())
|
||||
|
||||
}
|
||||
|
||||
func TestLoadDocument_WithInfo(t *testing.T) {
|
||||
|
||||
//yml := `openapi: 3.0.1`
|
||||
//doc, err := LoadDocument([]byte(yml))
|
||||
//assert.NoError(t, err)
|
||||
//assert.Equal(t, "3.0.1", doc.GetVersion())
|
||||
|
||||
}
|
||||
5
go.mod
5
go.mod
@@ -3,6 +3,7 @@ module github.com/pb33f/libopenapi
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/iancoleman/strcase v0.2.0
|
||||
github.com/stretchr/testify v1.8.0
|
||||
github.com/vmware-labs/yaml-jsonpath v0.3.2
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
@@ -11,9 +12,5 @@ require (
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
|
||||
github.com/iancoleman/strcase v0.2.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.8.0 // indirect
|
||||
go.uber.org/zap v1.23.0 // indirect
|
||||
)
|
||||
|
||||
@@ -21,6 +21,10 @@ parameters:
|
||||
name: simple
|
||||
type: string
|
||||
x-chicken: nuggets
|
||||
security:
|
||||
- global_auth:
|
||||
- write:pets
|
||||
- read:pets
|
||||
tags:
|
||||
- name: pet
|
||||
description: Everything about your Pets
|
||||
|
||||
Reference in New Issue
Block a user