diff --git a/agent/pkg/oas/specgen_test.go b/agent/pkg/oas/specgen_test.go index fc59aee88..1b7dd1438 100644 --- a/agent/pkg/oas/specgen_test.go +++ b/agent/pkg/oas/specgen_test.go @@ -48,7 +48,8 @@ func TestEntries(t *testing.T) { t.FailNow() } GetOasGeneratorInstance().Start() - loadStartingOAS() + loadStartingOAS("test_artifacts/catalogue.json", "catalogue") + loadStartingOAS("test_artifacts/trcc.json", "trcc-api-service") cnt, err := feedEntries(files, true) if err != nil { @@ -175,8 +176,7 @@ func waitQueueProcessed() { } } -func loadStartingOAS() { - file := "test_artifacts/catalogue.json" +func loadStartingOAS(file string, label string) { fd, err := os.Open(file) if err != nil { panic(err) @@ -195,10 +195,10 @@ func loadStartingOAS() { panic(err) } - gen := NewGen("catalogue") + gen := NewGen(label) gen.StartFromSpec(doc) - GetOasGeneratorInstance().ServiceSpecs.Store("catalogue", gen) + GetOasGeneratorInstance().ServiceSpecs.Store(label, gen) } func TestEntriesNegative(t *testing.T) { diff --git a/agent/pkg/oas/test_artifacts/trcc.json b/agent/pkg/oas/test_artifacts/trcc.json new file mode 100644 index 000000000..91252b166 --- /dev/null +++ b/agent/pkg/oas/test_artifacts/trcc.json @@ -0,0 +1,25 @@ +{ + "openapi": "3.1.0", + "info": { + "title": "Preloaded TRCC", + "version": "0.1", + "description": "Test file for loading pre-existing OAS" + }, + "paths": { + "/models/{id}": { + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "style": "simple", + "schema": { + "type": "string", + "pattern": ".+(_|-|\\.).+" + }, + "example": "some-uuid-maybe" + } + ] + } + } +} \ No newline at end of file diff --git a/agent/pkg/oas/tree.go b/agent/pkg/oas/tree.go index f2e464bee..70eb27b5c 100644 --- a/agent/pkg/oas/tree.go +++ b/agent/pkg/oas/tree.go @@ -51,7 +51,7 @@ func (n *Node) getOrSet(path NodePath, existingPathObj *openapi.PathObj) (node * node = n.searchInConstants(pathChunk) } - if node == nil { + if node == nil && pathChunk != "" { node = n.searchInParams(paramObj, pathChunk, chunkIsGibberish) } @@ -116,7 +116,7 @@ func getPatternFromExamples(exmp *openapi.Examples) *openapi.Regexp { if allInts { re := new(openapi.Regexp) - re.Regexp = regexp.MustCompile("\\d+") + re.Regexp = regexp.MustCompile(`\d+`) return re } return nil @@ -153,10 +153,6 @@ func (n *Node) createParam() *openapi.ParameterObj { } func (n *Node) searchInParams(paramObj *openapi.ParameterObj, chunk string, chunkIsGibberish bool) *Node { - if paramObj != nil || chunkIsGibberish { - logger.Log.Debugf("") - } - // look among params for _, subnode := range n.children { if subnode.constant != nil { @@ -172,6 +168,8 @@ func (n *Node) searchInParams(paramObj *openapi.ParameterObj, chunk string, chun // TODO: and not in exceptions if subnode.pathParam.Schema.Pattern.Match([]byte(chunk)) { return subnode + } else { + return nil } } }