@sdk-it/spec 0.45.0 → 0.46.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/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -3
- package/dist/index.js.map +2 -2
- package/dist/lib/find-polymorphic-varients.d.ts.map +1 -1
- package/dist/lib/find-polymorphic-varients.js +5 -10
- package/dist/lib/find-polymorphic-varients.js.map +2 -2
- package/dist/lib/for-each-operation.d.ts +11 -3
- package/dist/lib/for-each-operation.d.ts.map +1 -1
- package/dist/lib/for-each-operation.js +23 -15
- package/dist/lib/for-each-operation.js.map +2 -2
- package/dist/lib/format-name.d.ts.map +1 -1
- package/dist/lib/format-name.js +0 -1
- package/dist/lib/format-name.js.map +2 -2
- package/dist/lib/ir.d.ts +2 -2
- package/dist/lib/ir.d.ts.map +1 -1
- package/dist/lib/ir.js +6 -120
- package/dist/lib/ir.js.map +2 -2
- package/dist/lib/is.d.ts.map +1 -1
- package/dist/lib/is.js +1 -3
- package/dist/lib/is.js.map +2 -2
- package/dist/lib/loaders/postman/postman-converter.d.ts.map +1 -1
- package/dist/lib/loaders/postman/postman-converter.js +1 -11
- package/dist/lib/loaders/postman/postman-converter.js.map +2 -2
- package/dist/lib/options.d.ts +7 -45
- package/dist/lib/options.d.ts.map +1 -1
- package/dist/lib/options.js +26 -28
- package/dist/lib/options.js.map +2 -2
- package/dist/lib/overview-docs/overview-pagination.d.ts +1 -1
- package/dist/lib/overview-docs/overview-pagination.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-pagination.js +1 -1
- package/dist/lib/overview-docs/overview-pagination.js.map +2 -2
- package/dist/lib/pagination/guess-pagination.d.ts.map +1 -1
- package/dist/lib/pagination/guess-pagination.js.map +2 -2
- package/dist/lib/pagination/pagination-result.d.ts.map +1 -1
- package/dist/lib/pagination/pagination-result.js +15 -5
- package/dist/lib/pagination/pagination-result.js.map +2 -2
- package/dist/lib/pagination/pagination.d.ts.map +1 -1
- package/dist/lib/pagination/pagination.js +7 -6
- package/dist/lib/pagination/pagination.js.map +2 -2
- package/dist/lib/processing-plugins/canonicalize-spec.d.ts +3 -0
- package/dist/lib/processing-plugins/canonicalize-spec.d.ts.map +1 -0
- package/dist/lib/processing-plugins/canonicalize-spec.js +29 -0
- package/dist/lib/processing-plugins/canonicalize-spec.js.map +7 -0
- package/dist/lib/processing-plugins/create-default-processing-plugins.d.ts +5 -0
- package/dist/lib/processing-plugins/create-default-processing-plugins.d.ts.map +1 -0
- package/dist/lib/processing-plugins/create-default-processing-plugins.js +30 -0
- package/dist/lib/processing-plugins/create-default-processing-plugins.js.map +7 -0
- package/dist/lib/processing-plugins/enrich-examples.d.ts +25 -0
- package/dist/lib/processing-plugins/enrich-examples.d.ts.map +1 -0
- package/dist/lib/processing-plugins/enrich-examples.js +93 -0
- package/dist/lib/processing-plugins/enrich-examples.js.map +7 -0
- package/dist/lib/processing-plugins/extract-inline-schemas.d.ts +3 -0
- package/dist/lib/processing-plugins/extract-inline-schemas.d.ts.map +1 -0
- package/dist/lib/processing-plugins/extract-inline-schemas.js +14 -0
- package/dist/lib/processing-plugins/extract-inline-schemas.js.map +7 -0
- package/dist/lib/processing-plugins/extract-overview-docs.d.ts +3 -0
- package/dist/lib/processing-plugins/extract-overview-docs.d.ts.map +1 -0
- package/dist/lib/processing-plugins/extract-overview-docs.js +13 -0
- package/dist/lib/processing-plugins/extract-overview-docs.js.map +7 -0
- package/dist/lib/processing-plugins/index.d.ts +14 -0
- package/dist/lib/processing-plugins/index.d.ts.map +1 -0
- package/dist/lib/processing-plugins/index.js +14 -0
- package/dist/lib/processing-plugins/index.js.map +7 -0
- package/dist/lib/processing-plugins/infer-pagination.d.ts +3 -0
- package/dist/lib/processing-plugins/infer-pagination.d.ts.map +1 -0
- package/dist/lib/processing-plugins/infer-pagination.js +21 -0
- package/dist/lib/processing-plugins/infer-pagination.js.map +7 -0
- package/dist/lib/processing-plugins/normalize-operation-ids.d.ts +3 -0
- package/dist/lib/processing-plugins/normalize-operation-ids.d.ts.map +1 -0
- package/dist/lib/processing-plugins/normalize-operation-ids.js +74 -0
- package/dist/lib/processing-plugins/normalize-operation-ids.js.map +7 -0
- package/dist/lib/processing-plugins/normalize-parameters.d.ts +3 -0
- package/dist/lib/processing-plugins/normalize-parameters.d.ts.map +1 -0
- package/dist/lib/processing-plugins/normalize-parameters.js +29 -0
- package/dist/lib/processing-plugins/normalize-parameters.js.map +7 -0
- package/dist/lib/processing-plugins/normalize-paths.d.ts +3 -0
- package/dist/lib/processing-plugins/normalize-paths.d.ts.map +1 -0
- package/dist/lib/processing-plugins/normalize-paths.js +67 -0
- package/dist/lib/processing-plugins/normalize-paths.js.map +7 -0
- package/dist/lib/processing-plugins/normalize-request-bodies.d.ts +3 -0
- package/dist/lib/processing-plugins/normalize-request-bodies.d.ts.map +1 -0
- package/dist/lib/processing-plugins/normalize-request-bodies.js +44 -0
- package/dist/lib/processing-plugins/normalize-request-bodies.js.map +7 -0
- package/dist/lib/processing-plugins/normalize-responses.d.ts +3 -0
- package/dist/lib/processing-plugins/normalize-responses.d.ts.map +1 -0
- package/dist/lib/processing-plugins/normalize-responses.js +38 -0
- package/dist/lib/processing-plugins/normalize-responses.js.map +7 -0
- package/dist/lib/processing-plugins/normalize-schemas.d.ts +3 -0
- package/dist/lib/processing-plugins/normalize-schemas.d.ts.map +1 -0
- package/dist/lib/processing-plugins/normalize-schemas.js +13 -0
- package/dist/lib/processing-plugins/normalize-schemas.js.map +7 -0
- package/dist/lib/processing-plugins/normalize-tags.d.ts +3 -0
- package/dist/lib/processing-plugins/normalize-tags.d.ts.map +1 -0
- package/dist/lib/processing-plugins/normalize-tags.js +18 -0
- package/dist/lib/processing-plugins/normalize-tags.js.map +7 -0
- package/dist/lib/processing.d.ts +33 -0
- package/dist/lib/processing.d.ts.map +1 -0
- package/dist/lib/processing.js +41 -0
- package/dist/lib/processing.js.map +7 -0
- package/dist/lib/reserved-keywords.d.ts.map +1 -1
- package/dist/lib/reserved-keywords.js +18 -1
- package/dist/lib/reserved-keywords.js.map +2 -2
- package/dist/lib/tag.js +2 -2
- package/dist/lib/tag.js.map +2 -2
- package/dist/lib/tune-request-body.d.ts.map +1 -1
- package/dist/lib/tune-request-body.js +22 -12
- package/dist/lib/tune-request-body.js.map +2 -2
- package/dist/lib/tune-response.d.ts.map +1 -1
- package/dist/lib/tune-response.js +16 -12
- package/dist/lib/tune-response.js.map +2 -2
- package/dist/lib/tune.d.ts.map +1 -1
- package/dist/lib/tune.js +31 -7
- package/dist/lib/tune.js.map +2 -2
- package/dist/lib/types.d.ts +4 -1
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/walk-schemas.d.ts +8 -0
- package/dist/lib/walk-schemas.d.ts.map +1 -0
- package/dist/lib/walk-schemas.js +51 -0
- package/dist/lib/walk-schemas.js.map +7 -0
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/tune-request-body.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n OperationObject,\n ParameterObject,\n RequestBodyObject,\n SchemaObject,\n SecurityRequirementObject,\n} from 'openapi3-ts/oas31';\n\nimport { followRef, isRef } from '@sdk-it/core/ref.js';\nimport { isEmpty } from '@sdk-it/core/utils.js';\n\nimport { findUniqueSchemaName } from './find-unique-schema-name.js';\nimport { securityToOptions } from './security.js';\nimport type { IR, OurRequestBodyObject } from './types.js';\n\nexport function patchParameters(\n spec: IR,\n schema: SchemaObject,\n parameters: ParameterObject[],\n security: SecurityRequirementObject[],\n) {\n const securityOptions = securityToOptions(\n spec,\n security,\n spec.components.securitySchemes,\n );\n\n
|
|
5
|
-
"mappings": "AAQA,SAAS,WAAW,aAAa;AACjC,SAAS,eAAe;AAExB,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAG3B,SAAS,gBACd,MACA,QACA,YACA,UACA;AACA,QAAM,kBAAkB;AAAA,IACtB;AAAA,IACA;AAAA,IACA,KAAK,WAAW;AAAA,EAClB;AAEA,
|
|
4
|
+
"sourcesContent": ["import type {\n OperationObject,\n ParameterObject,\n RequestBodyObject,\n SchemaObject,\n SecurityRequirementObject,\n} from 'openapi3-ts/oas31';\n\nimport { followRef, isRef } from '@sdk-it/core/ref.js';\nimport { isEmpty } from '@sdk-it/core/utils.js';\n\nimport { findUniqueSchemaName } from './find-unique-schema-name.js';\nimport { securityToOptions } from './security.js';\nimport type { IR, OurRequestBodyObject } from './types.js';\n\nexport function patchParameters(\n spec: IR,\n schema: SchemaObject,\n parameters: ParameterObject[],\n security: SecurityRequirementObject[],\n) {\n const securityOptions = securityToOptions(\n spec,\n security,\n spec.components.securitySchemes,\n );\n\n const required = new Set(\n Array.isArray(schema.required) ? schema.required : [],\n );\n schema['x-properties'] ??= {};\n for (const param of parameters) {\n if (param.required) {\n required.add(param.name);\n }\n schema['x-properties'][param.name] = {\n 'x-in': param.in,\n ...(isRef(param.schema)\n ? followRef<SchemaObject>(spec, param.schema.$ref)\n : (param.schema ?? { type: 'string' })),\n };\n }\n for (const param of securityOptions) {\n required.delete(param.name);\n schema['x-properties'][param.name] = {\n 'x-in': 'header',\n ...(isRef(param.schema)\n ? followRef<SchemaObject>(spec, param.schema.$ref)\n : (param.schema ?? { type: 'string' })),\n };\n }\n schema['x-required'] = [...required];\n}\n\nexport function tuneRequestBody(\n spec: IR,\n operationId: string,\n operation: OperationObject,\n parameters: ParameterObject[],\n security: SecurityRequirementObject[],\n): OurRequestBodyObject {\n const requestBodySource = isRef(operation.requestBody)\n ? followRef<RequestBodyObject>(spec, operation.requestBody.$ref)\n : (operation.requestBody ?? {\n content: {},\n required: false,\n });\n const requestBody = structuredClone(requestBodySource);\n if (isEmpty(requestBody.content)) {\n const inputName = findUniqueSchemaName(spec, operationId, [\n 'input',\n 'payload',\n 'request',\n ]);\n const schema: SchemaObject = {\n 'x-inputname': inputName,\n 'x-requestbody': true,\n };\n patchParameters(spec, schema, parameters, security);\n const tuned: OurRequestBodyObject = {\n ...requestBody,\n content: {\n 'application/empty': {\n schema: { $ref: `#/components/schemas/${inputName}` },\n },\n },\n };\n\n spec.components.schemas[inputName] = schema;\n return tuned;\n }\n for (const contentType in requestBody.content) {\n const mediaType = requestBody.content[contentType];\n const inputName = findUniqueSchemaName(spec, operationId, [\n 'input',\n 'payload',\n 'request',\n ]);\n let schema: SchemaObject | undefined;\n\n switch (true) {\n case isRef(mediaType.schema):\n schema = structuredClone(\n followRef<SchemaObject>(spec, mediaType.schema.$ref),\n );\n // we cannot use the model name as inputName as it might be used in other places that are not request bodies\n // inputName = parseRef(mediaType.schema.$ref).model;\n break;\n case isEmpty(mediaType.schema):\n schema ??= {}; // default to empty schema if not defined\n console.warn(\n `Request body schema for content type \"${contentType}\" is empty.`,\n );\n break;\n default:\n schema = structuredClone(mediaType.schema);\n break;\n }\n\n patchParameters(spec, schema, parameters, security);\n spec.components.schemas[inputName] = {\n ...schema,\n 'x-requestbody': true,\n 'x-inputname': inputName,\n };\n\n requestBody.content[contentType].schema = {\n $ref: `#/components/schemas/${inputName}`,\n };\n }\n return requestBody as OurRequestBodyObject;\n}\n"],
|
|
5
|
+
"mappings": "AAQA,SAAS,WAAW,aAAa;AACjC,SAAS,eAAe;AAExB,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAG3B,SAAS,gBACd,MACA,QACA,YACA,UACA;AACA,QAAM,kBAAkB;AAAA,IACtB;AAAA,IACA;AAAA,IACA,KAAK,WAAW;AAAA,EAClB;AAEA,QAAM,WAAW,IAAI;AAAA,IACnB,MAAM,QAAQ,OAAO,QAAQ,IAAI,OAAO,WAAW,CAAC;AAAA,EACtD;AACA,SAAO,cAAc,MAAM,CAAC;AAC5B,aAAW,SAAS,YAAY;AAC9B,QAAI,MAAM,UAAU;AAClB,eAAS,IAAI,MAAM,IAAI;AAAA,IACzB;AACA,WAAO,cAAc,EAAE,MAAM,IAAI,IAAI;AAAA,MACnC,Q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A,MACxD;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AACD,QAAI;AAEJ,YAAQ,MAAM;AAAA,MACZ,KAAK,MAAM,UAAU,MAAM;AACzB,iBAAS;AAAA,UACP,UAAwB,MAAM,UAAU,OAAO,IAAI;AAAA,QACrD;AAGA;AAAA,MACF,KAAK,QAAQ,UAAU,MAAM;AAC3B,mBAAW,CAAC;AACZ,gBAAQ;AAAA,UACN,yCAAyC,WAAW;AAAA,QACtD;AACA;AAAA,MACF;AACE,iBAAS,gBAAgB,UAAU,MAAM;AACzC;AAAA,IACJ;AAEA,oBAAgB,MAAM,QAAQ,YAAY,QAAQ;AAClD,SAAK,WAAW,QAAQ,SAAS,IAAI;AAAA,MACnC,GAAG;AAAA,MACH,iBAAiB;AAAA,MACjB,eAAe;AAAA,IACjB;AAEA,gBAAY,QAAQ,WAAW,EAAE,SAAS;AAAA,MACxC,MAAM,wBAAwB,SAAS;AAAA,IACzC;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tune-response.d.ts","sourceRoot":"","sources":["../../src/lib/tune-response.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,mBAAmB,CAAC;AAc3B,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,EAAE,EACR,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,eAAe,EAC1B,eAAe,CAAC,EAAE,eAAe,+
|
|
1
|
+
{"version":3,"file":"tune-response.d.ts","sourceRoot":"","sources":["../../src/lib/tune-response.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,mBAAmB,CAAC;AAc3B,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,EAAE,EACR,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,eAAe,EAC1B,eAAe,CAAC,EAAE,eAAe,+CAyIlC"}
|
|
@@ -16,14 +16,10 @@ function resolveResponses(spec, operationId, operation, responsesConfig) {
|
|
|
16
16
|
operation.responses ??= {};
|
|
17
17
|
let foundSuccessResponse = false;
|
|
18
18
|
for (const status in responses) {
|
|
19
|
-
if (status === "default") {
|
|
20
|
-
delete responses[status];
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
19
|
operation.responses[status] = structuredClone(
|
|
24
20
|
resolveRef(spec, responses[status])
|
|
25
21
|
);
|
|
26
|
-
if (isSuccessStatusCode(status)) {
|
|
22
|
+
if (status !== "default" && isSuccessStatusCode(status)) {
|
|
27
23
|
foundSuccessResponse = true;
|
|
28
24
|
}
|
|
29
25
|
}
|
|
@@ -40,11 +36,6 @@ function resolveResponses(spec, operationId, operation, responsesConfig) {
|
|
|
40
36
|
for (const status in operation.responses) {
|
|
41
37
|
const response = operation.responses[status];
|
|
42
38
|
const statusCode = +status;
|
|
43
|
-
const outputName = statusCode !== 200 ? pascalcase(operationId) + status : findUniqueSchemaName(spec, operationId, [
|
|
44
|
-
"output",
|
|
45
|
-
"payload",
|
|
46
|
-
"result"
|
|
47
|
-
]);
|
|
48
39
|
if (!responsesConfig?.flattenErrorResponses) {
|
|
49
40
|
if (!isSuccessStatusCode(status)) {
|
|
50
41
|
continue;
|
|
@@ -55,7 +46,7 @@ function resolveResponses(spec, operationId, operation, responsesConfig) {
|
|
|
55
46
|
"application/octet-stream": {}
|
|
56
47
|
};
|
|
57
48
|
}
|
|
58
|
-
|
|
49
|
+
let responseName;
|
|
59
50
|
for (const [contentType, mediaType] of Object.entries(
|
|
60
51
|
response.content
|
|
61
52
|
)) {
|
|
@@ -67,9 +58,19 @@ function resolveResponses(spec, operationId, operation, responsesConfig) {
|
|
|
67
58
|
// because they are supposed to be in a separate file only inlined
|
|
68
59
|
// schemas are grouped by operationId
|
|
69
60
|
});
|
|
70
|
-
|
|
61
|
+
responseName ??= model;
|
|
71
62
|
continue;
|
|
72
63
|
}
|
|
64
|
+
const outputName = statusCode !== 200 ? findUniqueSchemaName(spec, `${pascalcase(operationId)}${status}`, [
|
|
65
|
+
"output",
|
|
66
|
+
"payload",
|
|
67
|
+
"result"
|
|
68
|
+
]) : findUniqueSchemaName(spec, operationId, [
|
|
69
|
+
"output",
|
|
70
|
+
"payload",
|
|
71
|
+
"result"
|
|
72
|
+
]);
|
|
73
|
+
responseName ??= outputName;
|
|
73
74
|
const isSse = isSseContentType(contentType);
|
|
74
75
|
const normalizedContentType = normalizeContentType(contentType);
|
|
75
76
|
const hasContentDisposition = hasHeader(
|
|
@@ -108,6 +109,9 @@ function resolveResponses(spec, operationId, operation, responsesConfig) {
|
|
|
108
109
|
$ref: `#/components/schemas/${outputName}`
|
|
109
110
|
};
|
|
110
111
|
}
|
|
112
|
+
if (responseName) {
|
|
113
|
+
response["x-response-name"] = responseName;
|
|
114
|
+
}
|
|
111
115
|
}
|
|
112
116
|
return operation.responses;
|
|
113
117
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/tune-response.ts"],
|
|
4
|
-
"sourcesContent": ["import { parse as parseContentType } from 'fast-content-type-parse';\nimport type {\n MediaTypeObject,\n OperationObject,\n ResponseObject,\n} from 'openapi3-ts/oas31';\n\nimport { isRef, parseRef, resolveRef } from '@sdk-it/core/ref.js';\nimport { isEmpty, pascalcase } from '@sdk-it/core/utils.js';\n\nimport { findUniqueSchemaName } from './find-unique-schema-name.js';\nimport {\n isBinaryContentType,\n isSseContentType,\n isStreamingContentType,\n isSuccessStatusCode,\n isTextContentType,\n parseJsonContentType,\n} from './is.js';\nimport { type ResponsesConfig } from './options.js';\nimport type { IR } from './types.js';\n\nexport function resolveResponses(\n spec: IR,\n operationId: string,\n operation: OperationObject,\n responsesConfig?: ResponsesConfig,\n) {\n const responses = operation.responses ?? {};\n operation.responses ??= {};\n let foundSuccessResponse = false;\n for (const status in responses) {\n
|
|
5
|
-
"mappings": "AAAA,SAAS,SAAS,wBAAwB;AAO1C,SAAS,OAAO,UAAU,kBAAkB;AAC5C,SAAS,SAAS,kBAAkB;AAEpC,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,eAAqC;AAG9B,SAAS,iBACd,MACA,aACA,WACA,iBACA;AACA,QAAM,YAAY,UAAU,aAAa,CAAC;AAC1C,YAAU,cAAc,CAAC;AACzB,MAAI,uBAAuB;AAC3B,aAAW,UAAU,WAAW;
|
|
4
|
+
"sourcesContent": ["import { parse as parseContentType } from 'fast-content-type-parse';\nimport type {\n MediaTypeObject,\n OperationObject,\n ResponseObject,\n} from 'openapi3-ts/oas31';\n\nimport { isRef, parseRef, resolveRef } from '@sdk-it/core/ref.js';\nimport { isEmpty, pascalcase } from '@sdk-it/core/utils.js';\n\nimport { findUniqueSchemaName } from './find-unique-schema-name.js';\nimport {\n isBinaryContentType,\n isSseContentType,\n isStreamingContentType,\n isSuccessStatusCode,\n isTextContentType,\n parseJsonContentType,\n} from './is.js';\nimport { type ResponsesConfig } from './options.js';\nimport type { IR } from './types.js';\n\nexport function resolveResponses(\n spec: IR,\n operationId: string,\n operation: OperationObject,\n responsesConfig?: ResponsesConfig,\n) {\n const responses = operation.responses ?? {};\n operation.responses ??= {};\n let foundSuccessResponse = false;\n for (const status in responses) {\n // use structuredClone to avoid mutating a response object\n // that is referenced by multiple operations\n operation.responses[status] = structuredClone(\n resolveRef<ResponseObject>(spec, responses[status]),\n );\n\n if (status !== 'default' && isSuccessStatusCode(status)) {\n foundSuccessResponse = true;\n }\n }\n\n if (!foundSuccessResponse) {\n operation.responses['200'] = {\n description: 'OK',\n content: {\n 'application/json': {\n schema: {},\n },\n },\n };\n }\n\n for (const status in operation.responses) {\n const response = operation.responses[status] as ResponseObject;\n const statusCode = +status;\n\n if (!responsesConfig?.flattenErrorResponses) {\n if (!isSuccessStatusCode(status)) {\n continue;\n }\n }\n\n if (isEmpty(response.content)) {\n response.content = {\n 'application/octet-stream': {},\n };\n }\n\n // if (isErrorStatusCode(status)) {\n // const mediaType = response.content?.['application/json'];\n // if (mediaType && isRef(mediaType.schema)) {\n // const { model } = parseRef(mediaType.schema.$ref);\n // Object.assign(config.spec.components.schemas[model], {\n // 'x-responsebody': true,\n // // do not assign response ref to a group\n // // because they are supposed to be in a separate file only inlined\n // // schemas are grouped by operationId\n // });\n // response['x-response-name'] = model;\n // }\n // continue;\n // }\n\n let responseName: string | undefined;\n for (const [contentType, mediaType] of Object.entries(\n response.content as Record<string, MediaTypeObject>,\n )) {\n if (isRef(mediaType.schema)) {\n const { model } = parseRef(mediaType.schema.$ref);\n Object.assign(spec.components.schemas[model], {\n 'x-responsebody': true,\n // do not assign response ref to a group\n // because they are supposed to be in a separate file only inlined\n // schemas are grouped by operationId\n });\n responseName ??= model;\n continue;\n }\n const outputName =\n statusCode !== 200\n ? findUniqueSchemaName(spec, `${pascalcase(operationId)}${status}`, [\n 'output',\n 'payload',\n 'result',\n ])\n : findUniqueSchemaName(spec, operationId, [\n 'output',\n 'payload',\n 'result',\n ]);\n responseName ??= outputName;\n const isSse = isSseContentType(contentType);\n const normalizedContentType = normalizeContentType(contentType);\n const hasContentDisposition = hasHeader(\n response.headers,\n 'Content-Disposition',\n );\n const isBinary =\n isBinaryContentType(contentType) ||\n (isStreamingContentType(normalizedContentType) &&\n hasContentDisposition);\n const isText = isTextContentType(contentType);\n\n if (parseJsonContentType(contentType)) {\n if (isEmpty(mediaType.schema)) {\n // add \"additionalProperties\" because we're certain this is a response body is of json type\n spec.components.schemas[outputName] = {\n type: 'object',\n additionalProperties: true,\n };\n }\n } else {\n if (isEmpty(mediaType.schema) && (isText || isBinary)) {\n mediaType.schema = {\n type: 'string',\n ...(isBinary ? { format: 'binary' } : {}),\n };\n }\n spec.components.schemas[outputName] = {\n ...spec.components.schemas[outputName],\n 'x-stream': isSse || (!isText && !isBinary),\n ...(isSse ? { 'x-sse': true } : {}),\n };\n }\n\n spec.components.schemas[outputName] = {\n ...spec.components.schemas[outputName],\n ...mediaType.schema,\n 'x-responsebody': true,\n 'x-response-group': operationId,\n };\n operation.responses[status].content[contentType].schema = {\n $ref: `#/components/schemas/${outputName}`,\n };\n }\n if (responseName) {\n response['x-response-name'] = responseName;\n }\n }\n\n return operation.responses;\n}\n\nfunction normalizeContentType(contentType: string) {\n try {\n return parseContentType(contentType)?.type?.toLowerCase();\n } catch {\n return contentType.split(';')[0]?.trim().toLowerCase();\n }\n}\n\nfunction hasHeader(headers: ResponseObject['headers'], name: string) {\n if (!headers) {\n return false;\n }\n const target = name.toLowerCase();\n return Object.keys(headers).some((key) => key.toLowerCase() === target);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS,wBAAwB;AAO1C,SAAS,OAAO,UAAU,kBAAkB;AAC5C,SAAS,SAAS,kBAAkB;AAEpC,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,eAAqC;AAG9B,SAAS,iBACd,MACA,aACA,WACA,iBACA;AACA,QAAM,YAAY,UAAU,aAAa,CAAC;AAC1C,YAAU,cAAc,CAAC;AACzB,MAAI,uBAAuB;AAC3B,aAAW,UAAU,WAAW;AAG9B,cAAU,UAAU,MAAM,IAAI;AAAA,MAC5B,WAA2B,MAAM,UAAU,MAAM,CAAC;AAAA,IACpD;AAEA,QAAI,WAAW,aAAa,oBAAoB,MAAM,GAAG;AACvD,6BAAuB;AAAA,IACzB;AAAA,EACF;AAEA,MAAI,CAAC,sBAAsB;AACzB,cAAU,UAAU,KAAK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,YAAY,MAAM,MAAM;AACxE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/lib/tune.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tune.d.ts","sourceRoot":"","sources":["../../src/lib/tune.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAgB3B,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,wBAAgB,OAAO,CACrB,IAAI,EAAE,EAAE,EACR,OAAO,EAAE,CAAC,YAAY,GAAG,eAAe,CAAC,EAAE,EAC3C,OAAO,cAAoB,
|
|
1
|
+
{"version":3,"file":"tune.d.ts","sourceRoot":"","sources":["../../src/lib/tune.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAgB3B,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,wBAAgB,OAAO,CACrB,IAAI,EAAE,EAAE,EACR,OAAO,EAAE,CAAC,YAAY,GAAG,eAAe,CAAC,EAAE,EAC3C,OAAO,cAAoB,QAqL5B;AAED,KAAK,IAAI,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,EAAE,CAAC;AAEpD,wBAAgB,UAAU,CACxB,IAAI,EAAE,EAAE,EACR,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,eAAe,CAAC,EACvD,IAAI,EAAE,IAAI,QA4JX;AA2CD,wBAAgB,WAAW,CACzB,MAAM,EAAE,YAAY,EACpB,WAAW,UAAO,GACjB,gBAAgB,EAAE,CAUpB"}
|
package/dist/lib/tune.js
CHANGED
|
@@ -82,9 +82,26 @@ function fixSpec(spec, schemas, visited = /* @__PURE__ */ new Set()) {
|
|
|
82
82
|
}
|
|
83
83
|
merge(
|
|
84
84
|
schema,
|
|
85
|
-
...resolved.map((
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
...resolved.map((resolvedSchema, index) => {
|
|
86
|
+
const sourceSchema = schemas2[index];
|
|
87
|
+
if (isRef(sourceSchema)) {
|
|
88
|
+
if (visited.has(sourceSchema.$ref)) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`Circular allOf reference detected: ${[
|
|
91
|
+
...visited,
|
|
92
|
+
sourceSchema.$ref
|
|
93
|
+
].join(" -> ")}`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
fixSpec(
|
|
97
|
+
spec,
|
|
98
|
+
[resolvedSchema],
|
|
99
|
+
new Set(visited).add(sourceSchema.$ref)
|
|
100
|
+
);
|
|
101
|
+
} else {
|
|
102
|
+
fixSpec(spec, [resolvedSchema], visited);
|
|
103
|
+
}
|
|
104
|
+
return resolvedSchema;
|
|
88
105
|
})
|
|
89
106
|
);
|
|
90
107
|
delete schema.allOf;
|
|
@@ -97,8 +114,6 @@ function fixSpec(spec, schemas, visited = /* @__PURE__ */ new Set()) {
|
|
|
97
114
|
Object.values(schema.additionalProperties.properties),
|
|
98
115
|
visited
|
|
99
116
|
);
|
|
100
|
-
Object.assign(schema, schema.additionalProperties);
|
|
101
|
-
delete schema.additionalProperties;
|
|
102
117
|
}
|
|
103
118
|
for (const kind of ["oneOf", "anyOf"]) {
|
|
104
119
|
if (!isEmpty(schema[kind])) {
|
|
@@ -170,7 +185,11 @@ function expandSpec(spec, schemas, refs) {
|
|
|
170
185
|
for (const [propName, value] of Object.entries(properties)) {
|
|
171
186
|
if (isRef(value)) continue;
|
|
172
187
|
const fixedPropName = propName.replace("[]", "");
|
|
173
|
-
const refName =
|
|
188
|
+
const refName = findUniqueSchemaName(
|
|
189
|
+
spec,
|
|
190
|
+
pascalcase(joinSkipDigits([name, fixedPropName], " ")),
|
|
191
|
+
["Property", "Field", "Attribute"]
|
|
192
|
+
);
|
|
174
193
|
if (!isEmpty(value.properties)) {
|
|
175
194
|
spec.components.schemas[refName] = value;
|
|
176
195
|
properties[propName] = { $ref: `#/components/schemas/${refName}` };
|
|
@@ -197,7 +216,11 @@ function expandSpec(spec, schemas, refs) {
|
|
|
197
216
|
for (const [propName, value] of Object.entries(properties)) {
|
|
198
217
|
if (isRef(value)) continue;
|
|
199
218
|
const fixedPropName = propName.replace("[]", "");
|
|
200
|
-
const refName =
|
|
219
|
+
const refName = findUniqueSchemaName(
|
|
220
|
+
spec,
|
|
221
|
+
pascalcase(joinSkipDigits([name, fixedPropName], " ")),
|
|
222
|
+
["Property", "Field", "Attribute"]
|
|
223
|
+
);
|
|
201
224
|
if (!isEmpty(value.properties)) {
|
|
202
225
|
spec.components.schemas[refName] = value;
|
|
203
226
|
properties[propName] = { $ref: `#/components/schemas/${refName}` };
|
|
@@ -267,6 +290,7 @@ function expandOneOf(spec, name, schema, refs, kind) {
|
|
|
267
290
|
["Varient"]
|
|
268
291
|
);
|
|
269
292
|
if (varientSchema.type === "object") {
|
|
293
|
+
spec.components.schemas[refName] = varientSchema;
|
|
270
294
|
expandSpec(spec, { [refName]: varientSchema }, refs);
|
|
271
295
|
schema[kind][varient.position] = {
|
|
272
296
|
$ref: `#/components/schemas/${refName}`
|
package/dist/lib/tune.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/tune.ts"],
|
|
4
|
-
"sourcesContent": ["import { merge, uniq } from 'lodash-es';\nimport assert from 'node:assert';\nimport type {\n ReferenceObject,\n SchemaObject,\n SchemaObjectType,\n} from 'openapi3-ts/oas31';\n\nimport {\n isEmpty,\n isRef,\n joinSkipDigits,\n notRef,\n pascalcase,\n resolveRef,\n snakecase,\n} from '@sdk-it/core';\n\nimport { type Varient, findVarients } from './find-polymorphic-varients.js';\nimport { findUniqueSchemaName } from './find-unique-schema-name.js';\nimport { formatName } from './format-name.js';\nimport { isPrimitiveSchema } from './is-primitive-schema.js';\nimport type { IR } from './types.js';\n\nexport function fixSpec(\n spec: IR,\n schemas: (SchemaObject | ReferenceObject)[],\n visited = new Set<string>(),\n) {\n for (const schema of schemas) {\n if (isRef(schema)) continue;\n\n if (!isEmpty(schema.properties)) {\n schema.type = 'object';\n delete schema.oneOf;\n delete schema.anyOf;\n fixSpec(spec, Object.values(schema.properties), visited);\n // path param are required and if it happens to have\n // body with defaults then zod would break off. so flat the defaults from object itself to properties\n for (const [key, value] of Object.entries(schema.properties)) {\n if (notRef(value) && isPrimitiveSchema(value)) {\n value.default ??= schema.default?.[key];\n delete schema.default?.[key];\n }\n }\n delete schema.default; // default should not be in properties\n }\n\n if (!isEmpty(schema['x-properties'])) {\n fixSpec(spec, Object.values(schema['x-properties']), visited);\n }\n\n if (!isEmpty(schema.items)) {\n delete schema.oneOf;\n delete schema.anyOf;\n schema.type = 'array';\n fixSpec(spec, [schema.items], visited);\n const items = resolveRef<SchemaObject>(spec, schema.items);\n if (Array.isArray(items.default)) {\n schema.default ??= structuredClone(items.default);\n }\n delete items.default; // default should not be in items\n }\n\n if (!isEmpty(schema.anyOf) && !isEmpty(schema.oneOf)) {\n delete schema.anyOf;\n }\n\n if (isEmpty(schema.enum)) {\n delete schema.enum;\n }\n\n if (!isEmpty(schema.enum)) {\n if (schema.enum.length === 1) {\n schema.const = schema.enum[0];\n delete schema.enum;\n } else {\n const valuesSet = new Set<string>();\n const valuesList = [];\n for (const it of schema.enum) {\n const formattedValue = formatName(snakecase(formatName(it)));\n if (!valuesSet.has(formattedValue)) {\n valuesSet.add(formattedValue);\n valuesList.push(it);\n }\n }\n schema.enum = valuesList;\n }\n delete schema.allOf;\n }\n\n if (schema.const !== undefined) {\n schema.default = schema.const;\n }\n\n if (!isEmpty(schema.allOf)) {\n const schemas = schema.allOf;\n // if (schemas.length === 1) {\n // fixSpec(spec, [schemas[0]], visited);\n // Object.assign(schema, schemas[0]);\n // delete schema.allOf;\n // } else {\n // }\n const resolved = schemas.map((it) => resolveRef<SchemaObject>(spec, it));\n const hasObjects = resolved.some((it) => it.type === 'object');\n const hasOtherTypes = resolved.some(\n (it) => it.type && it.type !== 'object',\n );\n if (hasObjects && hasOtherTypes) {\n assert(false, `allOf must be an object`);\n }\n merge(\n schema,\n ...resolved.map((it) => {\n fixSpec(spec, [it], visited);\n return it;\n }),\n );\n delete schema.allOf;\n } else {\n delete schema.allOf;\n }\n\n if (\n schema.type === 'object' &&\n isEmpty(schema.properties) &&\n typeof schema.additionalProperties === 'object' &&\n !isEmpty(schema.additionalProperties) &&\n notRef(schema.additionalProperties) &&\n !isEmpty(schema.additionalProperties.properties)\n ) {\n // additionalProperties is of type object and properties is empty\n fixSpec(\n spec,\n Object.values(schema.additionalProperties.properties),\n visited,\n );\n Object.assign(schema, schema.additionalProperties);\n delete schema.additionalProperties;\n }\n\n for (const kind of ['oneOf', 'anyOf'] as const) {\n if (!isEmpty(schema[kind])) {\n delete schema.type; // type is not allowed with oneOf or anyOf\n fixSpec(spec, schema[kind], visited);\n if (isEmpty(schema[kind])) {\n // fixSpec can remove oneOf or anyOf if it has no items so we need to check again\n // after fixing\n continue;\n }\n\n let enumSchemaIndex = -1;\n const enumValues: string[] = [];\n for (let idx = 0; idx < schema[kind].length; idx++) {\n const item = schema[kind][idx];\n // just handle non ref for now\n if (notRef(item) && item.type === 'string') {\n // if enum equal one it'd already have been converted to const so check for more than one\n if (item.enum && item.enum.length > 1) {\n // foundEnum = true;\n enumValues.push(...item.enum);\n if (enumSchemaIndex === -1) {\n enumSchemaIndex = idx;\n }\n }\n }\n }\n if (enumSchemaIndex !== -1) {\n const enumSchema = schema[kind][enumSchemaIndex];\n if (notRef(enumSchema)) {\n enumSchema.enum = uniq(enumValues);\n }\n // delete the other schemas that have enum\n schema[kind] = schema[kind].filter(\n (it, idx) => idx === enumSchemaIndex || isRef(it),\n );\n }\n const otherTypes = schema[kind].filter(\n (it) => resolveRef<SchemaObject>(spec, it).type !== 'null',\n );\n if (otherTypes.length === 1) {\n Object.assign(schema, otherTypes[0]);\n delete schema[kind];\n continue;\n }\n\n schema['x-varients'] = findVarients(spec, schema[kind]);\n } else {\n delete schema[kind];\n }\n }\n }\n}\n\ntype Refs = { name: string; value: SchemaObject }[];\n\nexport function expandSpec(\n spec: IR,\n schemas: Record<string, SchemaObject | ReferenceObject>,\n refs: Refs,\n) {\n for (const [name, schema] of Object.entries(schemas)) {\n if (isRef(schema)) continue;\n\n if (!isEmpty(schema.properties)) {\n if (!isEmpty(schema.oneOf)) {\n for (const oneOfIdx in schema.oneOf) {\n const oneOf = schema.oneOf[oneOfIdx];\n if (isRef(oneOf)) continue;\n for (const key of ['properties', 'x-properties'] as const) {\n if (!isEmpty(oneOf.required) && schema[key]) {\n schema.oneOf[oneOfIdx] = schema[key][oneOf.required[0]];\n }\n }\n }\n delete schema.type;\n expandSpec(spec, schemas, refs);\n continue;\n }\n if (schema.additionalProperties) {\n continue;\n }\n // refs.push({ name, value: schema });\n spec.components.schemas[name] = schema;\n const properties = schema.properties as Record<\n string,\n SchemaObject | ReferenceObject\n >;\n for (const [propName, value] of Object.entries(properties)) {\n if (isRef(value)) continue;\n\n const fixedPropName = propName.replace('[]', '');\n // this neeeds inheritance logic first otherwise it'll create class mess\n // const refName = findUniqueSchemaName(\n // spec,\n // propName,\n // ['Property', 'Field', 'Attribute'],\n // pascalcase(joinSkipDigits([name, fixedPropName], ' ')),\n // );\n const refName = pascalcase(joinSkipDigits([name, fixedPropName], ' '));\n\n if (!isEmpty(value.properties)) {\n // refs.push({ name: refName, value: value });\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else if (!isEmpty(value.oneOf)) {\n expandOneOf(spec, name, value, refs, 'oneOf');\n\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else if (!isEmpty(value.anyOf)) {\n expandOneOf(spec, name, value, refs, 'anyOf');\n\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else {\n expandSpec(spec, { [refName]: value }, refs);\n }\n }\n\n continue;\n }\n if (!isEmpty(schema['x-properties'])) {\n // refs.push({ name, value: schema });\n spec.components.schemas[name] = schema;\n\n const properties = schema['x-properties'] as Record<\n string,\n SchemaObject | ReferenceObject\n >;\n for (const [propName, value] of Object.entries(properties)) {\n if (isRef(value)) continue;\n\n const fixedPropName = propName.replace('[]', '');\n // this neeeds inheritance logic first otherwise it'll create class mess\n // const refName = findUniqueSchemaName(\n // spec,\n // propName,\n // ['Property', 'Field', 'Attribute'],\n // pascalcase(joinSkipDigits([name, fixedPropName], ' ')),\n // );\n const refName = pascalcase(joinSkipDigits([name, fixedPropName], ' '));\n\n if (!isEmpty(value.properties)) {\n // refs.push({ name: refName, value: value });\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else if (!isEmpty(value.oneOf)) {\n expandOneOf(spec, name, value, refs, 'oneOf');\n\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else if (!isEmpty(value.anyOf)) {\n expandOneOf(spec, name, value, refs, 'anyOf');\n\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else {\n expandSpec(spec, { [refName]: value }, refs);\n }\n }\n continue;\n }\n\n if (schema.type === 'array') {\n if (isRef(schema.items)) continue;\n if (isEmpty(schema.items)) continue;\n const refName = findUniqueSchemaName(spec, name, ['Item', 'Entry']);\n if (schema.items.type === 'object') {\n // const refName = findUniqueSchemaName(spec, name, ['Object']);\n // refs.push({ name: refName, value: schema.items });\n spec.components.schemas[refName] = schema.items;\n expandSpec(spec, { [refName]: schema.items }, refs);\n schema.items = { $ref: `#/components/schemas/${refName}` };\n continue;\n }\n if (schema.items.type === 'array') {\n // for nested arrays, we need to move the last nested items only\n // so {type: 'array', items: { type: 'array', items: { type: 'object', properties: ... } }}\n // only object schema is moved while the array hirarchy is intact.\n expandSpec(spec, { [refName]: schema.items }, refs);\n continue;\n }\n if (!isEmpty(schema.items.oneOf)) {\n expandOneOf(spec, refName, schema.items, refs, 'oneOf');\n continue;\n }\n if (!isEmpty(schema.items.anyOf)) {\n expandOneOf(spec, refName, schema.items, refs, 'anyOf');\n continue;\n }\n }\n if (!isEmpty(schema.oneOf)) {\n expandOneOf(spec, name, schema, refs, 'oneOf');\n continue;\n }\n if (!isEmpty(schema.anyOf)) {\n expandOneOf(spec, name, schema, refs, 'anyOf');\n continue;\n }\n }\n}\n\nfunction expandOneOf(\n spec: IR,\n name: string,\n schema: SchemaObject,\n refs: Refs,\n kind: 'oneOf' | 'anyOf',\n) {\n const varients = schema['x-varients'] as Varient[];\n if (!varients || varients.length === 0) {\n console.warn(\n `No varients found for ${name}. This might be an error in the OpenAPI spec.`,\n );\n }\n varients.forEach((varient) => {\n const varientSchema = schema[kind]![varient.position];\n if (isRef(varientSchema)) return;\n const refName = findUniqueSchemaName(\n spec,\n pascalcase(`${name} ${varient.name}`),\n ['Varient'],\n );\n\n if (varientSchema.type === 'object') {\n expandSpec(spec, { [refName]: varientSchema }, refs);\n schema[kind]![varient.position] = {\n $ref: `#/components/schemas/${refName}`,\n };\n } else {\n expandSpec(spec, { [refName]: varientSchema }, refs);\n }\n\n // const referable = (['array', 'object'] as SchemaObjectType[]).some((type) =>\n // coerceTypes(varientSchema).includes(type),\n // );\n // if (!referable) {\n // return;\n // }\n });\n}\n\nexport function coerceTypes(\n schema: SchemaObject,\n excludeNull = true,\n): SchemaObjectType[] {\n const types = Array.isArray(schema.type)\n ? schema.type\n : schema.type\n ? [schema.type]\n : [];\n if (excludeNull) {\n return types.filter((type) => type !== 'null');\n }\n return types;\n}\n"],
|
|
5
|
-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KAAK,GAAG;AACpD,aAAO,OAAO;AAAA,IAChB;AAEA,QAAI,QAAQ,OAAO,IAAI,GAAG;AACxB,aAAO,OAAO;AAAA,IAChB;AAEA,QAAI,CAAC,QAAQ,OAAO,IAAI,GAAG;AACzB,UAAI,OAAO,KAAK,WAAW,GAAG;AAC5B,eAAO,QAAQ,OAAO,KAAK,CAAC;AAC5B,eAAO,OAAO;AAAA,MAChB,OAAO;AACL,cAAM,YAAY,oBAAI,IAAY;AAClC,cAAM,aAAa,CAAC;AACpB,mBAAW,MAAM,OAAO,MAAM;AAC5B,gBAAM,iBAAiB,WAAW,UAAU,WAAW,EAAE,CAAC,CAAC;AAC3D,cAAI,CAAC,UAAU,IAAI,cAAc,GAAG;AAClC,sBAAU,IAAI,cAAc;AAC5B,uBAAW,KAAK,EAAE;AAAA,UACpB;AAAA,QACF;AACA,eAAO,OAAO;AAAA,MAChB;AACA,aAAO,OAAO;AAAA,IAChB;AAEA,QAAI,OAAO,UAAU,QAAW;AAC9B,aAAO,UAAU,OAAO;AAAA,IAC1B;AAEA,QAAI,CAAC,QAAQ,OAAO,KAAK,GAAG;AAC1B,YAAMA,WAAU,OAAO;AAOvB,YAAM,WAAWA,SAAQ,IAAI,CAAC,OAAO,WAAyB,MAAM,EAAE,CAAC;AACvE,YAAM,aAAa,SAAS,KAAK,CAAC,OAAO,GAAG,SAAS,QAAQ;AAC7D,YAAM,gBAAgB,SAAS;AAAA,QAC7B,CAAC,OAAO,GAAG,QAAQ,GAAG,SAAS;AAAA,MACjC;AACA,UAAI,cAAc,eAAe;AAC/B,eAAO,OAAO,yBAAyB;AAAA,MACzC;AACA;AAAA,QACE;AAAA,QACA,GAAG,SAAS,IAAI,CAAC,
|
|
4
|
+
"sourcesContent": ["import { merge, uniq } from 'lodash-es';\nimport assert from 'node:assert';\nimport type {\n ReferenceObject,\n SchemaObject,\n SchemaObjectType,\n} from 'openapi3-ts/oas31';\n\nimport {\n isEmpty,\n isRef,\n joinSkipDigits,\n notRef,\n pascalcase,\n resolveRef,\n snakecase,\n} from '@sdk-it/core';\n\nimport { type Varient, findVarients } from './find-polymorphic-varients.js';\nimport { findUniqueSchemaName } from './find-unique-schema-name.js';\nimport { formatName } from './format-name.js';\nimport { isPrimitiveSchema } from './is-primitive-schema.js';\nimport type { IR } from './types.js';\n\nexport function fixSpec(\n spec: IR,\n schemas: (SchemaObject | ReferenceObject)[],\n visited = new Set<string>(),\n) {\n for (const schema of schemas) {\n if (isRef(schema)) continue;\n\n if (!isEmpty(schema.properties)) {\n schema.type = 'object';\n delete schema.oneOf;\n delete schema.anyOf;\n fixSpec(spec, Object.values(schema.properties), visited);\n // path param are required and if it happens to have\n // body with defaults then zod would break off. so flat the defaults from object itself to properties\n for (const [key, value] of Object.entries(schema.properties)) {\n if (notRef(value) && isPrimitiveSchema(value)) {\n value.default ??= schema.default?.[key];\n delete schema.default?.[key];\n }\n }\n delete schema.default; // default should not be in properties\n }\n\n if (!isEmpty(schema['x-properties'])) {\n fixSpec(spec, Object.values(schema['x-properties']), visited);\n }\n\n if (!isEmpty(schema.items)) {\n delete schema.oneOf;\n delete schema.anyOf;\n schema.type = 'array';\n fixSpec(spec, [schema.items], visited);\n const items = resolveRef<SchemaObject>(spec, schema.items);\n if (Array.isArray(items.default)) {\n schema.default ??= structuredClone(items.default);\n }\n delete items.default; // default should not be in items\n }\n\n if (!isEmpty(schema.anyOf) && !isEmpty(schema.oneOf)) {\n delete schema.anyOf;\n }\n\n if (isEmpty(schema.enum)) {\n delete schema.enum;\n }\n\n if (!isEmpty(schema.enum)) {\n if (schema.enum.length === 1) {\n schema.const = schema.enum[0];\n delete schema.enum;\n } else {\n const valuesSet = new Set<string>();\n const valuesList = [];\n for (const it of schema.enum) {\n const formattedValue = formatName(snakecase(formatName(it)));\n if (!valuesSet.has(formattedValue)) {\n valuesSet.add(formattedValue);\n valuesList.push(it);\n }\n }\n schema.enum = valuesList;\n }\n delete schema.allOf;\n }\n\n if (schema.const !== undefined) {\n schema.default = schema.const;\n }\n\n if (!isEmpty(schema.allOf)) {\n const schemas = schema.allOf;\n // if (schemas.length === 1) {\n // fixSpec(spec, [schemas[0]], visited);\n // Object.assign(schema, schemas[0]);\n // delete schema.allOf;\n // } else {\n // }\n const resolved = schemas.map((it) => resolveRef<SchemaObject>(spec, it));\n const hasObjects = resolved.some((it) => it.type === 'object');\n const hasOtherTypes = resolved.some(\n (it) => it.type && it.type !== 'object',\n );\n if (hasObjects && hasOtherTypes) {\n assert(false, `allOf must be an object`);\n }\n merge(\n schema,\n ...resolved.map((resolvedSchema, index) => {\n const sourceSchema = schemas[index];\n if (isRef(sourceSchema)) {\n if (visited.has(sourceSchema.$ref)) {\n throw new Error(\n `Circular allOf reference detected: ${[\n ...visited,\n sourceSchema.$ref,\n ].join(' -> ')}`,\n );\n }\n fixSpec(\n spec,\n [resolvedSchema],\n new Set(visited).add(sourceSchema.$ref),\n );\n } else {\n fixSpec(spec, [resolvedSchema], visited);\n }\n return resolvedSchema;\n }),\n );\n delete schema.allOf;\n } else {\n delete schema.allOf;\n }\n\n if (\n schema.type === 'object' &&\n isEmpty(schema.properties) &&\n typeof schema.additionalProperties === 'object' &&\n !isEmpty(schema.additionalProperties) &&\n notRef(schema.additionalProperties) &&\n !isEmpty(schema.additionalProperties.properties)\n ) {\n // Tune the dictionary value's properties without replacing the\n // dictionary container with its value schema.\n fixSpec(\n spec,\n Object.values(schema.additionalProperties.properties),\n visited,\n );\n }\n\n for (const kind of ['oneOf', 'anyOf'] as const) {\n if (!isEmpty(schema[kind])) {\n delete schema.type; // type is not allowed with oneOf or anyOf\n fixSpec(spec, schema[kind], visited);\n if (isEmpty(schema[kind])) {\n // fixSpec can remove oneOf or anyOf if it has no items so we need to check again\n // after fixing\n continue;\n }\n\n let enumSchemaIndex = -1;\n const enumValues: string[] = [];\n for (let idx = 0; idx < schema[kind].length; idx++) {\n const item = schema[kind][idx];\n // just handle non ref for now\n if (notRef(item) && item.type === 'string') {\n // if enum equal one it'd already have been converted to const so check for more than one\n if (item.enum && item.enum.length > 1) {\n // foundEnum = true;\n enumValues.push(...item.enum);\n if (enumSchemaIndex === -1) {\n enumSchemaIndex = idx;\n }\n }\n }\n }\n if (enumSchemaIndex !== -1) {\n const enumSchema = schema[kind][enumSchemaIndex];\n if (notRef(enumSchema)) {\n enumSchema.enum = uniq(enumValues);\n }\n // delete the other schemas that have enum\n schema[kind] = schema[kind].filter(\n (it, idx) => idx === enumSchemaIndex || isRef(it),\n );\n }\n const otherTypes = schema[kind].filter(\n (it) => resolveRef<SchemaObject>(spec, it).type !== 'null',\n );\n if (otherTypes.length === 1) {\n Object.assign(schema, otherTypes[0]);\n delete schema[kind];\n continue;\n }\n\n schema['x-varients'] = findVarients(spec, schema[kind]);\n } else {\n delete schema[kind];\n }\n }\n }\n}\n\ntype Refs = { name: string; value: SchemaObject }[];\n\nexport function expandSpec(\n spec: IR,\n schemas: Record<string, SchemaObject | ReferenceObject>,\n refs: Refs,\n) {\n for (const [name, schema] of Object.entries(schemas)) {\n if (isRef(schema)) continue;\n\n if (!isEmpty(schema.properties)) {\n if (!isEmpty(schema.oneOf)) {\n for (const oneOfIdx in schema.oneOf) {\n const oneOf = schema.oneOf[oneOfIdx];\n if (isRef(oneOf)) continue;\n for (const key of ['properties', 'x-properties'] as const) {\n if (!isEmpty(oneOf.required) && schema[key]) {\n schema.oneOf[oneOfIdx] = schema[key][oneOf.required[0]];\n }\n }\n }\n delete schema.type;\n expandSpec(spec, schemas, refs);\n continue;\n }\n if (schema.additionalProperties) {\n continue;\n }\n // refs.push({ name, value: schema });\n spec.components.schemas[name] = schema;\n const properties = schema.properties as Record<\n string,\n SchemaObject | ReferenceObject\n >;\n for (const [propName, value] of Object.entries(properties)) {\n if (isRef(value)) continue;\n\n const fixedPropName = propName.replace('[]', '');\n // this neeeds inheritance logic first otherwise it'll create class mess\n // const refName = findUniqueSchemaName(\n // spec,\n // propName,\n // ['Property', 'Field', 'Attribute'],\n // pascalcase(joinSkipDigits([name, fixedPropName], ' ')),\n // );\n const refName = findUniqueSchemaName(\n spec,\n pascalcase(joinSkipDigits([name, fixedPropName], ' ')),\n ['Property', 'Field', 'Attribute'],\n );\n\n if (!isEmpty(value.properties)) {\n // refs.push({ name: refName, value: value });\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else if (!isEmpty(value.oneOf)) {\n expandOneOf(spec, name, value, refs, 'oneOf');\n\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else if (!isEmpty(value.anyOf)) {\n expandOneOf(spec, name, value, refs, 'anyOf');\n\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else {\n expandSpec(spec, { [refName]: value }, refs);\n }\n }\n\n continue;\n }\n if (!isEmpty(schema['x-properties'])) {\n // refs.push({ name, value: schema });\n spec.components.schemas[name] = schema;\n\n const properties = schema['x-properties'] as Record<\n string,\n SchemaObject | ReferenceObject\n >;\n for (const [propName, value] of Object.entries(properties)) {\n if (isRef(value)) continue;\n\n const fixedPropName = propName.replace('[]', '');\n // this neeeds inheritance logic first otherwise it'll create class mess\n // const refName = findUniqueSchemaName(\n // spec,\n // propName,\n // ['Property', 'Field', 'Attribute'],\n // pascalcase(joinSkipDigits([name, fixedPropName], ' ')),\n // );\n const refName = findUniqueSchemaName(\n spec,\n pascalcase(joinSkipDigits([name, fixedPropName], ' ')),\n ['Property', 'Field', 'Attribute'],\n );\n\n if (!isEmpty(value.properties)) {\n // refs.push({ name: refName, value: value });\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else if (!isEmpty(value.oneOf)) {\n expandOneOf(spec, name, value, refs, 'oneOf');\n\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else if (!isEmpty(value.anyOf)) {\n expandOneOf(spec, name, value, refs, 'anyOf');\n\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else {\n expandSpec(spec, { [refName]: value }, refs);\n }\n }\n continue;\n }\n\n if (schema.type === 'array') {\n if (isRef(schema.items)) continue;\n if (isEmpty(schema.items)) continue;\n const refName = findUniqueSchemaName(spec, name, ['Item', 'Entry']);\n if (schema.items.type === 'object') {\n // const refName = findUniqueSchemaName(spec, name, ['Object']);\n // refs.push({ name: refName, value: schema.items });\n spec.components.schemas[refName] = schema.items;\n expandSpec(spec, { [refName]: schema.items }, refs);\n schema.items = { $ref: `#/components/schemas/${refName}` };\n continue;\n }\n if (schema.items.type === 'array') {\n // for nested arrays, we need to move the last nested items only\n // so {type: 'array', items: { type: 'array', items: { type: 'object', properties: ... } }}\n // only object schema is moved while the array hirarchy is intact.\n expandSpec(spec, { [refName]: schema.items }, refs);\n continue;\n }\n if (!isEmpty(schema.items.oneOf)) {\n expandOneOf(spec, refName, schema.items, refs, 'oneOf');\n continue;\n }\n if (!isEmpty(schema.items.anyOf)) {\n expandOneOf(spec, refName, schema.items, refs, 'anyOf');\n continue;\n }\n }\n if (!isEmpty(schema.oneOf)) {\n expandOneOf(spec, name, schema, refs, 'oneOf');\n continue;\n }\n if (!isEmpty(schema.anyOf)) {\n expandOneOf(spec, name, schema, refs, 'anyOf');\n continue;\n }\n }\n}\n\nfunction expandOneOf(\n spec: IR,\n name: string,\n schema: SchemaObject,\n refs: Refs,\n kind: 'oneOf' | 'anyOf',\n) {\n const varients = schema['x-varients'] as Varient[];\n if (!varients || varients.length === 0) {\n console.warn(\n `No varients found for ${name}. This might be an error in the OpenAPI spec.`,\n );\n }\n varients.forEach((varient) => {\n const varientSchema = schema[kind]![varient.position];\n if (isRef(varientSchema)) return;\n const refName = findUniqueSchemaName(\n spec,\n pascalcase(`${name} ${varient.name}`),\n ['Varient'],\n );\n\n if (varientSchema.type === 'object') {\n spec.components.schemas[refName] = varientSchema;\n expandSpec(spec, { [refName]: varientSchema }, refs);\n schema[kind]![varient.position] = {\n $ref: `#/components/schemas/${refName}`,\n };\n } else {\n expandSpec(spec, { [refName]: varientSchema }, refs);\n }\n\n // const referable = (['array', 'object'] as SchemaObjectType[]).some((type) =>\n // coerceTypes(varientSchema).includes(type),\n // );\n // if (!referable) {\n // return;\n // }\n });\n}\n\nexport function coerceTypes(\n schema: SchemaObject,\n excludeNull = true,\n): SchemaObjectType[] {\n const types = Array.isArray(schema.type)\n ? schema.type\n : schema.type\n ? [schema.type]\n : [];\n if (excludeNull) {\n return types.filter((type) => type !== 'null');\n }\n return types;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,YAAY;AAC5B,OAAO,YAAY;AAOnB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAuB,oBAAoB;AAC3C,SAAS,4BAA4B;AACrC,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAG3B,SAAS,QACd,MACA,SACA,UAAU,oBAAI,IAAY,GAC1B;AACA,aAAW,UAAU,SAAS;AAC5B,QAAI,MAAM,MAAM,EAAG;AAEnB,QAAI,CAAC,QAAQ,OAAO,UAAU,GAAG;AAC/B,aAAO,OAAO;AACd,aAAO,OAAO;AACd,aAAO,OAAO;AACd,cAAQ,MAAM,OAAO,OAAO,OAAO,UAAU,GAAG,OAAO;AAGvD,iBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,UAAU,GAAG;AAC5D,YAAI,OAAO,KAAK,KAAK,kBAAkB,KAAK,GAAG;AAC7C,gBAAM,YAAY,OAAO,UAAU,GAAG;AACtC,iBAAO,OAAO,UAAU,GAAG;AAAA,QAC7B;AAAA,MACF;AACA,aAAO,OAAO;AAAA,IAChB;AA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ANGED
|
@@ -3,7 +3,10 @@ import type { PaginationGuess } from './pagination/guess-pagination.js';
|
|
|
3
3
|
import type { SidebarData, TagGroups } from './sidebar.js';
|
|
4
4
|
export interface IR extends OpenAPIObject {
|
|
5
5
|
servers: ServerObject[];
|
|
6
|
-
'x-sdk-
|
|
6
|
+
'x-sdk-processing'?: {
|
|
7
|
+
plugins: string[];
|
|
8
|
+
configuration: string;
|
|
9
|
+
};
|
|
7
10
|
'x-docs': SidebarData;
|
|
8
11
|
'x-tagGroups': TagGroups[];
|
|
9
12
|
components: Omit<ComponentsObject, 'schemas'> & {
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,eAAe,EACf,eAAe,EACf,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,SAAS,EACV,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,WAAW,EAAG,SAAQ,aAAa;IACvC,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,eAAe,EACf,eAAe,EACf,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,SAAS,EACV,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;A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,CAAC;KAC1C,CACF,CAAC;IACF,WAAW,EAAE,oBAAoB,CAAC;CACnC,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AACD,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,cAAc,CAAC;IACtB,SAAS,EAAE,oBAAoB,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG;IAClD,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SchemaObject } from 'openapi3-ts/oas31';
|
|
2
|
+
import type { IR } from './types.js';
|
|
3
|
+
export interface WalkedSchema {
|
|
4
|
+
schema: SchemaObject;
|
|
5
|
+
pointer: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function walkSchemas(spec: IR): Generator<WalkedSchema>;
|
|
8
|
+
//# sourceMappingURL=walk-schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walk-schemas.d.ts","sourceRoot":"","sources":["../../src/lib/walk-schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAIvE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAiDD,wBAAiB,WAAW,CAAC,IAAI,EAAE,EAAE,GAAG,SAAS,CAAC,YAAY,CAAC,CAS9D"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { isRef } from "@sdk-it/core/ref.js";
|
|
2
|
+
function escapePointerSegment(segment) {
|
|
3
|
+
return segment.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
4
|
+
}
|
|
5
|
+
function* walkSchema(schema, pointer, visited) {
|
|
6
|
+
if (isRef(schema) || visited.has(schema)) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
visited.add(schema);
|
|
10
|
+
yield { schema, pointer };
|
|
11
|
+
for (const key of ["properties", "x-properties"]) {
|
|
12
|
+
const properties = schema[key];
|
|
13
|
+
for (const [name, property] of Object.entries(properties ?? {})) {
|
|
14
|
+
yield* walkSchema(
|
|
15
|
+
property,
|
|
16
|
+
`${pointer}/${key}/${escapePointerSegment(name)}`,
|
|
17
|
+
visited
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
for (const key of [
|
|
22
|
+
"items",
|
|
23
|
+
"not",
|
|
24
|
+
"additionalProperties",
|
|
25
|
+
"propertyNames"
|
|
26
|
+
]) {
|
|
27
|
+
const child = schema[key];
|
|
28
|
+
if (typeof child === "object" && child !== null) {
|
|
29
|
+
yield* walkSchema(child, `${pointer}/${key}`, visited);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
for (const key of ["allOf", "oneOf", "anyOf", "prefixItems"]) {
|
|
33
|
+
for (const [index, child] of (schema[key] ?? []).entries()) {
|
|
34
|
+
yield* walkSchema(child, `${pointer}/${key}/${index}`, visited);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function* walkSchemas(spec) {
|
|
39
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
40
|
+
for (const [name, schema] of Object.entries(spec.components.schemas)) {
|
|
41
|
+
yield* walkSchema(
|
|
42
|
+
schema,
|
|
43
|
+
`#/components/schemas/${escapePointerSegment(name)}`,
|
|
44
|
+
visited
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
walkSchemas
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=walk-schemas.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/walk-schemas.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ReferenceObject, SchemaObject } from 'openapi3-ts/oas31';\n\nimport { isRef } from '@sdk-it/core/ref.js';\n\nimport type { IR } from './types.js';\n\nexport interface WalkedSchema {\n schema: SchemaObject;\n pointer: string;\n}\n\nfunction escapePointerSegment(segment: string) {\n return segment.replaceAll('~', '~0').replaceAll('/', '~1');\n}\n\nfunction* walkSchema(\n schema: SchemaObject | ReferenceObject,\n pointer: string,\n visited: WeakSet<SchemaObject>,\n): Generator<WalkedSchema> {\n if (isRef(schema) || visited.has(schema)) {\n return;\n }\n\n visited.add(schema);\n yield { schema, pointer };\n\n for (const key of ['properties', 'x-properties'] as const) {\n const properties = schema[key] as\n Record<string, SchemaObject | ReferenceObject> | undefined;\n for (const [name, property] of Object.entries(properties ?? {})) {\n yield* walkSchema(\n property,\n `${pointer}/${key}/${escapePointerSegment(name)}`,\n visited,\n );\n }\n }\n\n for (const key of [\n 'items',\n 'not',\n 'additionalProperties',\n 'propertyNames',\n ] as const) {\n const child = schema[key];\n if (typeof child === 'object' && child !== null) {\n yield* walkSchema(child, `${pointer}/${key}`, visited);\n }\n }\n\n for (const key of ['allOf', 'oneOf', 'anyOf', 'prefixItems'] as const) {\n for (const [index, child] of (schema[key] ?? []).entries()) {\n yield* walkSchema(child, `${pointer}/${key}/${index}`, visited);\n }\n }\n}\n\nexport function* walkSchemas(spec: IR): Generator<WalkedSchema> {\n const visited = new WeakSet<SchemaObject>();\n for (const [name, schema] of Object.entries(spec.components.schemas)) {\n yield* walkSchema(\n schema,\n `#/components/schemas/${escapePointerSegment(name)}`,\n visited,\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,aAAa;AAStB,SAAS,qBAAqB,SAAiB;AAC7C,SAAO,QAAQ,WAAW,KAAK,IAAI,EAAE,WAAW,KAAK,IAAI;AAC3D;AAEA,UAAU,WACR,QACA,SACA,S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it/spec",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"!**/*.test.*"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@sdk-it/core": "0.
|
|
30
|
+
"@sdk-it/core": "0.46.0",
|
|
31
31
|
"openapi3-ts": "4.5.0",
|
|
32
32
|
"pluralize": "^8.0.0",
|
|
33
33
|
"stringcase": "^4.3.1",
|