From e8bb52bf3dff2a7e5dac28249d85c30b07f57c11 Mon Sep 17 00:00:00 2001 From: Dave Shanley Date: Sat, 6 Aug 2022 18:40:23 -0400 Subject: [PATCH] Starting work on oAuth Flows. --- datamodel/low/3.0/link.go | 4 +++ datamodel/low/3.0/oauth_flows.go | 44 +++++++++++++++++++--------- datamodel/low/3.0/security_scheme.go | 35 +++++++++++++--------- openapi/create_document_test.go | 6 ++++ 4 files changed, 61 insertions(+), 28 deletions(-) diff --git a/datamodel/low/3.0/link.go b/datamodel/low/3.0/link.go index 8b7c132..362b9e2 100644 --- a/datamodel/low/3.0/link.go +++ b/datamodel/low/3.0/link.go @@ -16,6 +16,10 @@ type Link struct { Extensions map[low.KeyReference[string]]low.ValueReference[any] } +func (l *Link) FindParameter(pName string) *low.ValueReference[string] { + return FindItemInMap[string](pName, l.Parameters.Value) +} + func (l *Link) Build(root *yaml.Node) error { extensionMap, err := ExtractExtensions(root) if err != nil { diff --git a/datamodel/low/3.0/oauth_flows.go b/datamodel/low/3.0/oauth_flows.go index 4ac8b88..84fa856 100644 --- a/datamodel/low/3.0/oauth_flows.go +++ b/datamodel/low/3.0/oauth_flows.go @@ -1,24 +1,40 @@ package v3 import ( - "github.com/pb33f/libopenapi/datamodel/low" - "gopkg.in/yaml.v3" + "github.com/pb33f/libopenapi/datamodel/low" + "gopkg.in/yaml.v3" ) type OAuthFlows struct { - Node *yaml.Node - Implicit OAuthFlow - Password OAuthFlow - ClientCredentials OAuthFlow - AuthorizationCode OAuthFlow - Extensions map[string]low.ObjectReference + Implicit low.NodeReference[*OAuthFlow] + Password low.NodeReference[*OAuthFlow] + ClientCredentials low.NodeReference[*OAuthFlow] + AuthorizationCode low.NodeReference[*OAuthFlow] + Extensions map[low.KeyReference[string]]low.ValueReference[any] +} + +func (o *OAuthFlows) Build(root *yaml.Node) error { + extensionMap, err := ExtractExtensions(root) + if err != nil { + return err + } + o.Extensions = extensionMap + return nil } type OAuthFlow struct { - Node *yaml.Node - AuthorizationUrl low.NodeReference[string] - TokenURL low.NodeReference[string] - RefreshURL low.NodeReference[string] - Scopes map[string]string - Extensions map[string]low.ObjectReference + AuthorizationUrl low.NodeReference[string] + TokenURL low.NodeReference[string] + RefreshURL low.NodeReference[string] + Scopes map[low.KeyReference[string]]low.ValueReference[string] + Extensions map[low.KeyReference[string]]low.ValueReference[any] +} + +func (o *OAuthFlow) Build(root *yaml.Node) error { + extensionMap, err := ExtractExtensions(root) + if err != nil { + return err + } + o.Extensions = extensionMap + return nil } diff --git a/datamodel/low/3.0/security_scheme.go b/datamodel/low/3.0/security_scheme.go index 7cfac32..bf75231 100644 --- a/datamodel/low/3.0/security_scheme.go +++ b/datamodel/low/3.0/security_scheme.go @@ -1,24 +1,31 @@ package v3 import ( - "github.com/pb33f/libopenapi/datamodel/low" - "gopkg.in/yaml.v3" + "github.com/pb33f/libopenapi/datamodel/low" + "gopkg.in/yaml.v3" ) type SecurityScheme struct { - Node *yaml.Node - Type low.NodeReference[string] - Description low.NodeReference[string] - Name low.NodeReference[string] - In low.NodeReference[string] - Scheme low.NodeReference[string] - BearerFormat low.NodeReference[string] - Flows OAuthFlows - OpenIdConnectURL low.NodeReference[string] - Extensions map[string]low.ObjectReference + Type low.NodeReference[string] + Description low.NodeReference[string] + Name low.NodeReference[string] + In low.NodeReference[string] + Scheme low.NodeReference[string] + BearerFormat low.NodeReference[string] + Flows low.NodeReference[*OAuthFlows] + OpenIdConnectURL low.NodeReference[string] + Extensions map[low.KeyReference[string]]low.ValueReference[any] +} + +func (ss *SecurityScheme) Build(root *yaml.Node) error { + extensionMap, err := ExtractExtensions(root) + if err != nil { + return err + } + ss.Extensions = extensionMap + return nil } type SecurityRequirement struct { - Node *yaml.Node - Value []low.NodeReference[string] + Value low.NodeReference[[]low.ValueReference[string]] } diff --git a/openapi/create_document_test.go b/openapi/create_document_test.go index 8967471..b91afe4 100644 --- a/openapi/create_document_test.go +++ b/openapi/create_document_test.go @@ -214,4 +214,10 @@ func TestCreateDocument_Paths(t *testing.T) { assert.Len(t, links.Value, 2) assert.Equal(t, "locateBurger", okCode.Value.FindLink("LocateBurger").Value.OperationId.Value) + locateBurger := okCode.Value.FindLink("LocateBurger").Value + + burgerIdParam := locateBurger.FindParameter("burgerId") + assert.NotNil(t, burgerIdParam) + assert.Equal(t, "$response.body#/id", burgerIdParam.Value) + }