Skip to content

Commit 4cdae28

Browse files
authored
OpenAPI: Fix and improve validation, resolve conflicts in endpoint descriptions (#835)
* Attempt to trigger OpenAPI validation at the end of the build Move invocation to home.navigation.html and set high output format weight, add locks and debug printing for map in arangoproxy There still appear to be openapi render hook calls after the validation, and Hugo reports the end of the build way before that * OpenAPI Render Hook: Substitute version alias with version number to prevent duplicate invocations This is only an issue for endpoint descriptions that contain internal links that get replaced with absolute URLs for api-docs.json / SwaggerUI. Hugo's caching of resources.GetRemote prevents duplicate calls arangoproxy's /openapi if the requests are identical * Replace invocation of OpenAPI validation It no longer gets triggered in live builds (hugo server) but only static builds, where we can reliably start the validation after the build * Add debugging and validation for OpenAPI endpoints to find duplicate operationIds and conflicting endpoint descriptions Note that identical endpoint descriptions for the same version are not considered an error (used for a few View endpoints on purpose). In fact, Hugo's caching of resources.GetRemote prevents arangoproxy from even getting called twice, which we take advantage of. * Fix newly discovered conflicts between arangosearch and search-alias View endpoints and operationIds * Revert addition of output format weight, use single curl HTTP method arangoproxy's endpoints work with any method (HEAD, POST, ...) but using -I (HEAD) has the advantage that it only returns the HTTP headers * Propagate validation errors to start_hugo.sh to let the pipeline fail if needed Also add a temporary bug to an endpoint description for testing * Propagate spec errors to CI * Test duplicate operationId * Remove a required property to cause swagger-cli to fail * Revert removal of required property * Reset error booleans
1 parent c2d81b2 commit 4cdae28

File tree

10 files changed

+218
-57
lines changed

10 files changed

+218
-57
lines changed

site/content/arangodb/3.11/develop/http-api/views/search-alias-views.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ db._drop(coll.name());
211211

212212
```openapi
213213
paths:
214-
/_db/{database-name}/_api/view/{view-name}:
214+
/_db/{database-name}/_api/view/{view-name}#searchalias:
215215
get:
216-
operationId: getView
216+
operationId: getViewSearchAlias
217217
description: |
218218
Returns the basic information about a specific View.
219219
parameters:
@@ -1012,10 +1012,10 @@ db._drop(coll.name());
10121012

10131013
```openapi
10141014
paths:
1015-
/_db/{database-name}/_api/view/{view-name}/rename:
1015+
/_db/{database-name}/_api/view/{view-name}/rename#searchalias:
10161016
put:
10171017
# The PATCH method can be used as an alias
1018-
operationId: renameView
1018+
operationId: renameViewSearchAlias
10191019
description: |
10201020
Renames a View.
10211021

site/content/arangodb/3.12/develop/http-api/views/search-alias-views.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ db._drop(coll.name());
211211

212212
```openapi
213213
paths:
214-
/_db/{database-name}/_api/view/{view-name}:
214+
/_db/{database-name}/_api/view/{view-name}#searchalias:
215215
get:
216-
operationId: getView
216+
operationId: getViewSearchAlias
217217
description: |
218218
Returns the basic information about a specific View.
219219
parameters:
@@ -1012,10 +1012,10 @@ db._drop(coll.name());
10121012

10131013
```openapi
10141014
paths:
1015-
/_db/{database-name}/_api/view/{view-name}/rename:
1015+
/_db/{database-name}/_api/view/{view-name}/rename#searchalias:
10161016
put:
10171017
# The PATCH method can be used as an alias
1018-
operationId: renameView
1018+
operationId: renameViewSearchAlias
10191019
description: |
10201020
Renames a View.
10211021

site/content/arangodb/4.0/develop/http-api/views/search-alias-views.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ db._drop(coll.name());
211211

212212
```openapi
213213
paths:
214-
/_db/{database-name}/_api/view/{view-name}:
214+
/_db/{database-name}/_api/view/{view-name}#searchalias:
215215
get:
216-
operationId: getView
216+
operationId: getViewSearchAlias
217217
description: |
218218
Returns the basic information about a specific View.
219219
parameters:
@@ -1012,10 +1012,10 @@ db._drop(coll.name());
10121012

10131013
```openapi
10141014
paths:
1015-
/_db/{database-name}/_api/view/{view-name}/rename:
1015+
/_db/{database-name}/_api/view/{view-name}/rename#searchalias:
10161016
put:
10171017
# The PATCH method can be used as an alias
1018-
operationId: renameView
1018+
operationId: renameViewSearchAlias
10191019
description: |
10201020
Renames a View.
10211021

site/themes/arangodb-docs-theme/layouts/_default/_markup/render-codeblock-openapi.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
{{- $url := index $match 2 }}
99
{{- $isRemote := ne (urls.Parse $url).Scheme "" }}
1010
{{- if not $isRemote }}
11-
{{- $absUrl := printf "https://docs.arango.ai%s" (urls.RelRef $page $url) }}
11+
{{- $absPath := urls.RelRef $page $url }}
12+
{{- $absPathUnaliased := replaceRE "^/arangodb/(?:stable|devel)/" (printf "/arangodb/%s/" $pageVersion) $absPath 1 }}
13+
{{- $absUrl := printf "https://docs.arango.ai%s" $absPathUnaliased }}
1214
{{- $newLink := printf "[%s](%s)" (index $match 1) $absUrl }}
1315
{{- $linkMap = merge $linkMap (dict (index $match 0) $newLink) }}
1416
{{- end }}

site/themes/arangodb-docs-theme/layouts/_default/baseof.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,4 @@
2929
{{ partialCached "back-to-top.html" . -}}
3030
{{ partialCached "search.html" . -}}
3131
</body>
32-
</html>
33-
{{- /* Trigger validation at the end of the build once */ -}}
34-
{{ if .IsHome -}}
35-
{{ with templates.Defer -}}
36-
{{ partial "openapi-validate.html" (dict "key" "global") -}}
37-
{{ end -}}
38-
{{ end -}}
32+
</html>

site/themes/arangodb-docs-theme/layouts/partials/openapi-validate.html

Lines changed: 0 additions & 6 deletions
This file was deleted.

site/themes/arangodb-docs-theme/layouts/shortcodes/validate-openapi.html

Lines changed: 0 additions & 6 deletions
This file was deleted.

toolchain/arangoproxy/internal/controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,14 @@ func OpenapiHandler(w http.ResponseWriter, r *http.Request) {
127127
func ValidateOpenapiHandler(w http.ResponseWriter, r *http.Request) {
128128
models.Logger.Printf("Validate openapi specs")
129129

130-
OPENAPIService.ValidateOpenapiGlobalSpec()
130+
err := OPENAPIService.ValidateOpenapiGlobalSpec()
131131
w.Header().Set("Content-Type", "text/plain") // Any allow-listed media type
132+
if err != nil {
133+
models.Logger.Printf("[ValidateOpenapiHandler] Validation failed: %s", err.Error())
134+
w.WriteHeader(http.StatusInternalServerError)
135+
w.Write([]byte(fmt.Sprintf("OpenAPI validation failed: %s", err.Error())))
136+
return
137+
}
132138
w.WriteHeader(http.StatusOK)
133139
}
134140

0 commit comments

Comments
 (0)