@@ -9,19 +9,6 @@ import (
99 "strings"
1010)
1111
12- type ApiIntermediate struct {
13- ApiVersion string
14- ApiTitle string
15- ApiDescription string
16- BasePath string
17- SubApis []SubApiIntermediate
18- }
19-
20- type SubApiIntermediate struct {
21- Name string
22- Path string
23- }
24-
2512// This is an intermediate representation of a path and/or operation as parsed
2613// in the comments. A collection of these can be combined and transformed to
2714// create the swagger hierarchy.
@@ -63,61 +50,55 @@ func (this *ResponseIntermediate) Schema() *spec.Schema {
6350 return schema
6451}
6552
66- func intermediatateApi (commentBlocks []string ) ApiIntermediate {
53+ // This function does not do type detection. It merely scrapes what information
54+ // there is in the comment block.
55+ func intermediatateOperation (commentBlock string ) OperationIntermediate {
6756
68- // @APIVersion 1.0.0
69- // @APITitle REST API
70- // @APIDescription EMS Rest API
71- // @BasePath /api/v1
72- // @SubApi HealthCheck [/health]
57+ /*
58+ OpenAPI Path:
59+ /api/villages
7360
74- var (
75- // At the time of writing, IntelliJ erroneously warns on unnecessary
76- // escape sequences. Do not trust IntelliJ.
77- rxApiVersion * regexp.Regexp = regexp .MustCompile (`@APIVersion\s+([\d\.]+)` )
78- rxApiTitle * regexp.Regexp = regexp .MustCompile (`@APITitle\s+(.+)` )
79- rxApiDescription * regexp.Regexp = regexp .MustCompile (`@APIDescription\s+(.+)` )
80- rxBasePath * regexp.Regexp = regexp .MustCompile (`@BasePath\s+([/a-zA-Z0-9-]+)` )
81- rxSubApi * regexp.Regexp = regexp .MustCompile (`@SubApi\s+([0-9a-zA-Z]+)\s+\[([/a-zA-Z0-9-]+)\]` )
82- )
61+ OpenAPI Method:
62+ GET
8363
84- var apiIntermediate ApiIntermediate = ApiIntermediate {
85- SubApis : make ([]SubApiIntermediate , 0 ),
86- }
64+ OpenAPI Query String Parameters:
65+ world string required World UUID
66+ user string optional User UUID
67+ x int optional X-coordinate for blind query
68+ y int optional Y-coordinate for blind query
69+ w int optional Width of query area
70+ h int optional Height of query area
8771
88- for _ , commentBlock := range commentBlocks {
89-
90- b := bytes .NewBufferString (commentBlock )
91- scanner := bufio .NewScanner (b )
92- for scanner .Scan () {
93- line := scanner .Text ()
94-
95- switch {
96-
97- case rxApiDescription .MatchString (line ):
98- apiIntermediate .ApiDescription = rxApiDescription .FindStringSubmatch (line )[1 ]
99- case rxApiTitle .MatchString (line ):
100- apiIntermediate .ApiTitle = rxApiTitle .FindStringSubmatch (line )[1 ]
101- case rxApiVersion .MatchString (line ):
102- apiIntermediate .ApiVersion = rxApiVersion .FindStringSubmatch (line )[1 ]
103- case rxBasePath .MatchString (line ):
104- apiIntermediate .BasePath = rxBasePath .FindStringSubmatch (line )[1 ]
105-
106- case rxSubApi .MatchString (line ):
107- matches := rxSubApi .FindStringSubmatch (line )
108- subApi := SubApiIntermediate {
109- Name : matches [1 ],
110- Path : matches [2 ],
111- }
112- apiIntermediate .SubApis = append (apiIntermediate .SubApis , subApi )
113- }
114- }
115- }
72+ OpenAPI Request Body:
73+ nil
11674
117- return apiIntermediate
118- }
75+ OpenAPI Response Body:
76+ []types.Village
11977
120- func intermediatateOperation (commentBlock string ) OperationIntermediate {
78+ OpenAPI Description:
79+ This endpoint returns all of the villages that belong to the user and world
80+ specified by the query string parameter.
81+
82+ The `world` parameter is required in all uses.
83+
84+ The `user` parameter returns all villages owned by that user. If the calling
85+ player has permission to view all village information, then that information
86+ will be returned. Otherwise, only a subset of village information is
87+ returned. Use of this parameter is the recommended way to get the calling
88+ user's villages. Use of this parameter takes precedence over the use of the
89+ `x`, `y`, `w`, and `h` parameters.
90+
91+ Similar to the tiles endpoint (`/api/tiles [GET]`), the `x`, `y`, `w`, and
92+ `h` parameters control the retrieval of all the villages in a specific area
93+ of the map. Unless specified, the values for these parameters are assumed to
94+ be zero. If `w` and `h` are zero, then only one village is returned (if it
95+ exists at the coordinates provided). The maximum values accepted for `w` and
96+ `h` will be 1000, and values exceeding 1000 will be quietly accepted as
97+ 1000.
98+
99+ In all circumstances, a set (array) is returned regardless of the quantity
100+ of villages returned.
101+ */
121102
122103 // @Title Get TimeZone
123104 // @Description Return a TimeZone, given its id
@@ -253,28 +234,3 @@ func intermediatateOperation(commentBlock string) OperationIntermediate {
253234
254235 return operationIntermediate
255236}
256-
257- func mergeDefinitions (dst , src * DefinitionIntermediate ) {
258- for srcName , srcMember := range src .Members {
259- _ , exists := dst .Members [srcName ]
260- if ! exists {
261- dst .Members [srcName ] = srcMember
262- }
263- }
264- }
265-
266- func tagOperations (apiIntermediate ApiIntermediate , operationIntermediates []OperationIntermediate ) []OperationIntermediate {
267- newOperationIntermediates := make ([]OperationIntermediate , 0 )
268-
269- for _ , operationIntermediate := range operationIntermediates {
270- for _ , subApi := range apiIntermediate .SubApis {
271- if strings .HasPrefix (operationIntermediate .Path , subApi .Path ) {
272- operationIntermediate .Tag = subApi .Name
273- break
274- }
275- }
276- newOperationIntermediates = append (newOperationIntermediates , operationIntermediate )
277- }
278-
279- return newOperationIntermediates
280- }
0 commit comments