Skip to content

Commit dc58e94

Browse files
Merge pull request #51 from stackql/feature/namespace-expansion-v3
better-analysis
2 parents 97376fb + 2d2ba4d commit dc58e94

File tree

189 files changed

+1831000
-302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+1831000
-302
lines changed

anysdk/address_space.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package anysdk
2+
3+
type AddressSpaceExpansionConfig interface {
4+
IsLegacy() bool
5+
IsAllowNilResponse() bool
6+
}
7+
8+
type AddressSpace interface {
9+
GetGlobalSelectSchemas() map[string]Schema
10+
DereferenceAddress(address string) (any, bool)
11+
WriteToAddress(address string, val any) error
12+
ReadFromAddress(address string) (any, bool)
13+
ResolveSignature(map[string]any) (bool, map[string]any)
14+
Invoke(...any) error
15+
ToMap(AddressSpaceExpansionConfig) (map[string]any, error)
16+
ToRelation(AddressSpaceExpansionConfig) (Relation, error)
17+
}

anysdk/addressable.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ func (ns *namedSchema) GetName() string {
1919
return ns.name
2020
}
2121

22+
func (ns *namedSchema) GetAlias() string {
23+
if ns.s != nil {
24+
return ns.s.GetAlias()
25+
}
26+
return ""
27+
}
28+
2229
func (ns *namedSchema) GetSchema() (Schema, bool) {
2330
return ns.s, true
2431
}
@@ -47,7 +54,7 @@ func newAddressableRequestBodyProperty(name string, s Schema, isRequired bool) A
4754
return &namedSchema{
4855
s: s,
4956
name: name,
50-
location: "requestBody",
57+
location: LocationRequestBody,
5158
isRequired: isRequired,
5259
}
5360
}
@@ -56,7 +63,7 @@ func newAddressableServerVariable(name string, s Schema, isRequired bool) Addres
5663
return &namedSchema{
5764
s: s,
5865
name: name,
59-
location: "server",
66+
location: LocationServer,
6067
isRequired: isRequired,
6168
}
6269
}
@@ -65,6 +72,7 @@ type Addressable interface {
6572
ConditionIsValid(lhs string, rhs interface{}) bool
6673
GetLocation() string
6774
GetName() string
75+
GetAlias() string
6876
GetSchema() (Schema, bool)
6977
GetType() string
7078
IsRequired() bool

anysdk/client.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -347,29 +347,6 @@ func inferMaxResultsElement(OperationStore) internaldto.HTTPElement {
347347
)
348348
}
349349

