Files
ocis/web/packages/web-client/scripts/generate-openapi.sh
Matteo e1a0f3a1b2 [full-ci] chore: [OCISDEV-1412] remove the readOnly workaround from the libre-graph client generation (#12956)
* chore: [OCISDEV-1412] remove the readOnly workaround from the libre-graph client generation

The client generation stripped every `readOnly: true` line from the spec
before running the generator, because the typescript-fetch templates leave
read-only fields out of the serializers they emit and a few fields oCIS does
accept on write were annotated read-only. Stripping them all also unmarked
the fields that genuinely are response-only.

The annotations are corrected upstream now, so the generator runs on the spec
as published. Everything oCIS writes is still serialized: the drive quota
total, the drive type, a space image and readme, the hidden flag and remote
item of a drive item, and the fields of a sharing permission. Response-only
fields such as the computed quota values are now typed read-only, which the
handful of places that assigned to them had to be adjusted for.

* chore: [OCISDEV-1412] regenerate the libre-graph client after the driveType split

drive now declares its own writable driveType while driveUpdate marks it
readOnly, so updateDrive no longer accepts a value the server rejects.

* fix: [OCISDEV-1412] keep the special folder id in the drive update body

Setting a space image or readme patches the drive with the id of an existing
item under special. driveItem.id was marked readOnly in the spec, so the
generated serializer dropped it and the server skipped the entry: the request
returned 200 and did nothing, which the e2e space image test caught as a
timeout waiting for the image to load.

The annotation is gone from the spec, and updateDrive now has tests asserting
the serialized body, since neither type checking nor a mocked call notices a
field that quietly disappears.

* fix: [OCISDEV-1412] regenerate after splitting the drive special folder schema

An update to a drive assigns its special folders by referencing existing
items by id. Upstream now models that with a dedicated schema instead of
reusing the response-only drive item, so the update body keeps the id while
the drive item itself is read-only again.

The wrapper around the generated client typed the update body as a drive
rather than a drive update, which no longer holds now that the two differ in
how they describe the special folders.
2026-09-17 07:18:50 +02:00

58 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env sh
set -eu
# Regenerates the libre-graph client under src/graph/generated.
#
# `readOnly: true` in the spec is load-bearing here: the typescript-fetch templates omit
# those fields from the generated `*ToJSON` serializers, so a field that oCIS does accept
# on write but that the spec marks read-only is silently dropped from the request body.
# Note that a `readOnly` next to a `$ref` has no effect (OpenAPI 3.0 ignores siblings of
# `$ref`) — what propagates is the annotation on the referenced schema itself.
#
# oCIS returns a field the spec does not declare: `attributes` on users, added by
# `UserWithAttributes` in services/graph and filled from
# OCIS_USER_SEARCH_DISPLAYED_ATTRIBUTES. The typescript-fetch templates rebuild every
# response from the declared fields only, so an undeclared field is dropped during decoding.
# It is declared on the read model below to keep it.
SPEC_URL="https://raw.githubusercontent.com/owncloud/libre-graph-api/main/api/openapi-spec/v1.0.yaml"
GRAPH_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")/../src/graph" && pwd)"
SPEC_FILE="$GRAPH_DIR/openapi-spec.yaml"
# The single line the `user` schema composes `userUpdate` into. The two other references to
# that schema are request bodies and sit at a different indentation.
USER_ALL_OF_LINE=" - \$ref: '#/components/schemas/userUpdate'"
cleanup() {
rm -f "$SPEC_FILE"
}
trap cleanup EXIT
rm -rf "$GRAPH_DIR/generated"
curl -sSfL "$SPEC_URL" \
| awk -v anchor="$USER_ALL_OF_LINE" '
{ print }
$0 == anchor {
print " - type: object"
print " properties:"
print " attributes:"
print " type: array"
print " items:"
print " type: string"
print " description: Attributes of the user as configured via OCIS_USER_SEARCH_DISPLAYED_ATTRIBUTES. Not part of the upstream spec, added by oCIS. Read-only."
patched = 1
}
END { if (!patched) exit 1 }
' >"$SPEC_FILE" || {
echo "failed to declare the oCIS-only user 'attributes' field: the spec no longer contains" >&2
echo "the expected line, adapt USER_ALL_OF_LINE to how the 'user' schema now composes" >&2
echo "'userUpdate'. Regenerating without it silently drops the field from user responses." >&2
exit 1
}
docker run --rm -v "$GRAPH_DIR:/local" openapitools/openapi-generator-cli generate \
-i /local/openapi-spec.yaml \
-g typescript-fetch \
--type-mappings=DateTime=string \
-o /local/generated