@sdk-it/spec 0.46.1 → 0.46.2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-inline-schemas.d.ts","sourceRoot":"","sources":["../../../src/lib/processing-plugins/extract-inline-schemas.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"extract-inline-schemas.d.ts","sourceRoot":"","sources":["../../../src/lib/processing-plugins/extract-inline-schemas.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AA4LzD,wBAAgB,oBAAoB,IAAI,gBAAgB,CAOvD"}
|
|
@@ -5,18 +5,15 @@ function extractInlineSchemaComponents(spec, schemas) {
|
|
|
5
5
|
if (isRef(schema)) continue;
|
|
6
6
|
if (!isEmpty(schema.properties)) {
|
|
7
7
|
if (!isEmpty(schema.oneOf)) {
|
|
8
|
-
for (const oneOfIndex
|
|
9
|
-
const oneOf = schema.oneOf[oneOfIndex];
|
|
8
|
+
for (const [oneOfIndex, oneOf] of schema.oneOf.entries()) {
|
|
10
9
|
if (isRef(oneOf)) continue;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
10
|
+
const requiredProperty = oneOf.required?.[0];
|
|
11
|
+
if (requiredProperty && isEmpty(oneOf.properties) && isEmpty(oneOf["x-properties"])) {
|
|
12
|
+
schema.oneOf[oneOfIndex] = schema.properties?.[requiredProperty] ?? schema["x-properties"]?.[requiredProperty] ?? oneOf;
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
delete schema.type;
|
|
18
|
-
|
|
19
|
-
continue;
|
|
16
|
+
extractInlineUnion(spec, name, schema, "oneOf");
|
|
20
17
|
}
|
|
21
18
|
if (schema.additionalProperties) {
|
|
22
19
|
continue;
|
|
@@ -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 { ProcessingPlugin } 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
|
|
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,
|
|
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 { ProcessingPlugin } 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 as Record<\n string,\n SchemaObject | ReferenceObject\n >;\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 = schema['x-properties'] as Record<\n string,\n SchemaObject | ReferenceObject\n >;\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 = 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 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(): ProcessingPlugin {\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,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,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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,uBAAyC;AACvD,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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdk-it/spec",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.2",
|
|
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.46.
|
|
30
|
+
"@sdk-it/core": "0.46.2",
|
|
31
31
|
"openapi3-ts": "4.5.0",
|
|
32
32
|
"pluralize": "^8.0.0",
|
|
33
33
|
"stringcase": "^4.3.1",
|