350-
func HTTPApiCallFromRequest(
351-
cc client.AnySdkClientConfigurator,
352-
runtimeCtx dto.RuntimeCtx,
353-
authCtx *dto.AuthCtx,
354-
authTypeRequested string,
355-
enforceRevokeFirst bool,
356-
outErrFile io.Writer,
357-
prov Provider,
358-
method OperationStore,
359-
request *http.Request,
360-
) (*http.Response, error) {
361-
return httpApiCallFromRequest(
362-
cc,
363-
runtimeCtx,
364-
authCtx,
365-
authTypeRequested,
366-
enforceRevokeFirst,
367-
outErrFile,
368-
method,
369-
request,
370-
)
371-
}
372-
373350
func GetMonitorRequest(urlStr string) (client.AnySdkArgList, error) {
374351
urlObj, err := url.Parse(urlStr)
375352
if err != nil {

anysdk/concerted_action.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type MethodAnalysisOutput interface {
6868
GetItemSchema() (Schema, bool)
6969
GetResponseSchema() (Schema, bool)
7070
IsNilResponseAllowed() bool
71+
IsAwait() bool
7172
}
7273

7374
type analysisOutput struct {
@@ -79,6 +80,7 @@ type analysisOutput struct {
7980
responseSchema Schema
8081
itemSchema Schema
8182
isNilResponseAllowed bool
83+
isAwait bool
8284
}
8385

8486
func (ao *analysisOutput) GetMethod() OperationStore {
@@ -93,6 +95,10 @@ func (ao *analysisOutput) GetSelectItemsKey() string {
9395
return ao.selectItemsKey
9496
}
9597

98+
func (ao *analysisOutput) IsAwait() bool {
99+
return ao.isAwait
100+
}
101+
96102
func (ao *analysisOutput) GetItemSchema() (Schema, bool) {
97103
return ao.itemSchema, ao.itemSchema != nil
98104
}
@@ -149,6 +155,7 @@ func newMethodAnalysisOutput(
149155
responseSchema Schema,
150156
itemSchema Schema,
151157
isNilResponseAllowed bool,
158+
isAwait bool,
152159
) MethodAnalysisOutput {
153160
return &analysisOutput{
154161
method: method,
@@ -159,6 +166,7 @@ func newMethodAnalysisOutput(
159166
responseSchema: responseSchema,
160167
itemSchema: itemSchema,
161168
isNilResponseAllowed: isNilResponseAllowed,
169+
isAwait: isAwait,
162170
}
163171
}
164172

@@ -239,5 +247,6 @@ func (ma *standardMethodAnalyzer) AnalyzeUnaryAction(
239247
schema,
240248
itemSchema,
241249
isNilResponseAllowed,
250+
isAwait,
242251
), nil
243252
}

anysdk/const.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,23 @@ const (
1414
SQLVerb string = "SQLVerb"
1515
)
1616

17+
const (
18+
LocationRequestBody string = "requestBody"
19+
LocationPath string = "path"
20+
LocationQuery string = "query"
21+
LocationHeader string = "header"
22+
LocationCookie string = "cookie"
23+
LocationServer string = "server"
24+
)
25+
1726
const (
1827
ExtensionKeyAlwaysRequired string = "x-alwaysRequired"
1928
ExtensionKeyGraphQL string = "x-stackQL-graphQL"
2029
ExtensionKeyConfig string = "x-stackQL-config"
2130
ExtensionKeyProvider string = "x-stackql-provider"
2231
ExtensionKeyResources string = "x-stackQL-resources"
2332
ExtensionKeyStringOnly string = "x-stackQL-stringOnly"
33+
ExtensionKeyAlias string = "x-stackQL-alias"
2434
)
2535

2636
const (

anysdk/expectedRequest.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ type ExpectedRequest interface {
2020
type standardExpectedRequest struct {
2121
BodyMediaType string `json:"mediaType,omitempty" yaml:"mediaType,omitempty"`
2222
Schema Schema
23-
Default string `json:"default,omitempty" yaml:"default,omitempty"`
24-
Base string `json:"base,omitempty" yaml:"base,omitempty"`
25-
Required []string `json:"required,omitempty" yaml:"required,omitempty"`
26-
XMLDeclaration string `json:"xmlDeclaration,omitempty" yaml:"xmlDeclaration,omitempty"`
27-
XMLTransform string `json:"xmlTransform,omitempty" yaml:"xmlTransform,omitempty"`
28-
XMLRootAnnotation string `json:"xmlRootAnnotation,omitempty" yaml:"xmlRootAnnotation,omitempty"`
23+
Default string `json:"default,omitempty" yaml:"default,omitempty"`
24+
Base string `json:"base,omitempty" yaml:"base,omitempty"`
25+
ProjectionMap map[string]string `json:"projection_map,omitempty" yaml:"projection_map,omitempty"`
26+
Required []string `json:"required,omitempty" yaml:"required,omitempty"`
27+
XMLDeclaration string `json:"xmlDeclaration,omitempty" yaml:"xmlDeclaration,omitempty"`
28+
XMLTransform string `json:"xmlTransform,omitempty" yaml:"xmlTransform,omitempty"`
29+
XMLRootAnnotation string `json:"xmlRootAnnotation,omitempty" yaml:"xmlRootAnnotation,omitempty"`
2930
}
3031

3132
func (er *standardExpectedRequest) setBodyMediaType(s string) {

anysdk/expectedResponse.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ type ExpectedResponse interface {
1010
GetOpenAPIDocKey() string
1111
GetObjectKey() string
1212
GetSchema() Schema
13+
GetProjectionMap() map[string]string
14+
GetProjection(string) (string, bool)
1315
getOverrideSchema() (*LocalSchemaRef, bool)
1416
getAsyncOverrideSchema() (*LocalSchemaRef, bool)
1517
setOverrideSchemaValue(Schema)
@@ -21,17 +23,33 @@ type ExpectedResponse interface {
2123
}
2224

2325
type standardExpectedResponse struct {
24-
OverrideBodyMediaType string `json:"overrideMediaType,omitempty" yaml:"overrideMediaType,omitempty"`
25-
AsyncOverrideBodyMediaType string `json:"asyncOverrideMediaType,omitempty" yaml:"asyncOverrideMediaType,omitempty"`
26-
BodyMediaType string `json:"mediaType,omitempty" yaml:"mediaType,omitempty"`
27-
OpenAPIDocKey string `json:"openAPIDocKey,omitempty" yaml:"openAPIDocKey,omitempty"`
28-
ObjectKey string `json:"objectKey,omitempty" yaml:"objectKey,omitempty"`
26+
OverrideBodyMediaType string `json:"overrideMediaType,omitempty" yaml:"overrideMediaType,omitempty"`
27+
AsyncOverrideBodyMediaType string `json:"asyncOverrideMediaType,omitempty" yaml:"asyncOverrideMediaType,omitempty"`
28+
BodyMediaType string `json:"mediaType,omitempty" yaml:"mediaType,omitempty"`
29+
OpenAPIDocKey string `json:"openAPIDocKey,omitempty" yaml:"openAPIDocKey,omitempty"`
30+
ObjectKey string `json:"objectKey,omitempty" yaml:"objectKey,omitempty"`
31+
ProjectionMap map[string]string `json:"projection_map,omitempty" yaml:"projection_map,omitempty"`
2932
Schema Schema
3033
OverrideSchema *LocalSchemaRef `json:"schema_override,omitempty" yaml:"schema_override,omitempty"`
3134
AsyncOverrideSchema *LocalSchemaRef `json:"async_schema_override,omitempty" yaml:"async_schema_override,omitempty"`
3235
Transform *standardTransform `json:"transform,omitempty" yaml:"transform,omitempty"`
3336
}
3437

38+
func (er *standardExpectedResponse) GetProjectionMap() map[string]string {
39+
if er.ProjectionMap == nil {
40+
return make(map[string]string)
41+
}
42+
return er.ProjectionMap
43+
}
44+
45+
func (er *standardExpectedResponse) GetProjection(key string) (string, bool) {
46+
if er.ProjectionMap == nil {
47+
return "", false
48+
}
49+
v, ok := er.ProjectionMap[key]
50+
return v, ok
51+
}
52+
3553
func (er *standardExpectedResponse) setBodyMediaType(s string) {
3654
er.BodyMediaType = s
3755
}

anysdk/loader.go

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func (l *standardLoader) mergeResources(svc OpenAPIService, rscMap map[string]Re
317317
if rsc.GetServiceDocPath() != nil {
318318
sr = rsc.GetServiceDocPath()
319319
}
320-
err := l.mergeResource(svc, rsc, sr)
320+
err := l.mergeResource(k, svc, rsc, sr)
321321
if err != nil {
322322
return err
323323
}
@@ -330,7 +330,7 @@ func (l *standardLoader) mergeResourcesScoped(svc OpenAPIService, svcUrl string,
330330
scopedMap := make(map[string]Resource)
331331
for k, rsc := range rr.GetResources() {
332332
if rr.ObtainServiceDocUrl(k) == svcUrl {
333-
err := l.mergeResource(svc, rsc, &ServiceRef{Ref: svcUrl})
333+
err := l.mergeResource(k, svc, rsc, &ServiceRef{Ref: svcUrl})
334334
if err != nil {
335335
return err
336336
}
@@ -349,14 +349,28 @@ func (l *standardLoader) mergeResourcesScoped(svc OpenAPIService, svcUrl string,
349349
return nil
350350
}
351351

352-
func (l *standardLoader) mergeResource(svc OpenAPIService,
352+
func (l *standardLoader) mergeResource(
353+
rscKey string,
354+
svc OpenAPIService,
353355
rsc Resource,
354356
sr *ServiceRef,
355357
) error {
356358
rsc.setService(svc) // must happen before resolving inverses
359+
existingMethods := make(Methods)
360+
existingResource, existingResourceErr := svc.GetResource(rscKey)
361+
if existingResourceErr == nil && existingResource != nil {
362+
existingMethods = existingResource.GetMethods()
363+
}
357364
for k, vOp := range rsc.GetMethods() {
358365
v := vOp
359366
v.setMethodKey(k)
367+
existingMethod, existingMethodExists := existingMethods[k]
368+
if existingMethodExists {
369+
v = existingMethod
370+
v.setMethodKey(k)
371+
v.setResource(rsc)
372+
continue
373+
}
360374
// TODO: replicate this for the damned inverse
361375
err := l.resolveOperationRef(svc, rsc, &v, v.GetPathRef(), sr)
362376
if err != nil {
@@ -579,20 +593,23 @@ func LoadProviderDocFromFile(fileName string) (Provider, error) {
579593
return loadProviderDocFromBytes(bytes)
580594
}
581595

582-
func GetProviderDocBytes(prov string) ([]byte, error) {
583-
fn, err := getProviderDoc(prov)
596+
func GetProviderDocBytes(prov string, fileRoot string) ([]byte, error) {
597+
fn, err := getProviderDoc(prov, fileRoot)
584598
if err != nil {
585599
return nil, err
586600
}
587601
return os.ReadFile(fn)
588602
}
589603

590-
func getServiceDoc(url string) (io.ReadCloser, error) {
591-
return os.Open(path.Join(OpenapiFileRoot, url))
604+
func getServiceDoc(url string, fileRoot string) (io.ReadCloser, error) {
605+
if fileRoot == "" {
606+
fileRoot = OpenapiFileRoot
607+
}
608+
return os.Open(path.Join(fileRoot, url))
592609
}
593610

594-
func getServiceDocBytes(url string) ([]byte, error) {
595-
f, err := getServiceDoc(url)
611+
func getServiceDocBytes(url string, fileRoot string) ([]byte, error) {
612+
f, err := getServiceDoc(url, fileRoot)
596613
if err != nil {
597614
return nil, err
598615
}
@@ -606,16 +623,16 @@ func ReadService(b []byte) (Service, error) {
606623
return svc, err
607624
}
608625

609-
func GetResourcesRegisterDocBytes(url string) ([]byte, error) {
610-
return getServiceDocBytes(url)
626+
func GetResourcesRegisterDocBytes(url string, fileRoot string) ([]byte, error) {
627+
return getServiceDocBytes(url, fileRoot)
611628
}
612629

613-
func GetServiceDocBytes(url string) ([]byte, error) {
614-
return getServiceDocBytes(url)
630+
func GetServiceDocBytes(url string, fileRoot string) ([]byte, error) {
631+
return getServiceDocBytes(url, fileRoot)
615632
}
616633

617-
func LoadProviderByName(prov, version string) (Provider, error) {
618-
b, err := GetProviderDocBytes(path.Join(prov, version))
634+
func LoadProviderByName(prov, version string, fileRoot string) (Provider, error) {
635+
b, err := GetProviderDocBytes(path.Join(prov, version), fileRoot)
619636
if err != nil {
620637
return nil, err
621638
}
@@ -641,12 +658,15 @@ func findLatestDoc(serviceDir string) (string, error) {
641658
return path.Join(serviceDir, fileNames[fileCount-1]), nil
642659
}
643660

644-
func getProviderDoc(provider string) (string, error) {
661+
func getProviderDoc(provider string, fileRoot string) (string, error) {
662+
if fileRoot == "" {
663+
fileRoot = OpenapiFileRoot
664+
}
645665
switch provider {
646666
case "google":
647-
return findLatestDoc(path.Join(OpenapiFileRoot, "googleapis.com"))
667+
return findLatestDoc(path.Join(fileRoot, "googleapis.com"))
648668
}
649-
return findLatestDoc(path.Join(OpenapiFileRoot, provider))
669+
return findLatestDoc(path.Join(fileRoot, provider))
650670
}
651671

652672
func loadOpenapiServiceDocFromBytes(ps ProviderService, bytes []byte) (OpenAPIService, error) {
@@ -763,6 +783,13 @@ func (loader *standardLoader) resolveOperationRef(doc OpenAPIService, rsc Resour
763783
}
764784

765785
component.setOperationRef(&OperationRef{Value: op, Ref: component.GetOperationRef().Ref})
786+
response, responseExists := component.GetResponse()
787+
if responseExists {
788+
err = loader.resolveExpectedResponse(doc, component.GetOperationRef().Value, response)
789+
if err != nil {
790+
return err
791+
}
792+
}
766793
component.setPathItem(pi)
767794
err = loader.extractAndMergeQueryTransposeOpLevel(component)
768795
if err != nil {

0 commit comments

Comments
 (0)