More pre-loaded

This commit is contained in:
Andrey Pokhilko
2022-02-21 15:44:38 +03:00
parent 16cefcc55e
commit baab4b8bdb
3 changed files with 34 additions and 11 deletions

View File

@@ -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) {

View File

@@ -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"
}
]
}
}
}

View File

@@ -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
}
}
}