Hi devs,
We now have 4 REST API reference pages in the new documentation:
They’re all written freely and they all look different: different table columns (with or without a Type, a Required or a Default column), paths written with or without the /rest prefix, data structures called “objects” on one page and “DTOs” on another, status codes documented on 3 pages out of 4, etc. There’s also no single place listing all the REST APIs of XWiki, the same way we now have All Bundled Rendering Macros (see Where to list all macros, UIXPs, etc).
So I’d like to propose to do for REST APIs what we already do for rendering macros and UIXPs in the Documentation Application: introduce dedicated XClasses and a sheet that renders them, so that all REST API pages share the same look and feel, and so that we can list them all in a Live Data.
Proposal
One page per REST API
A page documents one REST API, i.e. the set of REST resources contributed by one extension or module (e.g. the 8 resources of the Release Notes Application), and not one page per endpoint. Rationale: the most useful content on these pages is shared by all the operations (why the API exists, path parameters, status codes, rights, non-goals, workflows spanning several calls), and splitting would produce lots of thin pages.
Three XClasses
REST API (one per page):
description: the introductionproduct: the product the API belongs to, as the{{version}}macro names it (“XWiki” for bundled APIs, “Release Notes Application”, “LLM”, etc.)pathParameters: the path parameters shared by all the operations (e.g.{wiki},{product}), described oncestatusCodes: Code | When, documented once for the whole APIrights(optional)
Operation (one per HTTP method + path):
id(e.g.createChange, also used as the anchor of its section),method,path(full path starting with/rest/),summary,group(optional, e.g. “Tasks”),since(optional, see below)descriptionparameters: Name | In (path, query, header) | Type | Required | Default | DescriptionrequestBody/responseBody: the name of a Representation (Tour[]for a list of them)exampleRequest(rendered as bash) /exampleResponse(rendered as JSON)
Representation (one per data structure, e.g. Change, Tour):
name,fields(Name | Type | Required | Default | Description, where Required can also be “read-only” for fields only present in answers),example
The tabular fields hold only the table rows, as wiki syntax, the sheet adding the header so that the columns are always the same. I considered one XObject per parameter/field/status code, but it means about 74 objects for the Release Notes page (14 with the proposal) and these rows are never queried.
Rendering
The sheet renders, in this order: the description, a summary table of all operations (Method + Path | Summary, grouped), one section per operation (description, parameters including the shared path ones, example request/response), the Representations, the Status codes, the Rights, then the page content, which stays free for anything else (workflows, warnings, what the API doesn’t do).
To give an idea, here’s how the Release Notes page would change:
- The
Sincecolumn of the summary table is replaced by a version badge on the operations added in 2.8. - The “Create a release note” and “Create a change” field tables become the
ReleaseNoteandChangeRepresentations (with a Type column), referenced by the POST and PUT operations instead of being duplicated. - The 3 GETs get their own (short) sections.
- The Status codes and Rights sections, the FAQ and the “What these resources do not do” section stay as they are.
Index of all REST operations
Following what was agreed in the catalogue pages thread, a new Explanation page documentation.xs.dev.rest-api explains how the XWiki REST API works in general (authentication, CSRF token, XML vs JSON, encoding of nested spaces), and a Reference page nested under it, “All Bundled REST Operations”, lists one operation per row in a Live Data (Method, Path, Summary, Group, Product, link to its section), filtered by default on the bundled ones, the filter being removable to also see the extension ones.
Checks
New documentation checks validate the pages: every {placeholder} of a path is described, rows have the right number of cells, operation ids are unique, request/response bodies reference an existing Representation, paths start with /rest/, the product is filled (and is “XWiki” for bundled APIs), unused Representations and shared path parameters are reported, and since values older than the LTS cycle are reported (same as for the {{version}} macro).
Rollout
- Implement the XClasses, sheet, template and checks in the Documentation Application (xwiki.org-specific part, next to the rendering macro and UIXP classes).
- Migrate the 4 existing pages (Release Notes first since it’s the richest), checking their content for accuracy against the code of each extension.
- Create the REST API Explanation page and the index.
- Later, migrate the generic XWiki REST API documentation (about 72 operations) topic by topic, into REST API pages under the topics they belong to.
Alternative considered: OpenAPI / Swagger
I’ve looked at generating an OpenAPI spec from our code instead. It’s feasible without adding Swagger annotations (tools like Enunciate or swagger-core can scan our existing JAX-RS annotations and the JAXB model generated from the XSD), and we already have a contrib Swagger macro able to render a spec in a wiki page. However:
- A Live Data can’t list operations that only exist inside an attached spec file.
- The descriptions would only be as good as the Javadoc and the XSD. The JAX-RS resources of
xwiki-platform-rest-apinow have proper Javadoc, but the XSD of the REST model has no documentation, and extensions contributing REST resources would need the same effort. - A spec can’t hold what makes the existing pages useful: why the API exists, the workflows spanning several calls, the rights, the non-goals.
- Every extension contributing REST resources would need to generate its own spec as part of its build.
The proposal keeps it open for later though, since the XClasses use the OpenAPI concepts (operation id, parameters in path/query/header, request/response bodies, schemas): we could export a spec from the XObjects (and get a “try it” console with the Swagger macro), or compare the pages with a spec generated at build time to detect missing or outdated operations. The same scanning of the JAX-RS annotations and Javadoc could also be used to pre-fill the Operation XObjects when migrating the generic XWiki REST API documentation.
Open question: the “no Since column” rule
Our doc guide says that a version only appears through the {{version}} macro, never as a Since column in a reference table, and that versions older than the current LTS cycle are removed. The proposal follows this rule (optional since rendered as a badge in the Summary cell, empty for most operations), and the Release Notes page currently breaks it. However, for API references, a since-per-operation is quite natural (it’s what the Javadoc @since gives developers), so I’m wondering if we should review that rule for API references. WDYT?
Next steps
If you agree, I’ll create a work package in the Documentation Application project, then update the doc guide (REST API pages and catalogue pages) and document the new XClasses in the Documentation Application documentation.
WDYT?
Thanks