|
@@ -154,6 +154,7 @@ func (s *apiImportState) process(api *ApiStruct, token string) (apiFileState, er
|
|
|
|
|
|
func (s *apiTypeState) process(api *ApiStruct, token string) (apiFileState, error) {
|
|
func (s *apiTypeState) process(api *ApiStruct, token string) (apiFileState, error) {
|
|
var blockCount = 0
|
|
var blockCount = 0
|
|
|
|
+ var braceCount = 0
|
|
for {
|
|
for {
|
|
line, err := s.readLine()
|
|
line, err := s.readLine()
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -161,7 +162,7 @@ func (s *apiTypeState) process(api *ApiStruct, token string) (apiFileState, erro
|
|
}
|
|
}
|
|
|
|
|
|
line = token + line
|
|
line = token + line
|
|
- if blockCount <= 1 {
|
|
|
|
|
|
+ if braceCount == 0 {
|
|
line = mayInsertStructKeyword(line)
|
|
line = mayInsertStructKeyword(line)
|
|
}
|
|
}
|
|
api.Type += newline + newline + line
|
|
api.Type += newline + newline + line
|
|
@@ -171,17 +172,31 @@ func (s *apiTypeState) process(api *ApiStruct, token string) (apiFileState, erro
|
|
|
|
|
|
if strings.HasSuffix(line, leftBrace) {
|
|
if strings.HasSuffix(line, leftBrace) {
|
|
blockCount++
|
|
blockCount++
|
|
|
|
+ braceCount++
|
|
}
|
|
}
|
|
if strings.HasSuffix(line, string(leftParenthesis)) {
|
|
if strings.HasSuffix(line, string(leftParenthesis)) {
|
|
blockCount++
|
|
blockCount++
|
|
}
|
|
}
|
|
if strings.HasSuffix(line, string(rightBrace)) {
|
|
if strings.HasSuffix(line, string(rightBrace)) {
|
|
blockCount--
|
|
blockCount--
|
|
|
|
+ braceCount--
|
|
}
|
|
}
|
|
if strings.HasSuffix(line, string(rightParenthesis)) {
|
|
if strings.HasSuffix(line, string(rightParenthesis)) {
|
|
blockCount--
|
|
blockCount--
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if braceCount >= 2 {
|
|
|
|
+ return nil, errors.New("nested type not supported: " + line)
|
|
|
|
+ }
|
|
|
|
+ if braceCount < 0 {
|
|
|
|
+ line = strings.TrimSuffix(line, string(rightBrace))
|
|
|
|
+ line = strings.TrimSpace(line)
|
|
|
|
+ if strings.HasSuffix(line, leftBrace) {
|
|
|
|
+ blockCount++
|
|
|
|
+ braceCount++
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
if blockCount == 0 {
|
|
if blockCount == 0 {
|
|
return &apiRootState{s.baseState}, nil
|
|
return &apiRootState{s.baseState}, nil
|
|
}
|
|
}
|
|
@@ -223,12 +238,15 @@ func (s *apiServiceState) process(api *ApiStruct, token string) (apiFileState, e
|
|
|
|
|
|
func mayInsertStructKeyword(line string) string {
|
|
func mayInsertStructKeyword(line string) string {
|
|
line = util.RemoveComment(line)
|
|
line = util.RemoveComment(line)
|
|
- if !strings.HasSuffix(line, leftBrace) {
|
|
|
|
|
|
+ if !strings.HasSuffix(line, leftBrace) && !strings.HasSuffix(line, string(rightBrace)) {
|
|
return line
|
|
return line
|
|
}
|
|
}
|
|
|
|
|
|
fields := strings.Fields(line)
|
|
fields := strings.Fields(line)
|
|
- if stringx.Contains(fields, tokenStruct) || stringx.Contains(fields, tokenStruct+leftBrace) || len(fields) <= 1 {
|
|
|
|
|
|
+ if stringx.Contains(fields, tokenStruct) ||
|
|
|
|
+ stringx.Contains(fields, tokenStruct+leftBrace) ||
|
|
|
|
+ stringx.Contains(fields, tokenStruct+leftBrace+string(rightBrace)) ||
|
|
|
|
+ len(fields) <= 1 {
|
|
return line
|
|
return line
|
|
}
|
|
}
|
|
|
|
|