diff --git a/public/radix_tree_address_space/address_space.go b/public/radix_tree_address_space/address_space.go index b7e4917..a2a70ed 100644 --- a/public/radix_tree_address_space/address_space.go +++ b/public/radix_tree_address_space/address_space.go @@ -24,6 +24,7 @@ const ( standardURLName = "url" standardHeadersName = "headers" standardBodyName = "body" + standardContextName = "context" standardQueryName = "query" standardPathName = "path" standardCookiesName = "cookies" @@ -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" @@ -88,6 +90,7 @@ type standardAddressSpaceGrammar struct { responseBodyPrefix string urlQueryPrefix string requestHeaderPrefix string + requestContextPrefix string responseHeaderPrefix string urlPathPrefix string } @@ -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), @@ -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 @@ -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: @@ -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 } @@ -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: @@ -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( diff --git a/public/radix_tree_address_space/address_space_test.go b/public/radix_tree_address_space/address_space_test.go index df1770b..b9ad6ba 100644 --- a/public/radix_tree_address_space/address_space_test.go +++ b/public/radix_tree_address_space/address_space_test.go @@ -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, ) @@ -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'") diff --git a/public/radix_tree_address_space/testdata/registry/basic/src/googleapis.com/v0.1.2/services-split/compute/compute-v1.yaml b/public/radix_tree_address_space/testdata/registry/basic/src/googleapis.com/v0.1.2/services-split/compute/compute-v1.yaml index a691381..91e5bb1 100644 --- a/public/radix_tree_address_space/testdata/registry/basic/src/googleapis.com/v0.1.2/services-split/compute/compute-v1.yaml +++ b/public/radix_tree_address_space/testdata/registry/basic/src/googleapis.com/v0.1.2/services-split/compute/compute-v1.yaml @@ -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