Skip to content

Commit 3606fd6

Browse files
committed
move jq processing into dedicated .jq file, add missing field
1 parent a79901b commit 3606fd6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ openapi-extract.json:
2121
#
2222
# Also, we're only handling the "extract" OpenAPI spec at this time.
2323
openapi.json: openapi-extract.json
24-
cat openapi-extract.json | jq 'walk(if (.|type) == "object" and .items? and (.items|type) == "array" then .items = .items[0] else . end)|del(.paths["/{api}"])|.openapi="3.0.3"' >openapi.json
24+
cat openapi-extract.json | jq -f extract.jq >openapi.json
2525

2626
# Create a minified version, while we're in here
2727
openapi.min.json: openapi.json

extract.jq

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This jq file is used to process openapi-extract.json into a proper
2+
# OpenAPI spec.
3+
4+
# This "spec" has array items as a list instead of an object. I have
5+
# no idea why. Here, we walk the whole spec and replace any entry with
6+
# key "items" and an array value with the first element of the array.
7+
walk(if (.|type) == "object" and .items? and (.items|type) == "array" then .items = .items[0] else . end)
8+
9+
# The "/{api}" path is underspecified. It's custom anyway. Just get
10+
# rid of it.
11+
| del(.paths["/{api}"])
12+
13+
# The various analyze endpoints are missing an important field in
14+
# their response, "resolvedPageUrl". Add it.
15+
| .paths["/analyze"].get.responses["200"].content["application/json"].schema.properties.objects.items.properties.resolvedPageUrl = {"type": "string"}
16+
| .paths["/article"].get.responses["200"].content["application/json"].schema.properties.objects.items.properties.resolvedPageUrl = {"type": "string"}
17+
| .paths["/product"].get.responses["200"].content["application/json"].schema.properties.objects.items.properties.resolvedPageUrl = {"type": "string"}
18+
| .paths["/discussion"].get.responses["200"].content["application/json"].schema.properties.objects.items.properties.resolvedPageUrl = {"type": "string"}
19+
| .paths["/job"].get.responses["200"].content["application/json"].schema.properties.objects.items.properties.resolvedPageUrl = {"type": "string"}
20+
| .paths["/image"].get.responses["200"].content["application/json"].schema.properties.objects.items.properties.resolvedPageUrl = {"type": "string"}
21+
| .paths["/video"].get.responses["200"].content["application/json"].schema.properties.objects.items.properties.resolvedPageUrl = {"type": "string"}
22+
| .paths["/list"].get.responses["200"].content["application/json"].schema.properties.objects.items.properties.resolvedPageUrl = {"type": "string"}
23+
| .paths["/event"].get.responses["200"].content["application/json"].schema.properties.objects.items.properties.resolvedPageUrl = {"type": "string"}
24+
25+
# This "spec" is v3.1.0, but tooling only really takes v3.0.x at the
26+
# moment. Just rewrite the version.
27+
|.openapi="3.0.3"

0 commit comments

Comments
 (0)