@sdk-it/spec 0.46.10 → 0.47.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/README.md +8 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +2 -2
- package/dist/lib/external-documents.d.ts +10 -0
- package/dist/lib/external-documents.d.ts.map +1 -0
- package/dist/lib/external-documents.js +61 -0
- package/dist/lib/external-documents.js.map +7 -0
- package/dist/lib/finalize-operations.d.ts +8 -0
- package/dist/lib/finalize-operations.d.ts.map +1 -0
- package/dist/lib/finalize-operations.js +134 -0
- package/dist/lib/finalize-operations.js.map +7 -0
- package/dist/lib/find-polymorphic-varients.d.ts.map +1 -1
- package/dist/lib/find-polymorphic-varients.js +3 -2
- package/dist/lib/find-polymorphic-varients.js.map +2 -2
- package/dist/lib/find-unique-schema-name.d.ts.map +1 -1
- package/dist/lib/for-each-operation.d.ts +3 -2
- package/dist/lib/for-each-operation.d.ts.map +1 -1
- package/dist/lib/for-each-operation.js +9 -4
- package/dist/lib/for-each-operation.js.map +2 -2
- package/dist/lib/format-name.d.ts.map +1 -1
- package/dist/lib/get-ref-usage.d.ts.map +1 -1
- package/dist/lib/get-ref-usage.js +1 -2
- package/dist/lib/get-ref-usage.js.map +2 -2
- package/dist/lib/guess/guess-resource.d.ts.map +1 -1
- package/dist/lib/guess/guess-resource.js +4 -4
- package/dist/lib/guess/guess-resource.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 +5 -3
- package/dist/lib/ir.js.map +2 -2
- package/dist/lib/is-primitive-schema.d.ts +12 -0
- package/dist/lib/is-primitive-schema.d.ts.map +1 -1
- package/dist/lib/is-primitive-schema.js +34 -1
- package/dist/lib/is-primitive-schema.js.map +2 -2
- package/dist/lib/is.d.ts +10 -1
- package/dist/lib/is.d.ts.map +1 -1
- package/dist/lib/is.js +20 -9
- package/dist/lib/is.js.map +2 -2
- package/dist/lib/loaders/load-spec.d.ts +9 -2
- package/dist/lib/loaders/load-spec.d.ts.map +1 -1
- package/dist/lib/loaders/load-spec.js +15 -20
- package/dist/lib/loaders/load-spec.js.map +2 -2
- package/dist/lib/loaders/local-loader.d.ts.map +1 -1
- package/dist/lib/loaders/postman/postman-converter.d.ts +1 -1
- package/dist/lib/loaders/postman/postman-converter.d.ts.map +1 -1
- package/dist/lib/loaders/postman/postman-converter.js +2 -3
- package/dist/lib/loaders/postman/postman-converter.js.map +2 -2
- package/dist/lib/loaders/postman/spec-types.d.ts.map +1 -1
- package/dist/lib/loaders/remote-loader.d.ts.map +1 -1
- package/dist/lib/loaders/remote-loader.js +4 -3
- package/dist/lib/loaders/remote-loader.js.map +2 -2
- package/dist/lib/metadata.d.ts +3 -9
- package/dist/lib/metadata.d.ts.map +1 -1
- package/dist/lib/metadata.js +22 -17
- package/dist/lib/metadata.js.map +2 -2
- package/dist/lib/operation-input.d.ts +33 -0
- package/dist/lib/operation-input.d.ts.map +1 -0
- package/dist/lib/operation-input.js +189 -0
- package/dist/lib/operation-input.js.map +7 -0
- package/dist/lib/options.d.ts +5 -6
- package/dist/lib/options.d.ts.map +1 -1
- package/dist/lib/options.js +0 -6
- package/dist/lib/options.js.map +2 -2
- package/dist/lib/overview-docs/doc-text-utils.d.ts +13 -13
- package/dist/lib/overview-docs/doc-text-utils.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-auth.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-auth.js.map +2 -2
- package/dist/lib/overview-docs/overview-docs.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-errors.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-errors.js +8 -5
- package/dist/lib/overview-docs/overview-errors.js.map +2 -2
- package/dist/lib/overview-docs/overview-page.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-page.js +2 -3
- package/dist/lib/overview-docs/overview-page.js.map +2 -2
- package/dist/lib/overview-docs/overview-pagination.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-sdks.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-sdks.js +2 -1
- package/dist/lib/overview-docs/overview-sdks.js.map +2 -2
- package/dist/lib/overview-docs/types.d.ts.map +1 -1
- package/dist/lib/overview-docs/types.js +1 -1
- package/dist/lib/overview-docs/types.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 +3 -3
- package/dist/lib/pagination/pagination-result.d.ts.map +1 -1
- package/dist/lib/pagination/pagination-result.js +6 -3
- package/dist/lib/pagination/pagination-result.js.map +2 -2
- package/dist/lib/pagination/pagination.d.ts +31 -1
- package/dist/lib/pagination/pagination.d.ts.map +1 -1
- package/dist/lib/pagination/pagination.js +30 -11
- package/dist/lib/pagination/pagination.js.map +2 -2
- package/dist/lib/processing-plugins/bundle-external-refs.d.ts +17 -0
- package/dist/lib/processing-plugins/bundle-external-refs.d.ts.map +1 -0
- package/dist/lib/processing-plugins/bundle-external-refs.js +241 -0
- package/dist/lib/processing-plugins/bundle-external-refs.js.map +7 -0
- package/dist/lib/processing-plugins/canonicalize-spec.d.ts +2 -2
- package/dist/lib/processing-plugins/canonicalize-spec.d.ts.map +1 -1
- package/dist/lib/processing-plugins/canonicalize-spec.js.map +2 -2
- package/dist/lib/processing-plugins/create-default-processing-plugins.d.ts +4 -3
- package/dist/lib/processing-plugins/create-default-processing-plugins.d.ts.map +1 -1
- package/dist/lib/processing-plugins/create-default-processing-plugins.js +10 -3
- package/dist/lib/processing-plugins/create-default-processing-plugins.js.map +2 -2
- package/dist/lib/processing-plugins/enrich-examples.d.ts +4 -4
- package/dist/lib/processing-plugins/enrich-examples.d.ts.map +1 -1
- package/dist/lib/processing-plugins/enrich-examples.js +1 -1
- package/dist/lib/processing-plugins/enrich-examples.js.map +2 -2
- package/dist/lib/processing-plugins/extract-inline-schemas.d.ts +2 -2
- package/dist/lib/processing-plugins/extract-inline-schemas.d.ts.map +1 -1
- package/dist/lib/processing-plugins/extract-inline-schemas.js.map +2 -2
- package/dist/lib/processing-plugins/extract-overview-docs.d.ts +2 -2
- package/dist/lib/processing-plugins/extract-overview-docs.d.ts.map +1 -1
- package/dist/lib/processing-plugins/extract-overview-docs.js +4 -1
- package/dist/lib/processing-plugins/extract-overview-docs.js.map +2 -2
- package/dist/lib/processing-plugins/index.d.ts +1 -0
- package/dist/lib/processing-plugins/index.d.ts.map +1 -1
- package/dist/lib/processing-plugins/index.js +1 -0
- package/dist/lib/processing-plugins/index.js.map +2 -2
- package/dist/lib/processing-plugins/infer-pagination.d.ts +2 -2
- package/dist/lib/processing-plugins/infer-pagination.d.ts.map +1 -1
- package/dist/lib/processing-plugins/infer-pagination.js +5 -6
- package/dist/lib/processing-plugins/infer-pagination.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-operation-ids.d.ts +2 -2
- package/dist/lib/processing-plugins/normalize-operation-ids.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-operation-ids.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-parameters.d.ts +2 -2
- package/dist/lib/processing-plugins/normalize-parameters.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-parameters.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-paths.d.ts +2 -2
- package/dist/lib/processing-plugins/normalize-paths.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-paths.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-request-bodies.d.ts +9 -3
- package/dist/lib/processing-plugins/normalize-request-bodies.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-request-bodies.js +36 -15
- package/dist/lib/processing-plugins/normalize-request-bodies.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-responses.d.ts +2 -2
- package/dist/lib/processing-plugins/normalize-responses.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-responses.js +11 -15
- package/dist/lib/processing-plugins/normalize-responses.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-schemas.d.ts +2 -2
- package/dist/lib/processing-plugins/normalize-schemas.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-schemas.js +14 -4
- package/dist/lib/processing-plugins/normalize-schemas.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-security.d.ts +2 -2
- package/dist/lib/processing-plugins/normalize-security.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-security.js +6 -5
- package/dist/lib/processing-plugins/normalize-security.js.map +2 -2
- package/dist/lib/processing-plugins/normalize-tags.d.ts +8 -2
- package/dist/lib/processing-plugins/normalize-tags.d.ts.map +1 -1
- package/dist/lib/processing-plugins/normalize-tags.js +35 -1
- package/dist/lib/processing-plugins/normalize-tags.js.map +2 -2
- package/dist/lib/processing-plugins/resolve-security-scheme-uris.d.ts +13 -2
- package/dist/lib/processing-plugins/resolve-security-scheme-uris.d.ts.map +1 -1
- package/dist/lib/processing-plugins/resolve-security-scheme-uris.js +68 -90
- package/dist/lib/processing-plugins/resolve-security-scheme-uris.js.map +2 -2
- package/dist/lib/processing.d.ts +25 -11
- package/dist/lib/processing.d.ts.map +1 -1
- package/dist/lib/processing.js +53 -16
- package/dist/lib/processing.js.map +2 -2
- package/dist/lib/reserved-keywords.d.ts.map +1 -1
- package/dist/lib/sidebar.d.ts +5 -4
- package/dist/lib/sidebar.d.ts.map +1 -1
- package/dist/lib/sidebar.js +46 -23
- package/dist/lib/sidebar.js.map +2 -2
- package/dist/lib/tag.d.ts.map +1 -1
- package/dist/lib/types.d.ts +34 -12
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +11 -0
- package/dist/lib/types.js.map +3 -3
- package/dist/lib/walk-schemas.d.ts +4 -2
- package/dist/lib/walk-schemas.d.ts.map +1 -1
- package/dist/lib/walk-schemas.js +15 -13
- package/dist/lib/walk-schemas.js.map +2 -2
- package/package.json +17 -6
- package/dist/lib/create-operation.d.ts +0 -28
- package/dist/lib/create-operation.d.ts.map +0 -1
- package/dist/lib/create-operation.js +0 -62
- package/dist/lib/create-operation.js.map +0 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/processing-plugins/extract-inline-schemas.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ReferenceObject, SchemaObject } from 'openapi3-ts/oas31';\n\nimport { isEmpty, isRef, joinSkipDigits, pascalcase } from '@sdk-it/core';\n\nimport type { Varient } from '../find-polymorphic-varients.js';\nimport { findUniqueSchemaName } from '../find-unique-schema-name.js';\nimport type {
|
|
5
|
-
"mappings": "AAEA,SAAS,SAAS,OAAO,gBAAgB,kBAAkB;AAG3D,SAAS,4BAA4B;AAIrC,SAAS,8BACP,MACA,SACA;AACA,aAAW,CAAC,MAAM,MAAM,KAAK,OAAO,QAAQ,OAAO,GAAG;AACpD,QAAI,MAAM,MAAM,EAAG;AAEnB,QAAI,CAAC,QAAQ,OAAO,UAAU,GAAG;AAC/B,UAAI,CAAC,QAAQ,OAAO,KAAK,GAAG;AAC1B,mBAAW,CAAC,YAAY,KAAK,KAAK,OAAO,MAAM,QAAQ,GAAG;AACxD,cAAI,MAAM,KAAK,EAAG;AAElB,gBAAM,mBAAmB,MAAM,WAAW,CAAC;AAC3C,cACE,oBACA,QAAQ,MAAM,UAAU,KACxB,QAAQ,MAAM,cAAc,CAAC,GAC7B;AACA,mBAAO,MAAM,UAAU,IACrB,OAAO,aAAa,gBAAgB,KACpC,OAAO,cAAc,IAAI,gBAAgB,KACzC;AAAA,UACJ;AAAA,QACF;AACA,eAAO,OAAO;AACd,2BAAmB,MAAM,MAAM,QAAQ,OAAO;AAAA,MAChD;AACA,UAAI,OAAO,sBAAsB;AAC/B;AAAA,MACF;AACA,WAAK,WAAW,QAAQ,IAAI,IAAI;AAChC,YAAM,aAAa,OAAO;
|
|
4
|
+
"sourcesContent": ["import type { ReferenceObject, SchemaObject } from 'openapi3-ts/oas31';\n\nimport { isEmpty, isRef, joinSkipDigits, pascalcase } from '@sdk-it/core';\n\nimport type { Varient } from '../find-polymorphic-varients.js';\nimport { findUniqueSchemaName } from '../find-unique-schema-name.js';\nimport type { IRPlugin } from '../processing.js';\nimport type { IR } from '../types.js';\n\nfunction extractInlineSchemaComponents(\n spec: IR,\n schemas: Record<string, SchemaObject | ReferenceObject>,\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 [oneOfIndex, oneOf] of schema.oneOf.entries()) {\n if (isRef(oneOf)) continue;\n\n const requiredProperty = oneOf.required?.[0];\n if (\n requiredProperty &&\n isEmpty(oneOf.properties) &&\n isEmpty(oneOf['x-properties'])\n ) {\n schema.oneOf[oneOfIndex] =\n schema.properties?.[requiredProperty] ??\n schema['x-properties']?.[requiredProperty] ??\n oneOf;\n }\n }\n delete schema.type;\n extractInlineUnion(spec, name, schema, 'oneOf');\n }\n if (schema.additionalProperties) {\n continue;\n }\n spec.components.schemas[name] = schema;\n const properties = schema.properties;\n for (const [propertyName, value] of Object.entries(properties)) {\n if (isRef(value)) continue;\n\n const fixedPropertyName = propertyName.replace('[]', '');\n const refName = findUniqueSchemaName(\n spec,\n pascalcase(joinSkipDigits([name, fixedPropertyName], ' ')),\n ['Property', 'Field', 'Attribute'],\n );\n\n if (!isEmpty(value.properties)) {\n spec.components.schemas[refName] = value;\n properties[propertyName] = {\n $ref: `#/components/schemas/${refName}`,\n };\n extractInlineSchemaComponents(spec, { [refName]: value });\n } else if (!isEmpty(value.oneOf)) {\n extractInlineUnion(spec, name, value, 'oneOf');\n\n spec.components.schemas[refName] = value;\n properties[propertyName] = {\n $ref: `#/components/schemas/${refName}`,\n };\n extractInlineSchemaComponents(spec, { [refName]: value });\n } else if (!isEmpty(value.anyOf)) {\n extractInlineUnion(spec, name, value, 'anyOf');\n\n spec.components.schemas[refName] = value;\n properties[propertyName] = {\n $ref: `#/components/schemas/${refName}`,\n };\n extractInlineSchemaComponents(spec, { [refName]: value });\n } else {\n extractInlineSchemaComponents(spec, { [refName]: value });\n }\n }\n\n continue;\n }\n if (!isEmpty(schema['x-properties'])) {\n spec.components.schemas[name] = schema;\n\n const properties: Record<string, SchemaObject | ReferenceObject> =\n schema['x-properties'];\n for (const [propertyName, value] of Object.entries(properties)) {\n if (isRef(value)) continue;\n\n const fixedPropertyName = propertyName.replace('[]', '');\n const refName = findUniqueSchemaName(\n spec,\n pascalcase(joinSkipDigits([name, fixedPropertyName], ' ')),\n ['Property', 'Field', 'Attribute'],\n );\n\n if (!isEmpty(value.properties)) {\n spec.components.schemas[refName] = value;\n properties[propertyName] = {\n $ref: `#/components/schemas/${refName}`,\n };\n extractInlineSchemaComponents(spec, { [refName]: value });\n } else if (!isEmpty(value.oneOf)) {\n extractInlineUnion(spec, name, value, 'oneOf');\n\n spec.components.schemas[refName] = value;\n properties[propertyName] = {\n $ref: `#/components/schemas/${refName}`,\n };\n extractInlineSchemaComponents(spec, { [refName]: value });\n } else if (!isEmpty(value.anyOf)) {\n extractInlineUnion(spec, name, value, 'anyOf');\n\n spec.components.schemas[refName] = value;\n properties[propertyName] = {\n $ref: `#/components/schemas/${refName}`,\n };\n extractInlineSchemaComponents(spec, { [refName]: value });\n } else {\n extractInlineSchemaComponents(spec, { [refName]: value });\n }\n }\n continue;\n }\n\n if (schema.type === 'array') {\n if (isRef(schema.items) || isEmpty(schema.items)) continue;\n const refName = findUniqueSchemaName(spec, name, ['Item', 'Entry']);\n if (schema.items.type === 'object') {\n spec.components.schemas[refName] = schema.items;\n extractInlineSchemaComponents(spec, { [refName]: schema.items });\n schema.items = { $ref: `#/components/schemas/${refName}` };\n continue;\n }\n if (schema.items.type === 'array') {\n extractInlineSchemaComponents(spec, { [refName]: schema.items });\n continue;\n }\n if (!isEmpty(schema.items.oneOf)) {\n extractInlineUnion(spec, refName, schema.items, 'oneOf');\n continue;\n }\n if (!isEmpty(schema.items.anyOf)) {\n extractInlineUnion(spec, refName, schema.items, 'anyOf');\n continue;\n }\n }\n if (!isEmpty(schema.oneOf)) {\n extractInlineUnion(spec, name, schema, 'oneOf');\n continue;\n }\n if (!isEmpty(schema.anyOf)) {\n extractInlineUnion(spec, name, schema, 'anyOf');\n }\n }\n}\n\nfunction extractInlineUnion(\n spec: IR,\n name: string,\n schema: SchemaObject,\n kind: 'oneOf' | 'anyOf',\n) {\n const varients: Varient[] = schema['x-varients'];\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 extractInlineSchemaComponents(spec, { [refName]: varientSchema });\n schema[kind]![varient.position] = {\n $ref: `#/components/schemas/${refName}`,\n };\n } else {\n extractInlineSchemaComponents(spec, { [refName]: varientSchema });\n }\n });\n}\n\nexport function extractInlineSchemas(): IRPlugin {\n return {\n name: 'extract-inline-schemas',\n process({ spec }) {\n extractInlineSchemaComponents(spec, spec.components.schemas);\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,SAAS,OAAO,gBAAgB,kBAAkB;AAG3D,SAAS,4BAA4B;AAIrC,SAAS,8BACP,MACA,SACA;AACA,aAAW,CAAC,MAAM,MAAM,KAAK,OAAO,QAAQ,OAAO,GAAG;AACpD,QAAI,MAAM,MAAM,EAAG;AAEnB,QAAI,CAAC,QAAQ,OAAO,UAAU,GAAG;AAC/B,UAAI,CAAC,QAAQ,OAAO,KAAK,GAAG;AAC1B,mBAAW,CAAC,YAAY,KAAK,KAAK,OAAO,MAAM,QAAQ,GAAG;AACxD,cAAI,MAAM,KAAK,EAAG;AAElB,gBAAM,mBAAmB,MAAM,WAAW,CA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,CAAC,YAAY,SAAS,WAAW,GAAG;AACtC,YAAQ;AAAA,MACN,yBAAyB,IAAI;AAAA,IAC/B;AAAA,EACF;AACA,WAAS,QAAQ,CAAC,YAAY;AAC5B,UAAM,gBAAgB,OAAO,IAAI,EAAG,QAAQ,QAAQ;AACpD,QAAI,MAAM,aAAa,EAAG;AAC1B,UAAM,UAAU;AAAA,MACd;AAAA,MACA,WAAW,GAAG,IAAI,IAAI,QAAQ,IAAI,EAAE;AAAA,MACpC,CAAC,SAAS;AAAA,IACZ;AAEA,QAAI,cAAc,SAAS,UAAU;AACnC,WAAK,WAAW,QAAQ,OAAO,IAAI;AACnC,oCAA8B,MAAM,EAAE,CAAC,OAAO,GAAG,cAAc,CAAC;AAChE,aAAO,IAAI,EAAG,QAAQ,QAAQ,IAAI;AAAA,QAChC,MAAM,wBAAwB,OAAO;AAAA,MACvC;AAAA,IACF,OAAO;AACL,oCAA8B,MAAM,EAAE,CAAC,OAAO,GAAG,cAAc,CAAC;AAAA,IAClE;AAAA,EACF,CAAC;AACH;AAEO,SAAS,uBAAiC;AAC/C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,EAAE,KAAK,GAAG;AAChB,oCAA8B,MAAM,KAAK,WAAW,OAAO;AAAA,IAC7D;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function extractOverviewDocsPlugin():
|
|
1
|
+
import type { IRPlugin } from '../processing.js';
|
|
2
|
+
export declare function extractOverviewDocsPlugin(): IRPlugin;
|
|
3
3
|
//# sourceMappingURL=extract-overview-docs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-overview-docs.d.ts","
|
|
1
|
+
{"version":3,"file":"extract-overview-docs.d.ts","sources":["../../../src/lib/processing-plugins/extract-overview-docs.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,kBAAkB,CAAC;AAGpE,wBAAgB,yBAAyB,IAAI,QAAQ,CAapD"}
|
|
@@ -45,7 +45,10 @@ function collectSdks({ options, report }) {
|
|
|
45
45
|
return false;
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
function collectDocs({
|
|
48
|
+
function collectDocs({
|
|
49
|
+
options,
|
|
50
|
+
report
|
|
51
|
+
}) {
|
|
49
52
|
const raw = options.docs.entries;
|
|
50
53
|
if (raw === void 0) return [];
|
|
51
54
|
if (!Array.isArray(raw)) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/processing-plugins/extract-overview-docs.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n GENERATED_DOC_IDS,\n extractOverviewDocs,\n} from '../overview-docs/overview-docs.js';\nimport {\n RESERVED_DOC_IDS,\n type ResolvedDoc,\n type SdkDoc,\n isAuthoredDoc,\n isSdkDoc,\n slugify,\n} from '../overview-docs/types.js';\nimport type {
|
|
5
|
-
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OACK;
|
|
4
|
+
"sourcesContent": ["import {\n GENERATED_DOC_IDS,\n extractOverviewDocs,\n} from '../overview-docs/overview-docs.js';\nimport {\n RESERVED_DOC_IDS,\n type ResolvedDoc,\n type SdkDoc,\n isAuthoredDoc,\n isSdkDoc,\n slugify,\n} from '../overview-docs/types.js';\nimport type { IRPlugin, ProcessingContext } from '../processing.js';\nimport type { IR } from '../types.js';\n\nexport function extractOverviewDocsPlugin(): IRPlugin {\n return {\n name: 'extract-overview-docs',\n process(context) {\n const sdks = collectSdks(context);\n const entries = collectDocs(context);\n context.spec['x-sdks'] = sdks;\n context.spec['x-docs'] = extractOverviewDocs(context.spec, {\n entries,\n sdks,\n });\n },\n };\n}\n\nfunction collectSdks({ options, report }: ProcessingContext<IR>): SdkDoc[] {\n const raw = options.docs.sdks;\n if (raw === undefined) return [];\n if (!Array.isArray(raw)) {\n report({\n severity: 'warning',\n code: 'invalid-x-sdks',\n message: 'x-sdks must be an array of { language, package, url? }.',\n path: '/x-sdks',\n });\n return [];\n }\n return raw.filter((entry: unknown, index): entry is SdkDoc => {\n if (isSdkDoc(entry)) return true;\n report({\n severity: 'warning',\n code: 'invalid-x-sdks',\n message:\n 'x-sdks entries need a language of typescript, python, or dart and a package name.',\n path: `/x-sdks/${index}`,\n });\n return false;\n });\n}\n\nfunction collectDocs({\n options,\n report,\n}: ProcessingContext<IR>): ResolvedDoc[] {\n const raw = options.docs.entries;\n if (raw === undefined) return [];\n if (!Array.isArray(raw)) {\n report({\n severity: 'warning',\n code: 'invalid-x-docs',\n message:\n 'x-docs must be an array of { id?, title, description?, content? }.',\n path: '/x-docs',\n });\n return [];\n }\n\n const docs: ResolvedDoc[] = [];\n const seen = new Set<string>();\n raw.forEach((entry: unknown, index) => {\n const path = `/x-docs/${index}`;\n const invalid = (message: string) =>\n report({ severity: 'warning', code: 'invalid-x-docs', message, path });\n\n if (!isAuthoredDoc(entry)) {\n invalid(\n 'x-docs entries need a title; id, description, and content must be strings.',\n );\n return;\n }\n const id = slugify(entry.id ?? entry.title);\n if (!id) {\n invalid(`Cannot derive a url-safe id from \"${entry.id ?? entry.title}\".`);\n return;\n }\n if (RESERVED_DOC_IDS.has(id)) {\n report({\n severity: 'warning',\n code: 'reserved-x-docs-id',\n message: `\"${id}\" is reserved by the API reference and cannot be used as a doc id.`,\n path,\n });\n return;\n }\n if (seen.has(id)) {\n report({\n severity: 'warning',\n code: 'duplicate-x-docs-id',\n message: `Doc id \"${id}\" is used more than once; later entries are ignored.`,\n path,\n });\n return;\n }\n if (!GENERATED_DOC_IDS.has(id) && !entry.content && !entry.description) {\n invalid(`Custom doc \"${id}\" needs content or a description to render.`);\n return;\n }\n seen.add(id);\n docs.push({ ...entry, id });\n });\n return docs;\n}\n"],
|
|
5
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oBAAI,IAAY;AAC7B,MAAI,QAAQ,CAAC,OAAgB,UAAU;AACrC,UAAM,OAAO,WAAW,KAAK;AAC7B,UAAM,UAAU,CAAC,YACf,OAAO,EAAE,UAAU,WAAW,MAAM,kBAAkB,SAAS,KAAK,CAAC;AAEvE,QAAI,CAAC,cAAc,KAAK,GAAG;AACzB;AAAA,QACE;AAAA,MACF;AACA;AAAA,IACF;AACA,UAAM,KAAK,QAAQ,MAAM,MAAM,MAAM,KAAK;AAC1C,QAAI,CAAC,IAAI;AACP,cAAQ,qCAAqC,MAAM,MAAM,MAAM,KAAK,IAAI;AACxE;AAAA,IACF;AACA,QAAI,iBAAiB,IAAI,EAAE,GAAG;AAC5B,aAAO;AAAA,QACL,UAAU;AAAA,QACV,MAAM;AAAA,QACN,SAAS,IAAI,EAAE;AAAA,QACf;AAAA,MACF,CAAC;AACD;AAAA,IACF;AACA,QAAI,KAAK,IAAI,EAAE,GAAG;AAChB,aAAO;AAAA,QACL,UAAU;AAAA,QACV,MAAM;AAAA,QACN,SAAS,WAAW,EAAE;AAAA,QACtB;AAAA,MACF,CAAC;AACD;AAAA,IACF;AACA,QAAI,CAAC,kBAAkB,IAAI,EAAE,KAAK,CAAC,MAAM,WAAW,CAAC,MAAM,aAAa;AACtE,cAAQ,eAAe,EAAE,6CAA6C;AACtE;AAAA,IACF;AACA,SAAK,IAAI,EAAE;AACX,SAAK,KAAK,EAAE,GAAG,OAAO,GAAG,CAAC;AAAA,EAC5B,CAAC;AACD,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","
|
|
1
|
+
{"version":3,"file":"index.d.ts","sources":["../../../src/lib/processing-plugins/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wCAAwC,CAAC;AACvD,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mCAAmC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/processing-plugins/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './canonicalize-spec.js';\nexport * from './create-default-processing-plugins.js';\nexport * from './enrich-examples.js';\nexport * from './extract-inline-schemas.js';\nexport * from './extract-overview-docs.js';\nexport * from './infer-pagination.js';\nexport * from './normalize-operation-ids.js';\nexport * from './normalize-parameters.js';\nexport * from './normalize-paths.js';\nexport * from './normalize-request-bodies.js';\nexport * from './normalize-responses.js';\nexport * from './normalize-security.js';\nexport * from './normalize-schemas.js';\nexport * from './normalize-tags.js';\nexport * from './resolve-security-scheme-uris.js';\n"],
|
|
5
|
-
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
4
|
+
"sourcesContent": ["export * from './bundle-external-refs.js';\nexport * from './canonicalize-spec.js';\nexport * from './create-default-processing-plugins.js';\nexport * from './enrich-examples.js';\nexport * from './extract-inline-schemas.js';\nexport * from './extract-overview-docs.js';\nexport * from './infer-pagination.js';\nexport * from './normalize-operation-ids.js';\nexport * from './normalize-parameters.js';\nexport * from './normalize-paths.js';\nexport * from './normalize-request-bodies.js';\nexport * from './normalize-responses.js';\nexport * from './normalize-security.js';\nexport * from './normalize-schemas.js';\nexport * from './normalize-tags.js';\nexport * from './resolve-security-scheme-uris.js';\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function inferPagination():
|
|
1
|
+
import type { IRPlugin } from '../processing.js';
|
|
2
|
+
export declare function inferPagination(): IRPlugin;
|
|
3
3
|
//# sourceMappingURL=infer-pagination.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infer-pagination.d.ts","
|
|
1
|
+
{"version":3,"file":"infer-pagination.d.ts","sources":["../../../src/lib/processing-plugins/infer-pagination.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,wBAAgB,eAAe,IAAI,QAAQ,CAa1C"}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { forEachOperation } from "../for-each-operation.js";
|
|
2
2
|
import { toPagination } from "../pagination/pagination.js";
|
|
3
3
|
function inferPagination() {
|
|
4
4
|
return {
|
|
5
5
|
name: "infer-pagination",
|
|
6
6
|
process({ spec, options }) {
|
|
7
|
-
|
|
8
|
-
const tunedOperation = operation;
|
|
7
|
+
forEachOperation(spec, (_entry, operation) => {
|
|
9
8
|
if (options.pagination.enabled && options.pagination.guess) {
|
|
10
|
-
|
|
9
|
+
operation["x-pagination"] = toPagination(spec, operation);
|
|
11
10
|
} else {
|
|
12
|
-
delete
|
|
11
|
+
delete operation["x-pagination"];
|
|
13
12
|
}
|
|
14
|
-
}
|
|
13
|
+
});
|
|
15
14
|
}
|
|
16
15
|
};
|
|
17
16
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/processing-plugins/infer-pagination.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "AAAA,SAAS,
|
|
4
|
+
"sourcesContent": ["import { forEachOperation } from '../for-each-operation.js';\nimport { toPagination } from '../pagination/pagination.js';\nimport type { IRPlugin } from '../processing.js';\n\nexport function inferPagination(): IRPlugin {\n return {\n name: 'infer-pagination',\n process({ spec, options }) {\n forEachOperation(spec, (_entry, operation) => {\n if (options.pagination.enabled && options.pagination.guess) {\n operation['x-pagination'] = toPagination(spec, operation);\n } else {\n delete operation['x-pagination'];\n }\n });\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAGtB,SAAS,kBAA4B;AAC1C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,EAAE,MAAM,QAAQ,GAAG;AACzB,uBAAiB,MAAM,CAAC,QAAQ,cAAc;AAC5C,YAAI,QAAQ,WAAW,WAAW,QAAQ,WAAW,OAAO;AAC1D,oBAAU,cAAc,IAAI,aAAa,MAAM,SAAS;AAAA,QAC1D,OAAO;AACL,iBAAO,UAAU,cAAc;AAAA,QACjC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function normalizeOperationIds():
|
|
1
|
+
import type { DocumentPlugin } from '../processing.js';
|
|
2
|
+
export declare function normalizeOperationIds(): DocumentPlugin;
|
|
3
3
|
//# sourceMappingURL=normalize-operation-ids.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-operation-ids.d.ts","
|
|
1
|
+
{"version":3,"file":"normalize-operation-ids.d.ts","sources":["../../../src/lib/processing-plugins/normalize-operation-ids.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AA2CvD,wBAAgB,qBAAqB,IAAI,cAAc,CA0CtD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/processing-plugins/normalize-operation-ids.ts"],
|
|
4
|
-
"sourcesContent": ["import { iterateOperations } from '../for-each-operation.js';\nimport { toResource } from '../guess/guess-resource.js';\nimport type {
|
|
5
|
-
"mappings": "AAAA,SAAS,yBAAyB;AAClC,SAAS,kBAAkB;AAG3B,SAAS,sBACP,kBACA,WACA,SACA,WACA;AACA,MAAI,UAAU;AACd,MAAI,oBAAoB,UAAU,SAAS;AAE3C,SAAO,iBAAiB,IAAI,iBAAiB,GAAG;AAC9C,UAAM,eAAe,KAAK,IAAI,UAAU,GAAG,QAAQ,SAAS,CAAC;AAC7D,UAAM,SAAS,QAAQ,YAAY;AACnC,wBAAoB;AAAA,MAClB,eAAe,QAAQ,SAAS,IAC5B,GAAG,MAAM,GAAG,UAAU,OAAO,CAAC,EAAE,YAAY,IAAI,UAAU,MAAM,CAAC,CAAC,KAClE,GAAG,MAAM,GAAG,UAAU,OAAO,CAAC,EAAE,YAAY,IAAI,UAAU,MAAM,CAAC,CAAC,GAAG,UAAU,QAAQ,SAAS,CAAC;AAAA,IACvG;AACA;AAAA,EACF;AAEA,SAAO;AACT;AAEA,SAAS,6BAA6B,OAAuB;AAC3D,QAAM,aAAa,MAChB,KAAK,EACL,QAAQ,kBAAkB,GAAG,EAC7B;AAAA,IAAQ;AAAA,IAA2B,CAAC,GAAG,cACtC,UAAU,YAAY;AAAA,EACxB,EACC,QAAQ,YAAY,CAAC,cAAc,UAAU,YAAY,CAAC;AAE7D,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AACA,MAAI,YAAY,KAAK,UAAU,GAAG;AAChC,WAAO;AAAA,EACT;AACA,SAAO,YAAY,WAAW,OAAO,CAAC,EAAE,YAAY,CAAC,GAAG,WAAW,MAAM,CAAC,CAAC;AAC7E;AAEO,SAAS,
|
|
4
|
+
"sourcesContent": ["import { iterateOperations } from '../for-each-operation.js';\nimport { toResource } from '../guess/guess-resource.js';\nimport type { DocumentPlugin } from '../processing.js';\n\nfunction findUniqueOperationId(\n usedOperationIds: Set<string>,\n initialId: string,\n choices: string[],\n formatter: (id: string) => string,\n) {\n let counter = 1;\n let uniqueOperationId = formatter(initialId);\n\n while (usedOperationIds.has(uniqueOperationId)) {\n const prependIndex = Math.min(counter - 1, choices.length - 1);\n const prefix = choices[prependIndex];\n uniqueOperationId = formatter(\n prependIndex < choices.length - 1\n ? `${prefix}${initialId.charAt(0).toUpperCase() + initialId.slice(1)}`\n : `${prefix}${initialId.charAt(0).toUpperCase() + initialId.slice(1)}${counter - choices.length + 1}`,\n );\n counter++;\n }\n\n return uniqueOperationId;\n}\n\nfunction normalizeOperationIdentifier(value: string): string {\n const normalized = value\n .trim()\n .replace(/[^A-Za-z0-9]+/g, ' ')\n .replace(/(?:^|\\s+)([A-Za-z0-9])/g, (_, character: string) =>\n character.toUpperCase(),\n )\n .replace(/^([A-Z])/, (character) => character.toLowerCase());\n\n if (!normalized) {\n return 'operation';\n }\n if (/^[A-Za-z]/.test(normalized)) {\n return normalized;\n }\n return `operation${normalized.charAt(0).toUpperCase()}${normalized.slice(1)}`;\n}\n\nexport function normalizeOperationIds(): DocumentPlugin {\n return {\n name: 'normalize-operation-ids',\n process({ spec, options, report }) {\n const usedOperationIds = new Set<string>();\n for (const { entry, operation } of iterateOperations(spec)) {\n const originalOperationId = operation.operationId;\n const { name } = toResource(operation, entry.path, entry.method);\n const operationTag = options.tag(operation, entry.path);\n const operationId = findUniqueOperationId(\n usedOperationIds,\n normalizeOperationIdentifier(\n options.operationId(operation, entry.path, entry.method),\n ),\n [\n operationTag,\n entry.method,\n entry.path.split('/').filter(Boolean).join(''),\n ],\n (candidate) =>\n normalizeOperationIdentifier(\n options.operationId(\n { ...operation, operationId: candidate },\n entry.path,\n entry.method,\n ),\n ),\n );\n usedOperationIds.add(operationId);\n operation.operationId = operationId;\n operation['x-fn-name'] = name;\n if (operationId !== originalOperationId) {\n report({\n severity: 'info',\n code: 'operation-id-normalized',\n message: `Normalized operation ID ${originalOperationId ?? '<missing>'} to ${operationId}`,\n path: `${entry.method.toUpperCase()} ${entry.path}`,\n });\n }\n }\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,yBAAyB;AAClC,SAAS,kBAAkB;AAG3B,SAAS,sBACP,kBACA,WACA,SACA,WACA;AACA,MAAI,UAAU;AACd,MAAI,oBAAoB,UAAU,SAAS;AAE3C,SAAO,iBAAiB,IAAI,iBAAiB,GAAG;AAC9C,UAAM,eAAe,KAAK,IAAI,UAAU,GAAG,QAAQ,SAAS,CAAC;AAC7D,UAAM,SAAS,QAAQ,YAAY;AACnC,wBAAoB;AAAA,MAClB,eAAe,QAAQ,SAAS,IAC5B,GAAG,MAAM,GAAG,UAAU,OAAO,CAAC,EAAE,YAAY,IAAI,UAAU,MAAM,CAAC,CAAC,KAClE,GAAG,MAAM,GAAG,UAAU,OAAO,CAAC,EAAE,YAAY,IAAI,UAAU,MAAM,CAAC,CAAC,GAAG,UAAU,QAAQ,SAAS,CAAC;AAAA,IACvG;AACA;AAAA,EACF;AAEA,SAAO;AACT;AAEA,SAAS,6BAA6B,OAAuB;AAC3D,QAAM,aAAa,MAChB,KAAK,EACL,QAAQ,kBAAkB,GAAG,EAC7B;AAAA,IAAQ;AAAA,IAA2B,CAAC,GAAG,cACtC,UAAU,YAAY;AAAA,EACxB,EACC,QAAQ,YAAY,CAAC,cAAc,UAAU,YAAY,CAAC;AAE7D,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AACA,MAAI,YAAY,KAAK,UAAU,GAAG;AAChC,WAAO;AAAA,EACT;AACA,SAAO,YAAY,WAAW,OAAO,CAAC,EAAE,YAAY,CAAC,GAAG,WAAW,MAAM,CAAC,CAAC;AAC7E;AAEO,SAAS,wBAAwC;AACtD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,EAAE,MAAM,SAAS,OAAO,GAAG;AACjC,YAAM,mBAAmB,oBAAI,IAAY;AACzC,iBAAW,EAAE,OAAO,UAAU,KAAK,kBAAkB,IAAI,GAAG;AAC1D,cAAM,sBAAsB,UAAU;AACtC,cAAM,EAAE,KAAK,IAAI,WAAW,WAAW,MAAM,MAAM,MAAM,MAAM;AAC/D,cAAM,eAAe,QAAQ,IAAI,WAAW,MAAM,IAAI;AACtD,cAAM,cAAc;AAAA,UAClB;AAAA,UACA;AAAA,YACE,QAAQ,YAAY,WAAW,MAAM,MAAM,MAAM,MAAM;AAAA,UACzD;AAAA,UACA;AAAA,YACE;AAAA,YACA,MAAM;AAAA,YACN,MAAM,KAAK,MAAM,GAAG,EAAE,OAAO,OAAO,EAAE,KAAK,EAAE;AAAA,UAC/C;AAAA,UACA,CAAC,cACC;AAAA,YACE,QAAQ;AAAA,cACN,EAAE,GAAG,WAAW,aAAa,UAAU;AAAA,cACvC,MAAM;AAAA,cACN,MAAM;AAAA,YACR;AAAA,UACF;AAAA,QACJ;AACA,yBAAiB,IAAI,WAAW;AAChC,kBAAU,cAAc;AACxB,kBAAU,WAAW,IAAI;AACzB,YAAI,gBAAgB,qBAAqB;AACvC,iBAAO;AAAA,YACL,UAAU;AAAA,YACV,MAAM;AAAA,YACN,SAAS,2BAA2B,uBAAuB,WAAW,OAAO,WAAW;AAAA,YACxF,MAAM,GAAG,MAAM,OAAO,YAAY,CAAC,IAAI,MAAM,IAAI;AAAA,UACnD,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function normalizeParameters():
|
|
1
|
+
import type { DocumentPlugin } from '../processing.js';
|
|
2
|
+
export declare function normalizeParameters(): DocumentPlugin;
|
|
3
3
|
//# sourceMappingURL=normalize-parameters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-parameters.d.ts","
|
|
1
|
+
{"version":3,"file":"normalize-parameters.d.ts","sources":["../../../src/lib/processing-plugins/normalize-parameters.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,wBAAgB,mBAAmB,IAAI,cAAc,CAsBpD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/processing-plugins/normalize-parameters.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ParameterObject, PathItemObject } from 'openapi3-ts/oas31';\n\nimport { resolveRef } from '@sdk-it/core/ref.js';\n\nimport { iterateOperations } from '../for-each-operation.js';\nimport type {
|
|
5
|
-
"mappings": "AAEA,SAAS,kBAAkB;AAE3B,SAAS,yBAAyB;AAG3B,SAAS,
|
|
4
|
+
"sourcesContent": ["import type { ParameterObject, PathItemObject } from 'openapi3-ts/oas31';\n\nimport { resolveRef } from '@sdk-it/core/ref.js';\n\nimport { iterateOperations } from '../for-each-operation.js';\nimport type { DocumentPlugin } from '../processing.js';\n\nexport function normalizeParameters(): DocumentPlugin {\n return {\n name: 'normalize-parameters',\n process({ spec }) {\n const pathItems = new Set<PathItemObject>();\n for (const { operation, pathItem } of iterateOperations(spec)) {\n pathItems.add(pathItem);\n const parameters = new Map<string, ParameterObject>();\n for (const parameterOrRef of [\n ...(pathItem.parameters ?? []),\n ...(operation.parameters ?? []),\n ]) {\n const parameter = resolveRef<ParameterObject>(spec, parameterOrRef);\n parameters.set(`${parameter.in}:${parameter.name}`, parameter);\n }\n operation.parameters = [...parameters.values()];\n }\n for (const pathItem of pathItems) {\n delete pathItem.parameters;\n }\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,kBAAkB;AAE3B,SAAS,yBAAyB;AAG3B,SAAS,sBAAsC;AACpD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,EAAE,KAAK,GAAG;AAChB,YAAM,YAAY,oBAAI,IAAoB;AAC1C,iBAAW,EAAE,WAAW,SAAS,KAAK,kBAAkB,IAAI,GAAG;AAC7D,kBAAU,IAAI,QAAQ;AACtB,cAAM,aAAa,oBAAI,IAA6B;AACpD,mBAAW,kBAAkB;AAAA,UAC3B,GAAI,SAAS,cAAc,CAAC;AAAA,UAC5B,GAAI,UAAU,cAAc,CAAC;AAAA,QAC/B,GAAG;AACD,gBAAM,YAAY,WAA4B,MAAM,cAAc;AAClE,qBAAW,IAAI,GAAG,UAAU,EAAE,IAAI,UAAU,IAAI,IAAI,SAAS;AAAA,QAC/D;AACA,kBAAU,aAAa,CAAC,GAAG,WAAW,OAAO,CAAC;AAAA,MAChD;AACA,iBAAW,YAAY,WAAW;AAChC,eAAO,SAAS;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function normalizePaths():
|
|
1
|
+
import type { DocumentPlugin } from '../processing.js';
|
|
2
|
+
export declare function normalizePaths(): DocumentPlugin;
|
|
3
3
|
//# sourceMappingURL=normalize-paths.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-paths.d.ts","
|
|
1
|
+
{"version":3,"file":"normalize-paths.d.ts","sources":["../../../src/lib/processing-plugins/normalize-paths.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,wBAAgB,cAAc,IAAI,cAAc,CAgE/C"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/processing-plugins/normalize-paths.ts"],
|
|
4
|
-
"sourcesContent": ["import type { PathItemObject, PathsObject } from 'openapi3-ts/oas31';\n\nimport { methods } from '@sdk-it/core/paths.js';\nimport { followRef } from '@sdk-it/core/ref.js';\n\nimport type {
|
|
5
|
-
"mappings": "AAEA,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAInB,SAAS,
|
|
4
|
+
"sourcesContent": ["import type { PathItemObject, PathsObject } from 'openapi3-ts/oas31';\n\nimport { methods } from '@sdk-it/core/paths.js';\nimport { followRef } from '@sdk-it/core/ref.js';\n\nimport type { DocumentPlugin } from '../processing.js';\n\nexport function normalizePaths(): DocumentPlugin {\n return {\n name: 'normalize-paths',\n process({ spec, report }) {\n const paths: PathsObject = {};\n const operationSources = new Map<string, string>();\n for (const [path, pathItem] of Object.entries(spec.paths)) {\n const normalizedPath = path.replace(/:([^/]+)/g, '{$1}');\n const target = (paths[normalizedPath] ??= {});\n const source = pathItem.$ref\n ? {\n ...followRef<PathItemObject>(spec, pathItem.$ref),\n ...pathItem,\n }\n : pathItem;\n delete source.$ref;\n Object.assign(\n target,\n Object.fromEntries(\n Object.entries(source).filter(\n ([key]) =>\n key !== 'parameters' &&\n !methods.some((method) => method === key),\n ),\n ),\n );\n for (const method of methods) {\n const operation = source[method];\n if (operation) {\n const operationKey = `${normalizedPath}:${method}`;\n const previousPath = operationSources.get(operationKey);\n if (previousPath) {\n const message = `Both ${previousPath} and ${path} define ${method.toUpperCase()} after path normalization`;\n report({\n severity: 'error',\n code: 'path-operation-collision',\n message,\n path: `${method.toUpperCase()} ${normalizedPath}`,\n });\n throw new Error(message);\n }\n const parameters = [\n ...(source.parameters ?? []),\n ...(operation.parameters ?? []),\n ];\n target[method] = {\n ...operation,\n ...(parameters.length > 0 ? { parameters } : {}),\n };\n operationSources.set(operationKey, path);\n }\n }\n if (normalizedPath !== path) {\n report({\n severity: 'info',\n code: 'path-normalized',\n message: `Normalized path ${path} to ${normalizedPath}`,\n path,\n });\n }\n }\n spec.paths = paths;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,YAC/B;AACA,mBAAO,MAAM,IAAI;AAAA,cACf,GAAG;AAAA,cACH,GAAI,WAAW,SAAS,IAAI,EAAE,WAAW,IAAI,CAAC;AAAA,YAChD;AACA,6BAAiB,IAAI,cAAc,IAAI;AAAA,UACzC;AAAA,QACF;AACA,YAAI,mBAAmB,MAAM;AAC3B,iBAAO;AAAA,YACL,UAAU;AAAA,YACV,MAAM;AAAA,YACN,SAAS,mBAAmB,IAAI,OAAO,cAAc;AAAA,YACrD;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AACA,WAAK,QAAQ;AAAA,IACf;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { ParameterObject, SchemaObject } from 'openapi3-ts/oas31';
|
|
2
|
-
import type {
|
|
2
|
+
import type { DocumentPlugin } from '../processing.js';
|
|
3
3
|
import type { IR } from '../types.js';
|
|
4
|
-
export declare function patchParameters(spec: IR, schema: SchemaObject, parameters: ParameterObject[]): void;
|
|
5
|
-
|
|
4
|
+
export declare function patchParameters(spec: Pick<IR, 'components'>, schema: SchemaObject, parameters: ParameterObject[]): void;
|
|
5
|
+
/**
|
|
6
|
+
* The object a generator types for a schema: its own properties plus the
|
|
7
|
+
* parameters {@link patchParameters} records beside them, every required name
|
|
8
|
+
* included.
|
|
9
|
+
*/
|
|
10
|
+
export declare function withParameters(schema: SchemaObject): SchemaObject;
|
|
11
|
+
export declare function normalizeRequestBodies(): DocumentPlugin;
|
|
6
12
|
//# sourceMappingURL=normalize-request-bodies.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-request-bodies.d.ts","
|
|
1
|
+
{"version":3,"file":"normalize-request-bodies.d.ts","sources":["../../../src/lib/processing-plugins/normalize-request-bodies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEf,YAAY,EACb,MAAM,mBAAmB,CAAC;AAO3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,EAAE,EAA4C,MAAM,aAAa,CAAC;AAEhF,wBAAgB,eAAe,CAC7B,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,YAAY,CAAC,EAC5B,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,eAAe,EAAE,QAkB9B;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAWjE;AAgFD,wBAAgB,sBAAsB,IAAI,cAAc,CA+CvD"}
|
|
@@ -18,6 +18,18 @@ function patchParameters(spec, schema, parameters) {
|
|
|
18
18
|
}
|
|
19
19
|
schema["x-required"] = [...required];
|
|
20
20
|
}
|
|
21
|
+
function withParameters(schema) {
|
|
22
|
+
const merged = structuredClone(schema);
|
|
23
|
+
if (merged["x-properties"]) {
|
|
24
|
+
merged.properties = { ...merged.properties, ...merged["x-properties"] };
|
|
25
|
+
}
|
|
26
|
+
if (merged["x-required"]) {
|
|
27
|
+
merged.required = [
|
|
28
|
+
.../* @__PURE__ */ new Set([...merged.required ?? [], ...merged["x-required"]])
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
return merged;
|
|
32
|
+
}
|
|
21
33
|
function normalizeRequestBody(spec, operationId, operation, parameters) {
|
|
22
34
|
const requestBodySource = isRef(operation.requestBody) ? followRef(spec, operation.requestBody.$ref) : operation.requestBody ?? {
|
|
23
35
|
content: {},
|
|
@@ -46,6 +58,7 @@ function normalizeRequestBody(spec, operationId, operation, parameters) {
|
|
|
46
58
|
spec.components.schemas[inputName] = schema;
|
|
47
59
|
return normalized;
|
|
48
60
|
}
|
|
61
|
+
const content = {};
|
|
49
62
|
for (const contentType in requestBody.content) {
|
|
50
63
|
const mediaType = requestBody.content[contentType];
|
|
51
64
|
const inputName = findUniqueSchemaName(spec, operationId, [
|
|
@@ -76,18 +89,26 @@ function normalizeRequestBody(spec, operationId, operation, parameters) {
|
|
|
76
89
|
"x-requestbody": true,
|
|
77
90
|
"x-inputname": inputName
|
|
78
91
|
};
|
|
79
|
-
|
|
80
|
-
|
|
92
|
+
content[contentType] = {
|
|
93
|
+
...mediaType,
|
|
94
|
+
schema: { $ref: `#/components/schemas/${inputName}` }
|
|
81
95
|
};
|
|
82
96
|
}
|
|
83
|
-
return requestBody;
|
|
97
|
+
return { ...requestBody, content };
|
|
84
98
|
}
|
|
85
99
|
function normalizeRequestBodies() {
|
|
86
100
|
return {
|
|
87
101
|
name: "normalize-request-bodies",
|
|
88
102
|
process({ spec }) {
|
|
89
|
-
for (const { operation } of iterateOperations(spec)) {
|
|
90
|
-
const
|
|
103
|
+
for (const { entry, operation } of iterateOperations(spec)) {
|
|
104
|
+
const { operationId, parameters } = operation;
|
|
105
|
+
if (!operationId || !parameters?.every(
|
|
106
|
+
(parameter) => !isRef(parameter)
|
|
107
|
+
)) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Cannot normalize request bodies before assigning an operation ID and resolving parameters for ${entry.method.toUpperCase()} ${entry.path}`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
91
112
|
if (operation.requestBody) {
|
|
92
113
|
const requestBody = resolveRef(
|
|
93
114
|
spec,
|
|
@@ -96,22 +117,21 @@ function normalizeRequestBodies() {
|
|
|
96
117
|
const schemas = Object.values(requestBody.content).map(
|
|
97
118
|
({ schema }) => schema ? resolveRef(spec, schema) : void 0
|
|
98
119
|
);
|
|
99
|
-
if (schemas.length > 0 && schemas.every(
|
|
120
|
+
if (schemas.length > 0 && schemas.every(
|
|
121
|
+
(schema) => !!schema?.["x-requestbody"]
|
|
122
|
+
)) {
|
|
100
123
|
for (const schema of new Set(schemas)) {
|
|
101
|
-
patchParameters(
|
|
102
|
-
spec,
|
|
103
|
-
schema,
|
|
104
|
-
tunedOperation.parameters
|
|
105
|
-
);
|
|
124
|
+
patchParameters(spec, schema, parameters);
|
|
106
125
|
}
|
|
126
|
+
operation.requestBody = requestBody;
|
|
107
127
|
continue;
|
|
108
128
|
}
|
|
109
129
|
}
|
|
110
|
-
|
|
130
|
+
operation.requestBody = normalizeRequestBody(
|
|
111
131
|
spec,
|
|
112
|
-
|
|
132
|
+
operationId,
|
|
113
133
|
operation,
|
|
114
|
-
|
|
134
|
+
parameters
|
|
115
135
|
);
|
|
116
136
|
}
|
|
117
137
|
}
|
|
@@ -119,6 +139,7 @@ function normalizeRequestBodies() {
|
|
|
119
139
|
}
|
|
120
140
|
export {
|
|
121
141
|
normalizeRequestBodies,
|
|
122
|
-
patchParameters
|
|
142
|
+
patchParameters,
|
|
143
|
+
withParameters
|
|
123
144
|
};
|
|
124
145
|
//# sourceMappingURL=normalize-request-bodies.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/processing-plugins/normalize-request-bodies.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n OperationObject,\n ParameterObject,\n RequestBodyObject,\n SchemaObject,\n} from 'openapi3-ts/oas31';\n\nimport { followRef, isRef, resolveRef } from '@sdk-it/core/ref.js';\nimport { isEmpty } from '@sdk-it/core/utils.js';\n\nimport { findUniqueSchemaName } from '../find-unique-schema-name.js';\nimport { iterateOperations } from '../for-each-operation.js';\nimport type {
|
|
5
|
-
"mappings": "AAOA,SAAS,WAAW,OAAO,kBAAkB;AAC7C,SAAS,eAAe;AAExB,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;
|
|
4
|
+
"sourcesContent": ["import type {\n OperationObject,\n ParameterObject,\n RequestBodyObject,\n SchemaObject,\n} from 'openapi3-ts/oas31';\n\nimport { followRef, isRef, resolveRef } from '@sdk-it/core/ref.js';\nimport { isEmpty } from '@sdk-it/core/utils.js';\n\nimport { findUniqueSchemaName } from '../find-unique-schema-name.js';\nimport { iterateOperations } from '../for-each-operation.js';\nimport type { DocumentPlugin } from '../processing.js';\nimport type { IR, OurRequestBodyObject, ProcessingDocument } from '../types.js';\n\nexport function patchParameters(\n spec: Pick<IR, 'components'>,\n schema: SchemaObject,\n parameters: ParameterObject[],\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 schema['x-required'] = [...required];\n}\n\n/**\n * The object a generator types for a schema: its own properties plus the\n * parameters {@link patchParameters} records beside them, every required name\n * included.\n */\nexport function withParameters(schema: SchemaObject): SchemaObject {\n const merged = structuredClone(schema);\n if (merged['x-properties']) {\n merged.properties = { ...merged.properties, ...merged['x-properties'] };\n }\n if (merged['x-required']) {\n merged.required = [\n ...new Set([...(merged.required ?? []), ...merged['x-required']]),\n ];\n }\n return merged;\n}\n\nfunction normalizeRequestBody(\n spec: ProcessingDocument,\n operationId: string,\n operation: OperationObject,\n parameters: ParameterObject[],\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);\n const normalized: 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 normalized;\n }\n const content: OurRequestBodyObject['content'] = {};\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 break;\n case isEmpty(mediaType.schema):\n schema ??= {};\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);\n spec.components.schemas[inputName] = {\n ...schema,\n 'x-requestbody': true,\n 'x-inputname': inputName,\n };\n\n content[contentType] = {\n ...mediaType,\n schema: { $ref: `#/components/schemas/${inputName}` },\n };\n }\n return { ...requestBody, content };\n}\n\nexport function normalizeRequestBodies(): DocumentPlugin {\n return {\n name: 'normalize-request-bodies',\n process({ spec }) {\n for (const { entry, operation } of iterateOperations(spec)) {\n const { operationId, parameters } = operation;\n if (\n !operationId ||\n !parameters?.every(\n (parameter): parameter is ParameterObject => !isRef(parameter),\n )\n ) {\n throw new Error(\n `Cannot normalize request bodies before assigning an operation ID and resolving parameters for ${entry.method.toUpperCase()} ${entry.path}`,\n );\n }\n if (operation.requestBody) {\n const requestBody = resolveRef<RequestBodyObject>(\n spec,\n operation.requestBody,\n );\n const schemas = Object.values(requestBody.content).map(\n ({ schema }) =>\n schema ? resolveRef<SchemaObject>(spec, schema) : undefined,\n );\n if (\n schemas.length > 0 &&\n schemas.every(\n (schema): schema is SchemaObject => !!schema?.['x-requestbody'],\n )\n ) {\n for (const schema of new Set(schemas)) {\n patchParameters(spec, schema, parameters);\n }\n operation.requestBody = requestBody;\n continue;\n }\n }\n operation.requestBody = normalizeRequestBody(\n spec,\n operationId,\n operation,\n parameters,\n );\n }\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AAOA,SAAS,WAAW,OAAO,kBAAkB;AAC7C,SAAS,eAAe;AAExB,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAI3B,SAAS,gBACd,MACA,QACA,YACA;AACA,QAAM,WAAW,IAAI;AAAA,IACnB,MAAM,QAAQ,OAAO,QAAQ,IAAI,OAAO,WAAW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/D,GACA;AACA,gBAAM,IAAI;AAAA,YACR,iGAAiG,MAAM,OAAO,YAAY,CAAC,IAAI,MAAM,IAAI;AAAA,UAC3I;AAAA,QACF;AACA,YAAI,UAAU,aAAa;AACzB,gBAAM,cAAc;AAAA,YAClB;AAAA,YACA,UAAU;AAAA,UACZ;AACA,gBAAM,UAAU,OAAO,OAAO,YAAY,OAAO,EAAE;AAAA,YACjD,CAAC,EAAE,OAAO,MACR,SAAS,WAAyB,MAAM,MAAM,IAAI;AAAA,UACtD;AACA,cACE,QAAQ,SAAS,KACjB,QAAQ;AAAA,YACN,CAAC,WAAmC,CAAC,CAAC,SAAS,eAAe;AAAA,UAChE,GACA;AACA,uBAAW,UAAU,IAAI,IAAI,OAAO,GAAG;AACrC,8BAAgB,MAAM,QAAQ,UAAU;AAAA,YAC1C;AACA,sBAAU,cAAc;AACxB;AAAA,UACF;AAAA,QACF;AACA,kBAAU,cAAc;AAAA,UACtB;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function normalizeResponses():
|
|
1
|
+
import type { DocumentPlugin } from '../processing.js';
|
|
2
|
+
export declare function normalizeResponses(): DocumentPlugin;
|
|
3
3
|
//# sourceMappingURL=normalize-responses.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-responses.d.ts","
|
|
1
|
+
{"version":3,"file":"normalize-responses.d.ts","sources":["../../../src/lib/processing-plugins/normalize-responses.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AA8JvD,wBAAgB,kBAAkB,IAAI,cAAc,CA8BnD"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { parse as parseContentType } from "fast-content-type-parse";
|
|
2
1
|
import { isRef, parseRef, resolveRef } from "@sdk-it/core/ref.js";
|
|
3
2
|
import { isEmpty, pascalcase } from "@sdk-it/core/utils.js";
|
|
4
3
|
import { findUniqueSchemaName } from "../find-unique-schema-name.js";
|
|
@@ -42,9 +41,11 @@ function normalizeOperationResponses(spec, operationId, operation, responsesConf
|
|
|
42
41
|
continue;
|
|
43
42
|
}
|
|
44
43
|
let responseName;
|
|
45
|
-
for (const [contentType, mediaType] of Object.entries(
|
|
46
|
-
response.
|
|
47
|
-
|
|
44
|
+
for (const [contentType, mediaType] of Object.entries(response.content)) {
|
|
45
|
+
const body = mediaBody(contentType, response.headers);
|
|
46
|
+
if (body === "text" && !describesString(spec, mediaType.schema)) {
|
|
47
|
+
mediaType.schema = { type: "string" };
|
|
48
|
+
}
|
|
48
49
|
if (isRef(mediaType.schema)) {
|
|
49
50
|
const { model } = parseRef(mediaType.schema.$ref);
|
|
50
51
|
Object.assign(spec.components.schemas[model], {
|
|
@@ -63,7 +64,6 @@ function normalizeOperationResponses(spec, operationId, operation, responsesConf
|
|
|
63
64
|
"result"
|
|
64
65
|
]);
|
|
65
66
|
responseName ??= outputName;
|
|
66
|
-
const body = mediaBody(contentType, response.headers);
|
|
67
67
|
if (body === "json") {
|
|
68
68
|
if (isEmpty(mediaType.schema)) {
|
|
69
69
|
spec.components.schemas[outputName] = {
|
|
@@ -71,11 +71,8 @@ function normalizeOperationResponses(spec, operationId, operation, responsesConf
|
|
|
71
71
|
additionalProperties: true
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
-
} else if (
|
|
75
|
-
mediaType.schema = {
|
|
76
|
-
type: "string",
|
|
77
|
-
...body === "binary" ? { format: "binary" } : {}
|
|
78
|
-
};
|
|
74
|
+
} else if (body === "binary" && isEmpty(mediaType.schema)) {
|
|
75
|
+
mediaType.schema = { type: "string", format: "binary" };
|
|
79
76
|
}
|
|
80
77
|
spec.components.schemas[outputName] = {
|
|
81
78
|
...spec.components.schemas[outputName],
|
|
@@ -130,11 +127,7 @@ function mediaBody(contentType, headers) {
|
|
|
130
127
|
return void 0;
|
|
131
128
|
}
|
|
132
129
|
function normalizeContentType(contentType) {
|
|
133
|
-
|
|
134
|
-
return parseContentType(contentType)?.type?.toLowerCase();
|
|
135
|
-
} catch {
|
|
136
|
-
return contentType.split(";")[0]?.trim().toLowerCase();
|
|
137
|
-
}
|
|
130
|
+
return contentType.split(";")[0].trim().toLowerCase();
|
|
138
131
|
}
|
|
139
132
|
function hasHeader(headers, name) {
|
|
140
133
|
if (!headers) {
|
|
@@ -174,6 +167,9 @@ function normalizeResponses() {
|
|
|
174
167
|
}
|
|
175
168
|
};
|
|
176
169
|
}
|
|
170
|
+
function describesString(spec, schema) {
|
|
171
|
+
return schema !== void 0 && resolveRef(spec, schema).type === "string";
|
|
172
|
+
}
|
|
177
173
|
export {
|
|
178
174
|
normalizeResponses
|
|
179
175
|
};
|