Skip to content

Commit d464cc0

Browse files
Merge pull request #46 from stackql/feature/aot-v2-0-3
aot-v2-0-3
2 parents 935f9fb + e685691 commit d464cc0

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

anysdk/loader.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ func resolveSQLVerbFromResource(rsc Resource, component *OpenAPIOperationStoreRe
885885
}
886886
rv := resolved
887887
rv.setSQLVerb(sqlVerb)
888+
jsonpointer.SetForToken(rsc, component.Ref, *rv)
888889
return rv, nil
889890
}
890891

anysdk/resource.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
var (
1313
_ Resource = &standardResource{}
1414
_ jsonpointer.JSONPointable = standardResource{}
15+
_ jsonpointer.JSONSetable = standardResource{}
1516
)
1617

1718
type Resource interface {
@@ -92,6 +93,9 @@ func (r *standardResource) setService(s OpenAPIService) {
9293

9394
func (r *standardResource) mutateSQLVerb(k string, idx int, v OpenAPIOperationStoreRef) {
9495
r.SQLVerbs[k][idx] = v
96+
if v.Value != nil {
97+
v.Value.setSQLVerb(k)
98+
}
9599
}
96100

97101
func (r *standardResource) setMethod(k string, v *standardOpenAPIOperationStore) {
@@ -196,6 +200,28 @@ func (rsc standardResource) JSONLookup(token string) (interface{}, error) {
196200
}
197201
}
198202

203+
func (rsc standardResource) JSONSet(token string, value interface{}) error {
204+
ss := strings.Split(token, "/")
205+
tokenRoot := ""
206+
if len(ss) > 1 {
207+
tokenRoot = ss[len(ss)-2]
208+
}
209+
switch tokenRoot {
210+
case "methods":
211+
if rsc.Methods == nil {
212+
return fmt.Errorf("Provider.JSONLookup() failure due to prov.ProviderServices == nil")
213+
}
214+
newMethod, isMethod := value.(standardOpenAPIOperationStore)
215+
if !isMethod {
216+
return fmt.Errorf("cannot resolve json pointer path '%s'", token)
217+
}
218+
rsc.Methods[ss[len(ss)-1]] = newMethod
219+
return nil
220+
default:
221+
return fmt.Errorf("cannot set json pointer path '%s'", token)
222+
}
223+
}
224+
199225
func (rs *standardResource) GetDefaultMethodKeysForSQLVerb(sqlVerb string) []string {
200226
return rs.getDefaultMethodKeysForSQLVerb(sqlVerb)
201227
}

public/discovery/static_analyzer.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,21 @@ func (osa *serviceLevelStaticAnalyzer) Analyze() error {
516516
// - expected response attributes:
517517
// - LocalSchemaRef x 2 for sync and async schema overrides
518518
// - OpenAPIOperationStoreRef via resolveSQLVerb()
519-
_, svcErr := osa.registryAPI.GetServiceFragment(providerService, resourceKey)
520-
if svcErr != nil {
521-
osa.errors = append(osa.errors, fmt.Errorf("failed to get service fragment for svc name = %s: %v", providerService.GetName(), svcErr))
519+
520+
// This is a crude trick to prevent pointless service doc re-processing
521+
methods := resource.GetMethods()
522+
if len(methods) == 0 {
523+
_, svcErr := osa.registryAPI.GetServiceFragment(providerService, resourceKey)
524+
if svcErr != nil {
525+
osa.errors = append(osa.errors, fmt.Errorf("failed to get service fragment for svc name = %s: %v", providerService.GetName(), svcErr))
526+
continue
527+
}
528+
methods = resource.GetMethods()
529+
}
530+
if len(methods) == 0 {
531+
osa.errors = append(osa.errors, fmt.Errorf("no methods found for resource %s", resourceKey))
522532
continue
523533
}
524-
methods := resource.GetMethods()
525534
for methodName, method := range methods {
526535
// Perform analysis on each method
527536

@@ -532,6 +541,17 @@ func (osa *serviceLevelStaticAnalyzer) Analyze() error {
532541
if isGraphQL {
533542
continue // TODO: GraphQL methods analysis
534543
}
544+
// Does this method have selection semantics?
545+
sqlVerb := strings.ToLower(method.GetSQLVerb())
546+
isSelectMethod := sqlVerb == "select"
547+
selectItemsKey := method.GetSelectItemsKey()
548+
hasSelectionSemantics := selectItemsKey != ""
549+
if !hasSelectionSemantics && isSelectMethod {
550+
osa.warnings = append(osa.warnings, fmt.Sprintf("apparent select method %s for resource %s does not have selection semantics", methodName, resourceKey))
551+
}
552+
if sqlVerb == "" {
553+
osa.warnings = append(osa.warnings, fmt.Sprintf("method %s for resource %s has no SQL verb", methodName, resourceKey))
554+
}
535555
shouldBeSelectable := method.ShouldBeSelectable()
536556
if shouldBeSelectable {
537557
responseSchema, mediaType, responseInferenceErr := method.GetFinalResponseBodySchemaAndMediaType()

0 commit comments

Comments
 (0)