Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,43 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# `disallowAdditionalPropertiesIfNotPresent: false` only covers schemas that
# omit additionalProperties. For an explicit `additionalProperties: false` the
# generator reads the OpenAPI 3.1 boolean schema inconsistently, so the
# additional-properties catch-all silently comes and goes between spec
# revisions. `true` has only one reading.
# Keep in lockstep with scripts/generate-local.sh.
- name: Fetch and normalise OpenAPI spec
if: steps.version_check.outputs.should_generate == 'true'
run: |
curl -fsSL https://docs.reveng.ai/openapi.json -o openapi.json
python3 - <<'PY'
import json

with open("openapi.json") as f:
spec = json.load(f)

for schema in spec.get("components", {}).get("schemas", {}).values():
if not isinstance(schema, dict) or schema.get("additionalProperties") is not False:
continue
if schema.get("properties"):
schema["additionalProperties"] = True
else:
# No properties means an empty response body; `true` would change
# its generated type, so drop the key instead.
del schema["additionalProperties"]

with open("openapi.json", "w") as f:
json.dump(spec, f)
PY

- name: Generate Java SDK
if: steps.version_check.outputs.should_generate == 'true'
uses: openapi-generators/openapitools-generator-action@b729d184e6b3459572c37c0e37f88a832e69b552 # v1.5.0
with:
generator: java
generator-tag: 'v7.23.0'
openapi-url: https://docs.reveng.ai/openapi.json
openapi-file: openapi.json
config-file: config.yml
template-dir: templates
# For the artifact version drop the `v` prefix as it's not usually used in Maven versions
Expand Down
24 changes: 24 additions & 0 deletions scripts/generate-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ case "$SPEC" in
;;
esac

# Normalise `additionalProperties: false` out of the spec. Keep in lockstep
# with the "Fetch and normalise OpenAPI spec" step in
# .github/workflows/check.yaml, which explains why.
python3 - "$SPEC_FILE" <<'PY'
import json
import sys

with open(sys.argv[1]) as f:
spec = json.load(f)

for schema in spec.get("components", {}).get("schemas", {}).values():
if not isinstance(schema, dict) or schema.get("additionalProperties") is not False:
continue
if schema.get("properties"):
schema["additionalProperties"] = True
else:
# No properties means an empty response body; `true` would change its
# generated type, so drop the key instead.
del schema["additionalProperties"]

with open(sys.argv[1], "w") as f:
json.dump(spec, f)
PY

SPEC_VERSION="$(jq -r '.info.version // empty' "$SPEC_FILE")"
[ -n "$SPEC_VERSION" ] || { echo "spec has no info.version" >&2; exit 1; }
echo "==> Spec info.version: $SPEC_VERSION"
Expand Down
3 changes: 2 additions & 1 deletion scripts/postprocess.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ rm -Rf gradlew.bat && mv java-client/gradlew.bat .
rm -Rf pom.xml && mv java-client/pom.xml .
rm -Rf settings.gradle && mv java-client/settings.gradle .
rm -Rf README.md && mv java-client/README.md .
rm -Rf java-client
# openapi.json is the normalised spec CI generates from; it must not be committed.
rm -Rf java-client openapi.json

# Ensure gradlew is executable
chmod +x gradlew
Expand Down
Loading