@haddowg/json-api-codegen 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/{index-BLBSnK8y.d.mts → index-Ch2PJH9Y.d.mts} +2 -2
- package/dist/{index-BLBSnK8y.d.mts.map → index-Ch2PJH9Y.d.mts.map} +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{src-D29xU79S.mjs → src-D4apiVHe.mjs} +56 -8
- package/dist/src-D4apiVHe.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/src-D29xU79S.mjs.map +0 -1
package/dist/cli.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as CodegenConfig } from "./index-
|
|
1
|
+
import { r as CodegenConfig } from "./index-Ch2PJH9Y.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/cli.d.ts
|
|
4
4
|
declare const USAGE = "Usage: json-api-codegen --input <url|file> --output <file> [--server <name>] [--schemas <url|file>] [--examples] [--check]";
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { i as generateFiles, t as check } from "./src-
|
|
2
|
+
import { i as generateFiles, t as check } from "./src-D4apiVHe.mjs";
|
|
3
3
|
import { realpathSync } from "node:fs";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
//#region src/cli.ts
|
|
@@ -330,7 +330,7 @@ declare function buildExamples(doc: OpenApiDocument, descriptor: ApiDescriptor):
|
|
|
330
330
|
/** Below this the document predates the structures this codegen reads. */
|
|
331
331
|
declare const MINIMUM_CONTRACT = 1;
|
|
332
332
|
/** Above this the document carries structures this codegen does not read. */
|
|
333
|
-
declare const MAXIMUM_CONTRACT =
|
|
333
|
+
declare const MAXIMUM_CONTRACT = 17;
|
|
334
334
|
/**
|
|
335
335
|
* Check the document's `info.x-generator.contract` against the range this codegen reads. A
|
|
336
336
|
* document older than the range throws; a newer one returns a warning, because its new
|
|
@@ -718,4 +718,4 @@ declare function generateFiles(config: CodegenConfig): Promise<string[]>;
|
|
|
718
718
|
declare function check(config: CodegenConfig): Promise<CheckResult>;
|
|
719
719
|
//#endregion
|
|
720
720
|
export { operationExamples as A, PathItemObject as B, VerbCollision as C, MINIMUM_CONTRACT as D, MAXIMUM_CONTRACT as E, InfoObject as F, SecurityRequirement as G, ResponseObject as H, MediaTypeObject as I, SecuritySchemeObject as K, OpenApiDocument as L, buildAtomic as M, buildDescriptor as N, checkContract as O, HttpMethod as P, OperationObject as R, Emitter as S, emit as T, SchemaObject as U, RequestBodyObject as V, SchemaOrBool as W, emitExamples as _, examplesOutputPath as a, emitErrorCodes as b, schemasOutputPath as c, hashJson as d, provenanceLines as f, readSchemas as g, readDocument as h, check as i, DescriptorBuilder as j, buildExamples as k, Provenance as l, SchemaBundle as m, CheckResult as n, generate as o, emitSchemas as p, CodegenConfig as r, generateFiles as s, ArtifactDrift as t, deriveProvenance as u, DocumentedErrorCode as v, detectVerbCollisions as w, readErrorCatalogue as x, ErrorCatalogue as y, ParameterObject as z };
|
|
721
|
-
//# sourceMappingURL=index-
|
|
721
|
+
//# sourceMappingURL=index-Ch2PJH9Y.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-Ch2PJH9Y.d.mts","names":[],"sources":["../src/openapi.ts","../src/build-descriptor.ts","../src/build-examples.ts","../src/contract.ts","../src/emit.ts","../src/error-codes.ts","../src/emit-examples.ts","../src/reader.ts","../src/emit-schemas.ts","../src/provenance.ts","../src/index.ts"],"mappings":";;;;;;AAQA;;;;UAAiB,YAAA;EACf,IAAA;EACA,IAAA;EACA,KAAA;EACA,MAAA;EACA,WAAA;EACA,IAAA;EACA,UAAA,GAAa,MAAA,SAAe,YAAA;EAC5B,KAAA,GAAQ,Y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IsB,QAAA,CAAS,MAAA,EAAQ,aAAA,GAAgB,OAAO;;iBAMxC,aAAA,CAAc,MAAA,EAAQ,aAAA,GAAgB,OAAO;AV5HnE;;;;;;AAAA,iBU+IsB,KAAA,CAAM,MAAA,EAAQ,aAAA,GAAgB,OAAA,CAAQ,WAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as operationExamples, B as PathItemObject, C as VerbCollision, D as MINIMUM_CONTRACT, E as MAXIMUM_CONTRACT, F as InfoObject, G as SecurityRequirement, H as ResponseObject, I as MediaTypeObject, K as SecuritySchemeObject, L as OpenApiDocument, M as buildAtomic, N as buildDescriptor, O as checkContract, P as HttpMethod, R as OperationObject, S as Emitter, T as emit, U as SchemaObject, V as RequestBodyObject, W as SchemaOrBool, _ as emitExamples, a as examplesOutputPath, b as emitErrorCodes, c as schemasOutputPath, d as hashJson, f as provenanceLines, g as readSchemas, h as readDocument, i as check, j as DescriptorBuilder, k as buildExamples, l as Provenance, m as SchemaBundle, n as CheckResult, o as generate, p as emitSchemas, r as CodegenConfig, s as generateFiles, t as ArtifactDrift, u as deriveProvenance, v as DocumentedErrorCode, w as detectVerbCollisions, x as readErrorCatalogue, y as ErrorCatalogue, z as ParameterObject } from "./index-
|
|
1
|
+
import { A as operationExamples, B as PathItemObject, C as VerbCollision, D as MINIMUM_CONTRACT, E as MAXIMUM_CONTRACT, F as InfoObject, G as SecurityRequirement, H as ResponseObject, I as MediaTypeObject, K as SecuritySchemeObject, L as OpenApiDocument, M as buildAtomic, N as buildDescriptor, O as checkContract, P as HttpMethod, R as OperationObject, S as Emitter, T as emit, U as SchemaObject, V as RequestBodyObject, W as SchemaOrBool, _ as emitExamples, a as examplesOutputPath, b as emitErrorCodes, c as schemasOutputPath, d as hashJson, f as provenanceLines, g as readSchemas, h as readDocument, i as check, j as DescriptorBuilder, k as buildExamples, l as Provenance, m as SchemaBundle, n as CheckResult, o as generate, p as emitSchemas, r as CodegenConfig, s as generateFiles, t as ArtifactDrift, u as deriveProvenance, v as DocumentedErrorCode, w as detectVerbCollisions, x as readErrorCatalogue, y as ErrorCatalogue, z as ParameterObject } from "./index-Ch2PJH9Y.mjs";
|
|
2
2
|
export { ArtifactDrift, CheckResult, CodegenConfig, DescriptorBuilder, type DocumentedErrorCode, Emitter, type ErrorCatalogue, type HttpMethod, type InfoObject, MAXIMUM_CONTRACT, MINIMUM_CONTRACT, type MediaTypeObject, type OpenApiDocument, type OperationObject, type ParameterObject, type PathItemObject, type Provenance, type RequestBodyObject, type ResponseObject, type SchemaBundle, type SchemaObject, type SchemaOrBool, type SecurityRequirement, type SecuritySchemeObject, type VerbCollision, buildAtomic, buildDescriptor, buildExamples, check, checkContract, deriveProvenance, detectVerbCollisions, emit, emitErrorCodes, emitExamples, emitSchemas, examplesOutputPath, generate, generateFiles, hashJson, operationExamples, provenanceLines, readDocument, readErrorCatalogue, readSchemas, schemasOutputPath };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as DescriptorBuilder, S as operationExamples, T as buildDescriptor, _ as readErrorCatalogue, a as schemasOutputPath, b as checkContract, c as emitSchemas, d as detectVerbCollisions, f as emit, g as emitErrorCodes, h as provenanceLines, i as generateFiles, l as emitExamples, m as hashJson, n as examplesOutputPath, o as readDocument, p as deriveProvenance, r as generate, s as readSchemas, t as check, u as Emitter, v as MAXIMUM_CONTRACT, w as buildAtomic, x as buildExamples, y as MINIMUM_CONTRACT } from "./src-
|
|
1
|
+
import { C as DescriptorBuilder, S as operationExamples, T as buildDescriptor, _ as readErrorCatalogue, a as schemasOutputPath, b as checkContract, c as emitSchemas, d as detectVerbCollisions, f as emit, g as emitErrorCodes, h as provenanceLines, i as generateFiles, l as emitExamples, m as hashJson, n as examplesOutputPath, o as readDocument, p as deriveProvenance, r as generate, s as readSchemas, t as check, u as Emitter, v as MAXIMUM_CONTRACT, w as buildAtomic, x as buildExamples, y as MINIMUM_CONTRACT } from "./src-D4apiVHe.mjs";
|
|
2
2
|
export { DescriptorBuilder, Emitter, MAXIMUM_CONTRACT, MINIMUM_CONTRACT, buildAtomic, buildDescriptor, buildExamples, check, checkContract, deriveProvenance, detectVerbCollisions, emit, emitErrorCodes, emitExamples, emitSchemas, examplesOutputPath, generate, generateFiles, hashJson, operationExamples, provenanceLines, readDocument, readErrorCatalogue, readSchemas, schemasOutputPath };
|
|
@@ -452,6 +452,9 @@ var DescriptorBuilder = class {
|
|
|
452
452
|
}
|
|
453
453
|
const scopes = this.scopes(op);
|
|
454
454
|
if (scopes !== void 0) action.scopes = scopes;
|
|
455
|
+
const okSchema = okJsonApiSchema(op);
|
|
456
|
+
const mediaType = okSchema === void 0 ? void 0 : locationMediaType(okSchema);
|
|
457
|
+
if (mediaType !== void 0) action.location = { mediaType };
|
|
455
458
|
return action;
|
|
456
459
|
}
|
|
457
460
|
/**
|
|
@@ -533,7 +536,8 @@ var DescriptorBuilder = class {
|
|
|
533
536
|
firstOkJsonApiRef(op) {
|
|
534
537
|
for (const [code, response] of Object.entries(op.responses ?? {})) {
|
|
535
538
|
if (!code.startsWith("2")) continue;
|
|
536
|
-
const
|
|
539
|
+
const schema = response.content?.[JSON_API_MEDIA_TYPE$1]?.schema;
|
|
540
|
+
const ref = schema === void 0 ? void 0 : documentArms(schema)[0]?.$ref;
|
|
537
541
|
if (typeof ref === "string") return ref;
|
|
538
542
|
}
|
|
539
543
|
}
|
|
@@ -976,13 +980,47 @@ function rawContentType(op) {
|
|
|
976
980
|
* (only a `204`).
|
|
977
981
|
*/
|
|
978
982
|
function actionOutput(op) {
|
|
983
|
+
const schema = okJsonApiSchema(op);
|
|
984
|
+
if (schema === void 0) return "none";
|
|
985
|
+
const arm = documentArms(schema)[0];
|
|
986
|
+
if (arm === void 0) return locationMediaType(schema) === void 0 ? "document" : "location";
|
|
987
|
+
return typeof arm.$ref === "string" && refName$1(arm.$ref) === "MetaDocument" ? "meta" : "document";
|
|
988
|
+
}
|
|
989
|
+
/** The JSON:API schema of an operation's first success response that declares one. */
|
|
990
|
+
function okJsonApiSchema(op) {
|
|
979
991
|
for (const [code, response] of Object.entries(op.responses ?? {})) {
|
|
980
992
|
if (!code.startsWith("2")) continue;
|
|
981
993
|
const schema = response.content?.[JSON_API_MEDIA_TYPE$1]?.schema;
|
|
982
|
-
if (schema
|
|
983
|
-
return typeof schema.$ref === "string" && refName$1(schema.$ref) === "MetaDocument" ? "meta" : "document";
|
|
994
|
+
if (schema !== void 0) return schema;
|
|
984
995
|
}
|
|
985
|
-
|
|
996
|
+
}
|
|
997
|
+
/** Whether a schema is a location document: a `$ref` to `LocationDocument`, or an `allOf` with one. */
|
|
998
|
+
function isLocationSchema(schema) {
|
|
999
|
+
const isRef = (entry) => typeof entry.$ref === "string" && refName$1(entry.$ref) === "LocationDocument";
|
|
1000
|
+
return isRef(schema) || (schema.allOf?.some(isRef) ?? false);
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* The documents a success response's schema offers besides a location document (generator
|
|
1004
|
+
* contract 17): each `oneOf` member that isn't one, or the schema itself when it isn't one.
|
|
1005
|
+
*/
|
|
1006
|
+
function documentArms(schema) {
|
|
1007
|
+
return (schema.oneOf ?? [schema]).filter((arm) => !isLocationSchema(arm));
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* The media type a location document's `links.location.type` is fixed to (generator contract
|
|
1011
|
+
* 17), `application/octet-stream` when the schema fixes none, or `undefined` when the schema
|
|
1012
|
+
* offers no location document.
|
|
1013
|
+
*/
|
|
1014
|
+
function locationMediaType(schema) {
|
|
1015
|
+
const location = (schema.oneOf ?? [schema]).find(isLocationSchema);
|
|
1016
|
+
if (location === void 0) return;
|
|
1017
|
+
for (const entry of location.allOf ?? []) {
|
|
1018
|
+
const links = entry.properties?.["links"];
|
|
1019
|
+
const link = isSchema$3(links) ? links.properties?.["location"] : void 0;
|
|
1020
|
+
const type = isSchema$3(link) ? link.properties?.["type"] : void 0;
|
|
1021
|
+
if (isSchema$3(type) && typeof type.const === "string") return type.const;
|
|
1022
|
+
}
|
|
1023
|
+
return "application/octet-stream";
|
|
986
1024
|
}
|
|
987
1025
|
/** Build the {@link ApiDescriptor} from a parsed OpenAPI document. */
|
|
988
1026
|
function buildDescriptor(doc) {
|
|
@@ -1147,7 +1185,7 @@ function buildExamples(doc, descriptor) {
|
|
|
1147
1185
|
/** Below this the document predates the structures this codegen reads. */
|
|
1148
1186
|
const MINIMUM_CONTRACT = 1;
|
|
1149
1187
|
/** Above this the document carries structures this codegen does not read. */
|
|
1150
|
-
const MAXIMUM_CONTRACT =
|
|
1188
|
+
const MAXIMUM_CONTRACT = 17;
|
|
1151
1189
|
/**
|
|
1152
1190
|
* Check the document's `info.x-generator.contract` against the range this codegen reads. A
|
|
1153
1191
|
* document older than the range throws; a newer one returns a warning, because its new
|
|
@@ -1157,8 +1195,8 @@ const MAXIMUM_CONTRACT = 16;
|
|
|
1157
1195
|
function checkContract(doc) {
|
|
1158
1196
|
const contract = doc.info?.["x-generator"]?.contract;
|
|
1159
1197
|
if (typeof contract !== "number") return;
|
|
1160
|
-
if (contract < 1) throw new Error(`the document declares contract ${contract}, which predates what this codegen reads (it supports 1 to
|
|
1161
|
-
if (contract >
|
|
1198
|
+
if (contract < 1) throw new Error(`the document declares contract ${contract}, which predates what this codegen reads (it supports 1 to 17). Use an older codegen release, or regenerate the document from a newer server.`);
|
|
1199
|
+
if (contract > 17) return `the document declares contract ${contract} and this codegen reads up to 17. It describes capabilities that were not generated; upgrade the codegen to pick them up.`;
|
|
1162
1200
|
}
|
|
1163
1201
|
//#endregion
|
|
1164
1202
|
//#region src/declared-links.ts
|
|
@@ -1637,6 +1675,15 @@ function safetyDoc(action) {
|
|
|
1637
1675
|
if (words.length === 0) return;
|
|
1638
1676
|
return `The server declares this action ${words.length === 1 ? words[0] : `${words.slice(0, -1).join(", ")} and ${words.at(-1)}`}.`;
|
|
1639
1677
|
}
|
|
1678
|
+
/**
|
|
1679
|
+
* What an action that answers with a URL returns (generator contract 17), as JSDoc, or
|
|
1680
|
+
* `undefined` for any other action.
|
|
1681
|
+
*/
|
|
1682
|
+
function locationDoc(action) {
|
|
1683
|
+
if (action.location === void 0) return;
|
|
1684
|
+
const serving = `a URL serving \`${action.location.mediaType}\``;
|
|
1685
|
+
return action.output === "location" ? `Returns ${serving} as an \`ActionLocation\`. The client doesn't follow it.` : `May return ${serving} instead, as an \`ActionLocation\`. The client doesn't follow it.`;
|
|
1686
|
+
}
|
|
1640
1687
|
/** A list of scopes as inline code joined into prose: `a`, `b` and `c`. */
|
|
1641
1688
|
function scopeList(scopes) {
|
|
1642
1689
|
const quoted = scopes.map((scope) => `\`${scope}\``);
|
|
@@ -1786,6 +1833,7 @@ var Emitter = class {
|
|
|
1786
1833
|
const op = actionOperation(this.doc, action);
|
|
1787
1834
|
const parts = [
|
|
1788
1835
|
actionDoc(action.path.slice(action.path.lastIndexOf("/") + 1), op),
|
|
1836
|
+
locationDoc(action),
|
|
1789
1837
|
safetyDoc(action),
|
|
1790
1838
|
scopeDoc(action.scopes),
|
|
1791
1839
|
exampleDoc(op)
|
|
@@ -2630,4 +2678,4 @@ async function check(config) {
|
|
|
2630
2678
|
//#endregion
|
|
2631
2679
|
export { DescriptorBuilder as C, operationExamples as S, buildDescriptor as T, readErrorCatalogue as _, schemasOutputPath as a, checkContract as b, emitSchemas as c, detectVerbCollisions as d, emit as f, emitErrorCodes as g, provenanceLines as h, generateFiles as i, emitExamples as l, hashJson as m, examplesOutputPath as n, readDocument as o, deriveProvenance as p, generate as r, readSchemas as s, check as t, Emitter as u, MAXIMUM_CONTRACT as v, buildAtomic as w, buildExamples as x, MINIMUM_CONTRACT as y };
|
|
2632
2680
|
|
|
2633
|
-
//# sourceMappingURL=src-
|
|
2681
|
+
//# sourceMappingURL=src-D4apiVHe.mjs.map
|