Skip to content

TypeScript API / laikacms/json-api / compactOpenApiDocument

Function: compactOpenApiDocument() ​

ts
function compactOpenApiDocument(source): OpenApiDocument;

Hoist repeated inline responses and parameters into components, replacing each occurrence with a $ref.

Authoring the paths with plain helper calls (errorResponse('...'), paginationParameters) is the readable way to write a spec, but it inlines the same objects over and over: the documents API repeats one 400-response body 7 times and the six page[*] parameters 4 times each, which is ~12% of the served document. Callers still write the spec inline; this pass normalizes it on the way out, so the wire form stays small without the source becoming a wall of $refs.

Responses are grouped by body, not by whole object: OpenAPI 3.1 lets a Reference Object carry its own description that overrides the target's (see OpenApiRef), so operations sharing an error body keep their specific wording while sharing one definition.

Lossless after $ref resolution - a client that dereferences the result gets the same document back.

Parameters ​

ParameterType
sourceOpenApiDocument

Returns ​

OpenApiDocument

Released under the MIT License.