Skip to content

Commit 3f8686c

Browse files
- Namespace query basics.
1 parent 5e6b8a9 commit 3f8686c

File tree

4 files changed

+83
-43
lines changed

4 files changed

+83
-43
lines changed

anysdk/operation_store.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ type StandardOperationStore interface {
141141
getRequestBodyAttributeParentKey(string) (string, bool)
142142
getRequestBodyTranslateAlgorithmString() string
143143
getRequestBodyStringifiedPaths() (map[string]struct{}, error)
144+
GetRequestBodyMediaType() string
144145
getRequestBodyMediaType() string
145146
getRequestBodyMediaTypeNormalised() string
146147
getXMLDeclaration() string
@@ -242,6 +243,10 @@ func NewEmptyOperationStore() StandardOperationStore {
242243
}
243244
}
244245

246+
func (op *standardOpenAPIOperationStore) GetRequestBodyMediaType() string {
247+
return op.getRequestBodyMediaType()
248+
}
249+
245250
func (op *standardOpenAPIOperationStore) getRequestBodyMediaType() string {
246251
if op.Request != nil {
247252
return op.Request.BodyMediaType

public/discovery/static_analyzer.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ var (
1818
_ StaticAnalyzer = &genericStaticAnalyzer{}
1919
_ StaticAnalyzer = &serviceLevelStaticAnalyzer{}
2020
_ ProviderServiceResourceAnalyzer = &standardProviderServiceResourceAnalyzer{}
21-
_ persistence.PersistenceSystem = &aotPersistenceSystem{}
2221
)
2322

2423
type AnalyzerCfg interface {
@@ -816,31 +815,3 @@ func (osa *serviceLevelStaticAnalyzer) GetWarnings() []string {
816815
func (osa *serviceLevelStaticAnalyzer) GetAffirmatives() []string {
817816
return osa.affirmatives
818817
}
819-
820-
type aotPersistenceSystem struct {
821-
systemName string
822-
}
823-
824-
func (aps *aotPersistenceSystem) GetSystemName() string {
825-
return aps.systemName
826-
}
827-
828-
func (aps *aotPersistenceSystem) HandleExternalTables(providerName string, externalTables map[string]anysdk.SQLExternalTable) error {
829-
// Implement logic to handle external tables
830-
return nil
831-
}
832-
833-
func (aps *aotPersistenceSystem) HandleViewCollection(viewCollection []anysdk.View) error {
834-
// Implement logic to handle view collection
835-
return nil
836-
}
837-
838-
func (aps *aotPersistenceSystem) CacheStoreGet(key string) ([]byte, error) {
839-
// Implement logic to get data from cache store
840-
return nil, nil
841-
}
842-
843-
func (aps *aotPersistenceSystem) CacheStorePut(key string, value []byte, expiration string, ttl int) error {
844-
// Implement logic to put data into cache store
845-
return nil
846-
}

public/radix_tree_address_space/address_space.go

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package radix_tree_address_space
22

33
import (
44
"fmt"
5+
"net/http"
56
"strings"
67

78
"github.com/getkin/kin-openapi/openapi3"
@@ -80,15 +81,58 @@ type AddressSpace interface {
8081
GetSimpleSelectKey() string
8182
GetSimpleSelectSchema() anysdk.Schema
8283
GetUnionSelectSchemas() map[string]anysdk.Schema
84+
DereferenceAddress(address string) (any, bool)
8385
}
8486

8587
type standardNamespace struct {
86-
serverVars map[string]string
87-
requestBodyParams map[string]anysdk.Addressable
88-
server *openapi3.Server
89-
simpleSelectKey string
90-
simpleSelectSchema anysdk.Schema
91-
unionSelectSchemas map[string]anysdk.Schema
88+
serverVars map[string]string
89+
requestBodyParams map[string]anysdk.Addressable
90+
server *openapi3.Server
91+
simpleSelectKey string
92+
simpleSelectSchema anysdk.Schema
93+
responseBodySchema anysdk.Schema
94+
requestBodySchema anysdk.Schema
95+
responseBodyMediaType string
96+
requestBodyMediaType string
97+
pathString string
98+
serverUrlString string
99+
request *http.Request
100+
response *http.Response
101+
unionSelectSchemas map[string]anysdk.Schema
102+
}
103+
104+
func (ns *standardNamespace) DereferenceAddress(address string) (any, bool) {
105+
parts := strings.Split(address, ".")
106+
if len(parts) == 0 {
107+
return nil, false
108+
}
109+
if parts[0] == standardRequestName {
110+
if len(parts) < 2 {
111+
return nil, false
112+
}
113+
switch parts[1] {
114+
case standardBodyName:
115+
return ns.requestBodySchema, true
116+
case standardHeadersName:
117+
return ns.request.Header, true
118+
default:
119+
return nil, false
120+
}
121+
}
122+
if parts[0] == standardResponseName {
123+
if len(parts) < 2 {
124+
return nil, false
125+
}
126+
switch parts[1] {
127+
case standardHeadersName:
128+
return ns.server.Variables, true
129+
case standardBodyName:
130+
return ns.responseBodySchema, true
131+
default:
132+
return nil, false
133+
}
134+
}
135+
return nil, false
92136
}
93137

94138
func (ns *standardNamespace) GetServer() *openapi3.Server {
@@ -144,10 +188,11 @@ func (asa *standardAddressSpaceAnalyzer) Analyze() error {
144188
for k, v := range firstServer.Variables {
145189
serverVars[k] = v.Default
146190
}
147-
reequestBodySchema, requestBodySchemaErr := asa.method.GetRequestBodySchema()
191+
requestBodySchema, requestBodySchemaErr := asa.method.GetRequestBodySchema()
192+
requestBodyMediaType := asa.method.GetRequestBodyMediaType()
148193
requestBodyParams := map[string]anysdk.Addressable{}
149194
var err error
150-
if reequestBodySchema != nil && requestBodySchemaErr == nil {
195+
if requestBodySchema != nil && requestBodySchemaErr == nil {
151196
requestBodyParams, err = asa.method.GetRequestBodyAttributesNoRename()
152197
if err != nil {
153198
return err
@@ -176,13 +221,18 @@ func (asa *standardAddressSpaceAnalyzer) Analyze() error {
176221
}
177222
unionSelectSchemas[k] = schema
178223
}
224+
responseSchema, responseMediaType, _ := asa.method.GetResponseBodySchemaAndMediaType()
179225
addressSpace := &standardNamespace{
180-
server: firstServer,
181-
serverVars: serverVars,
182-
requestBodyParams: requestBodyParams,
183-
simpleSelectKey: simpleSelectKey,
184-
simpleSelectSchema: simpleSelectSchema,
185-
unionSelectSchemas: unionSelectSchemas,
226+
server: firstServer,
227+
serverVars: serverVars,
228+
requestBodyParams: requestBodyParams,
229+
simpleSelectKey: simpleSelectKey,
230+
simpleSelectSchema: simpleSelectSchema,
231+
unionSelectSchemas: unionSelectSchemas,
232+
responseBodySchema: responseSchema,
233+
requestBodySchema: requestBodySchema,
234+
responseBodyMediaType: responseMediaType,
235+
requestBodyMediaType: requestBodyMediaType,
186236
}
187237
if addressSpace == nil {
188238
return fmt.Errorf("failed to create address space for operation %s", asa.method.GetName())

public/radix_tree_address_space/address_space_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,20 @@ func TestDeepDiscoveryGoogleCurrent(t *testing.T) {
129129
for k, v := range unionSelectSchemas {
130130
t.Logf("Union select schema key: %s, schema title: %s", k, v.GetTitle())
131131
}
132+
requestBody, requestBodyOk := addressSpace.DereferenceAddress("request.body")
133+
if !requestBodyOk {
134+
t.Fatalf("Address space analysis failed: expected to dereference 'request.body'")
135+
}
136+
if requestBody != nil {
137+
t.Fatalf("Address space analysis failed: expected nil 'request.body'")
138+
}
139+
responseBody, responseBodyOk := addressSpace.DereferenceAddress("response.body")
140+
if !responseBodyOk {
141+
t.Fatalf("Address space analysis failed: expected to dereference 'response.body'")
142+
}
143+
if responseBody == nil {
144+
t.Fatalf("Address space analysis failed: expected non-nil 'response.body'")
145+
}
132146
}
133147

134148
func TestDeepDiscoveryAWSCurrent(t *testing.T) {

0 commit comments

Comments
 (0)