Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions public/radix_tree_address_space/address_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
standardURLName = "url"
standardHeadersName = "headers"
standardBodyName = "body"
standardContextName = "context"
standardQueryName = "query"
standardPathName = "path"
standardCookiesName = "cookies"
Expand All @@ -32,6 +33,7 @@ const (
// path types
pathTypeRequestBody pathType = "request_body"
pathTypeResponseBody pathType = "response_body"
pathTypeRequestContext pathType = "request_context"
pathTypeURLQuery pathType = "url_query"
pathTypeURLPath pathType = "url_path"
pathTypeRequestHeader pathType = "request_header"
Expand Down Expand Up @@ -88,6 +90,7 @@ type standardAddressSpaceGrammar struct {
responseBodyPrefix string
urlQueryPrefix string
requestHeaderPrefix string
requestContextPrefix string
responseHeaderPrefix string
urlPathPrefix string
}
Expand All @@ -104,6 +107,7 @@ func newStandardAddressSpaceGrammar() AddressSpaceGrammar {
cookiesName: standardCookiesName,
postTransformPrefix: standardPostTransformPrefix,
serverName: standardServerName,
requestContextPrefix: fmt.Sprintf("%s.%s.", standardRequestName, standardContextName),
requestBodyPrefix: fmt.Sprintf("%s.%s.", standardRequestName, standardBodyName),
responseBodyPrefix: fmt.Sprintf("%s.%s.", standardResponseName, standardBodyName),
urlQueryPrefix: fmt.Sprintf("%s.%s.", standardRequestName, standardQueryName),
Expand All @@ -120,6 +124,11 @@ func (sg *standardAddressSpaceGrammar) extractRequestBodySubPath(fullPath string
return "", false
}

func (sg *standardAddressSpaceGrammar) extractRequestContextSubPath(fullPath string) (string, bool) {
rv := strings.TrimPrefix(fullPath, sg.requestContextPrefix)
return rv, rv != fullPath
}

func (sg *standardAddressSpaceGrammar) extractResponseBodySubPath(fullPath string) (string, bool) {
rv := strings.TrimPrefix(fullPath, sg.responseBodyPrefix)
return rv, rv != fullPath
Expand All @@ -144,6 +153,8 @@ func (sg *standardAddressSpaceGrammar) ExtractSubPath(fullPath string, pathType
switch pathType {
case pathTypeRequestBody:
return sg.extractRequestBodySubPath(fullPath)
case pathTypeRequestContext:
return sg.extractRequestContextSubPath(fullPath)
case pathTypeResponseBody:
return sg.extractResponseBodySubPath(fullPath)
case pathTypeURLQuery:
Expand Down Expand Up @@ -527,6 +538,18 @@ func (ns *standardNamespace) DereferenceAddress(address string) (any, bool) {
return ns.requestBodySchema, true
case standardHeadersName:
return ns.request.Header, true
case standardContextName:
if len(parts) < 3 {
return nil, false
}
if ns.method == nil {
return nil, false
}
rv, ok := ns.method.GetParameter(parts[2])
if !ok || rv.GetLocation() != anysdk.LocationContext {
return nil, false
}
return rv, true
default:
return nil, false
}
Expand Down Expand Up @@ -584,6 +607,8 @@ func (asa *standardAddressSpaceFormulator) expandParameterPaths() (map[string]st
rv[k] = fmt.Sprintf("%s.%s.%s", standardRequestName, standardCookiesName, k)
case anysdk.LocationServer:
rv[k] = fmt.Sprintf("%s.%s", "server", k)
case anysdk.LocationContext:
rv[k] = fmt.Sprintf("%s.%s.%s", standardRequestName, standardContextName, k)
// case anysdk.LocationRequestBody:
// rv[k] = fmt.Sprintf("%s.%s.%s", standardRequestName, standardBodyName, k)
default:
Expand Down Expand Up @@ -631,6 +656,16 @@ func (asa *standardAddressSpaceFormulator) resolvePathsToSchemas(aliasToPathMap
rv[path] = schema
continue
}
contextKey, isContextAttribute := asa.grammar.ExtractSubPath(path, pathTypeRequestContext)
if isContextAttribute {
schema := anysdk.NewStringSchema(
nil,
contextKey,
contextKey,
)
rv[path] = schema
continue
}
requestHeaderKey, isRequestHeaderAttribute := asa.grammar.ExtractSubPath(path, pathTypeRequestHeader)
if isRequestHeaderAttribute {
schema := anysdk.NewStringSchema(
Expand Down
8 changes: 8 additions & 0 deletions public/radix_tree_address_space/address_space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ func TestAliasedAddressSpaceGoogleCurrent(t *testing.T) {
map[string]string{
"amalgam": "response.body.$.items",
"name": "response.body.$.items[*].instanceGroups[*].name",
"ctx_nop": "request.context.nop_ctx_var",
},
false,
)
Expand All @@ -342,6 +343,13 @@ func TestAliasedAddressSpaceGoogleCurrent(t *testing.T) {
if responseBody == nil {
t.Fatalf("Address space analysis failed: expected non-nil 'response.body'")
}
requestCtxVar, requestCtxVarOk := addressSpace.DereferenceAddress("request.context.nop_ctx_var")
if !requestCtxVarOk {
t.Fatalf("Address space analysis failed: expected to dereference 'request.context.nop_ctx_var'")
}
if requestCtxVar == nil {
t.Fatalf("Address space analysis failed: expected non-nil 'request.context.nop_ctx_var'")
}
projectParam, projectParamOk := addressSpace.DereferenceAddress(".project")
if !projectParamOk {
t.Fatalf("Address space analysis failed: expected to dereference '.project'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29422,6 +29422,11 @@ paths:
required: true
schema:
type: string
- in: context
name: nop_ctx_var
required: false
schema:
type: string
- description: 'A filter expression that filters resources listed in the response.
The expression must specify the field name, a comparison operator, and the
value that you want to use for filtering. The value must be a string, a
Expand Down
Loading