@sdk-it/spec 0.28.0 → 0.29.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 +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/find-polymorphic-varients.test.js +1 -1
- package/dist/lib/find-polymorphic-varients.test.js.map +1 -1
- package/dist/lib/{operation.d.ts → ir.d.ts} +1 -1
- package/dist/lib/ir.d.ts.map +1 -0
- package/dist/lib/{operation.js → ir.js} +1 -1
- package/dist/lib/{operation.js.map → ir.js.map} +1 -1
- package/dist/lib/ir.test.d.ts +2 -0
- package/dist/lib/ir.test.d.ts.map +1 -0
- package/dist/lib/{operation.test.js → ir.test.js} +1 -1
- package/dist/lib/{operation.test.js.map → ir.test.js.map} +1 -1
- package/dist/lib/options.d.ts +1 -1
- package/dist/lib/options.d.ts.map +1 -1
- package/dist/lib/options.js +2 -1
- package/dist/lib/options.js.map +2 -2
- package/dist/lib/overview-docs/doc-templates.d.ts +51 -0
- package/dist/lib/overview-docs/doc-templates.d.ts.map +1 -0
- package/dist/lib/overview-docs/doc-templates.js +123 -0
- package/dist/lib/overview-docs/doc-templates.js.map +7 -0
- package/dist/lib/overview-docs/doc-text-utils.d.ts +86 -0
- package/dist/lib/overview-docs/doc-text-utils.d.ts.map +1 -0
- package/dist/lib/overview-docs/doc-text-utils.js +108 -0
- package/dist/lib/overview-docs/doc-text-utils.js.map +7 -0
- package/dist/lib/overview-docs/overview-auth.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-auth.js +34 -52
- package/dist/lib/overview-docs/overview-auth.js.map +2 -2
- package/dist/lib/overview-docs/overview-errors.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-errors.js +11 -28
- package/dist/lib/overview-docs/overview-errors.js.map +2 -2
- package/dist/lib/overview-docs/overview-intro.d.ts +1 -1
- package/dist/lib/overview-docs/overview-intro.d.ts.map +1 -1
- package/dist/lib/overview-docs/overview-intro.js +41 -36
- package/dist/lib/overview-docs/overview-intro.js.map +2 -2
- package/dist/lib/tune.test.js +1 -1
- package/dist/lib/tune.test.js.map +1 -1
- package/dist/lib/types.d.ts +2 -1
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/lib/operation.d.ts.map +0 -1
- package/dist/lib/operation.test.d.ts +0 -2
- package/dist/lib/operation.test.d.ts.map +0 -1
- package/dist/lib/overview-docs/overview-quick-reference.d.ts +0 -4
- package/dist/lib/overview-docs/overview-quick-reference.d.ts.map +0 -1
- package/dist/lib/overview-docs/overview-sdk-examples.d.ts +0 -4
- package/dist/lib/overview-docs/overview-sdk-examples.d.ts.map +0 -1
- package/dist/lib/overview-docs/overview-usage.d.ts +0 -4
- package/dist/lib/overview-docs/overview-usage.d.ts.map +0 -1
- package/dist/lib/overview-docs.d.ts +0 -4
- package/dist/lib/overview-docs.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,13 +4,13 @@ export * from './lib/find-unique-schema-name.js';
|
|
|
4
4
|
export * from './lib/for-each-operation.js';
|
|
5
5
|
export * from './lib/format-name.js';
|
|
6
6
|
export * from './lib/get-ref-usage.js';
|
|
7
|
+
export * from './lib/ir.js';
|
|
7
8
|
export * from './lib/is-primitive-schema.js';
|
|
8
9
|
export * from './lib/is.js';
|
|
9
10
|
export * from './lib/loaders/load-spec.js';
|
|
10
11
|
export * from './lib/loaders/local-loader.js';
|
|
11
12
|
export * from './lib/loaders/remote-loader.js';
|
|
12
13
|
export * from './lib/metadata.js';
|
|
13
|
-
export * from './lib/operation.js';
|
|
14
14
|
export * from './lib/options.js';
|
|
15
15
|
export * from './lib/overview-docs/overview-errors.js';
|
|
16
16
|
export * from './lib/reserved-keywords.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mBAAmB,CAAC;AAClC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wCAAwC,CAAC;AACvD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,13 +4,13 @@ export * from "./lib/find-unique-schema-name.js";
|
|
|
4
4
|
export * from "./lib/for-each-operation.js";
|
|
5
5
|
export * from "./lib/format-name.js";
|
|
6
6
|
export * from "./lib/get-ref-usage.js";
|
|
7
|
+
export * from "./lib/ir.js";
|
|
7
8
|
export * from "./lib/is-primitive-schema.js";
|
|
8
9
|
export * from "./lib/is.js";
|
|
9
10
|
export * from "./lib/loaders/load-spec.js";
|
|
10
11
|
export * from "./lib/loaders/local-loader.js";
|
|
11
12
|
export * from "./lib/loaders/remote-loader.js";
|
|
12
13
|
export * from "./lib/metadata.js";
|
|
13
|
-
export * from "./lib/operation.js";
|
|
14
14
|
export * from "./lib/options.js";
|
|
15
15
|
export * from "./lib/overview-docs/overview-errors.js";
|
|
16
16
|
export * from "./lib/reserved-keywords.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './lib/create-operation.js';\nexport * from './lib/find-polymorphic-varients.js';\nexport * from './lib/find-unique-schema-name.js';\nexport * from './lib/for-each-operation.js';\nexport * from './lib/format-name.js';\nexport * from './lib/get-ref-usage.js';\nexport * from './lib/is-primitive-schema.js';\nexport * from './lib/is.js';\nexport * from './lib/loaders/load-spec.js';\nexport * from './lib/loaders/local-loader.js';\nexport * from './lib/loaders/remote-loader.js';\nexport * from './lib/metadata.js';\nexport * from './lib/
|
|
4
|
+
"sourcesContent": ["export * from './lib/create-operation.js';\nexport * from './lib/find-polymorphic-varients.js';\nexport * from './lib/find-unique-schema-name.js';\nexport * from './lib/for-each-operation.js';\nexport * from './lib/format-name.js';\nexport * from './lib/get-ref-usage.js';\nexport * from './lib/ir.js';\nexport * from './lib/is-primitive-schema.js';\nexport * from './lib/is.js';\nexport * from './lib/loaders/load-spec.js';\nexport * from './lib/loaders/local-loader.js';\nexport * from './lib/loaders/remote-loader.js';\nexport * from './lib/metadata.js';\nexport * from './lib/options.js';\nexport * from './lib/overview-docs/overview-errors.js';\nexport * from './lib/reserved-keywords.js';\nexport * from './lib/security.js';\nexport * from './lib/sidebar.js';\nexport * from './lib/tag.js';\nexport * from './lib/tune-request-body.js';\nexport * from './lib/tune-response.js';\nexport * from './lib/tune.js';\nexport * from './lib/types.js';\n"],
|
|
5
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;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/find-polymorphic-varients.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { merge } from 'lodash-es';\nimport assert from 'node:assert';\nimport { describe, it } from 'node:test';\nimport type { OpenAPIObject, SchemaObject } from 'openapi3-ts/oas31';\n\nimport {\n type Varient,\n findPolymorphicVarients,\n findVarients,\n} from './find-polymorphic-varients.ts';\nimport { augmentSpec } from './operation.ts';\nimport type { OurOpenAPIObject } from './types.ts';\n\nfunction createSpec(openapi?: Partial<OpenAPIObject>): OurOpenAPIObject {\n return augmentSpec(\n {\n spec: merge(\n {\n openapi: '3.1.0',\n info: {\n title: 'Test API',\n version: '1.0.0',\n },\n components: {\n schemas: {},\n securitySchemes: {},\n },\n paths: {},\n },\n openapi,\n ),\n },\n true,\n );\n}\ndescribe('findVarients', () => {\n describe('strings', () => {\n it('names string type as text', () => {\n const spec = createSpec();\n const result = findVarients(spec, [{ type: 'string' }]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'text',\n position: 0,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n it('names string based on format', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n {\n type: 'string',\n format: 'date-time',\n },\n { type: 'string' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'dateTime',\n position: 0,\n priority: 90,\n type: 'string',\n },\n {\n name: 'text',\n position: 1,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it('names string based on const value', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n { type: 'string', const: 'active' },\n { type: 'string', const: '' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'active',\n position: 0,\n priority: 100,\n type: 'string',\n },\n {\n name: 'empty',\n position: 1,\n priority: 99,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it.skip('names string based on enum values', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n { type: 'string', enum: ['pending', 'completed', ''] },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'pending',\n position: 0,\n priority: 80,\n type: 'string',\n },\n {\n name: 'completed',\n position: 0,\n priority: 79,\n type: 'string',\n },\n {\n name: 'empty',\n position: 0,\n priority: 78,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it.skip('prioritizes const first', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n { type: 'string', format: 'email' },\n { type: 'string', const: 'fixed' },\n { type: 'string', enum: ['option1', 'option2'] },\n { type: 'string' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'fixed',\n position: 1,\n priority: 99,\n type: 'string',\n },\n {\n name: 'email',\n position: 0,\n priority: 90,\n type: 'string',\n },\n {\n name: 'option1',\n position: 2,\n priority: 78,\n type: 'string',\n },\n {\n name: 'option2',\n position: 2,\n priority: 77,\n type: 'string',\n },\n {\n name: 'text',\n position: 3,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it('handles format priority over enum', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n { type: 'string', format: 'email', enum: ['user@example.com'] },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'email',\n position: 0,\n priority: 90,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it('handles const priority over enum', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n { type: 'string', const: 'fixed', enum: ['option1', 'option2'] },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'fixed',\n position: 0,\n priority: 100,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it('handles complex format names with camelCase conversion', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n { type: 'string', format: 'date-time' },\n { type: 'string', format: 'iso-8601' },\n { type: 'string', format: 'binary' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'dateTime',\n position: 0,\n priority: 90,\n type: 'string',\n },\n {\n name: 'iso8601',\n position: 1,\n priority: 89,\n type: 'string',\n },\n {\n name: 'binary',\n position: 2,\n priority: 88,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n });\n\n describe('numbers', () => {\n it('names number type as number', () => {\n const spec = createSpec();\n const result = findVarients(spec, [{ type: 'number' }]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'number',\n position: 0,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n\n it('names integer type as integer', () => {\n const spec = createSpec();\n const result = findVarients(spec, [{ type: 'integer' }]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'number',\n position: 0,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n\n it('names number based on format', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n {\n type: 'number',\n format: 'float',\n },\n {\n type: 'number',\n format: 'double',\n },\n {\n type: 'integer',\n format: 'int64',\n },\n { type: 'number' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'float',\n position: 0,\n priority: 90,\n type: 'number',\n },\n {\n name: 'double',\n position: 1,\n priority: 89,\n type: 'number',\n },\n {\n name: 'integer',\n position: 2,\n priority: 87,\n type: 'number',\n },\n {\n name: 'number',\n position: 3,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n });\n\n describe('mixed types', () => {\n it('handles mixed string and number types', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n { type: 'number' },\n { type: 'string' },\n ]);\n assert.deepStrictEqual(result, [\n {\n name: 'text',\n position: 1,\n type: 'string',\n },\n {\n name: 'number',\n position: 0,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n });\n});\n\ndescribe('findPolymorphicVarients', () => {\n describe('strings', () => {\n it('returns single variant per position for multiple strings', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'string', format: 'date-time' },\n { type: 'string' },\n { type: 'string', const: 'active' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'active',\n position: 2,\n priority: 98,\n type: 'string',\n },\n {\n name: 'dateTime',\n position: 0,\n priority: 90,\n type: 'string',\n },\n {\n name: 'text',\n position: 1,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it.skip('returns first variant when multiple enums at same position', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'string', enum: ['first', 'second', 'third'] },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'first',\n position: 0,\n priority: 80,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it.skip('selects first variant from multiple at same position', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'string', enum: ['option1', 'option2'] },\n { type: 'string', format: 'email' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'email',\n position: 1,\n priority: 88,\n type: 'string',\n },\n {\n name: 'option1',\n position: 0,\n priority: 80,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it.skip('handles mixed types selecting one per position', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'string', enum: ['a', 'b'] },\n { type: 'number' },\n { type: 'string', const: 'fixed' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'fixed',\n position: 2,\n priority: 98,\n type: 'string',\n },\n {\n name: 'a',\n position: 0,\n priority: 80,\n type: 'string',\n },\n {\n name: 'number',\n position: 1,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n\n it('handles plain strings mixed with formatted strings', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'string' },\n { type: 'string', format: 'password' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'password',\n position: 1,\n priority: 89,\n type: 'string',\n },\n {\n name: 'text',\n position: 0,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n it('ignore duplicates', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'string' },\n { type: 'string', format: 'password' },\n { type: 'string' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'password',\n position: 1,\n priority: 89,\n type: 'string',\n },\n {\n name: 'text',\n position: 0,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n });\n\n describe('numbers', () => {\n it('returns single variant per position for multiple numbers', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'number', format: 'float' },\n { type: 'integer' },\n { type: 'number', format: 'double' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'float',\n position: 0,\n priority: 90,\n type: 'number',\n },\n {\n name: 'double',\n position: 2,\n priority: 89,\n type: 'number',\n },\n {\n name: 'number',\n position: 1,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n\n it('returns first variant when multiple number formats at same position', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'number', format: 'float' },\n { type: 'number', format: 'double' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'float',\n position: 0,\n priority: 90,\n type: 'number',\n },\n {\n name: 'double',\n position: 1,\n priority: 89,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n\n it('handles mixed number and integer types', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'integer', format: 'int64' },\n { type: 'number' },\n { type: 'integer' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'integer',\n position: 0,\n priority: 89,\n type: 'number',\n },\n {\n name: 'number',\n position: 1,\n type: 'number',\n },\n {\n name: 'number',\n position: 2,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n\n it('handles plain numbers mixed with formatted numbers', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'number' },\n { type: 'number', format: 'float' },\n { type: 'number' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'float',\n position: 1,\n priority: 89,\n type: 'number',\n },\n {\n name: 'number',\n position: 0,\n type: 'number',\n },\n {\n name: 'number',\n position: 2,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n });\n\n describe('arrays', () => {\n it.only('complex', () => {\n const spec = createSpec({\n components: {\n schemas: {\n RouteConfig: {\n anyOf: [\n {\n type: 'array',\n items: {\n anyOf: [\n {\n type: 'string',\n enum: ['image', 'video', 'audio'],\n },\n {\n type: 'string',\n enum: [\n 'application/andrew-inset',\n 'application/applixware',\n ],\n },\n ],\n },\n },\n {\n type: 'object',\n additionalProperties: {\n type: 'object',\n properties: {\n maxFileSize: {\n type: 'string',\n description:\n 'The maximum file size allowed for a given file type.',\n example: '4MB',\n },\n maxFileCount: {\n type: 'number',\n description:\n 'Maximum allowed files for a given file type.',\n example: 1,\n },\n contentDisposition: {\n type: 'string',\n enum: ['inline', 'attachment'],\n default: 'inline',\n },\n acl: {\n type: 'string',\n enum: ['public-read', 'private'],\n },\n },\n },\n },\n ],\n },\n },\n },\n });\n const varients = findVarients(\n spec,\n (spec.components.schemas.RouteConfig as SchemaObject).anyOf ?? [],\n );\n\n assert.deepStrictEqual(varients, [\n {\n name: 'textList',\n type: 'array',\n subtype: 'string',\n position: 0,\n },\n {\n static: true,\n subtype: 'string',\n source: 'public-read',\n name: 'public-read',\n type: 'object',\n position: 1,\n },\n ]);\n });\n });\n});\n"],
|
|
4
|
+
"sourcesContent": ["import { merge } from 'lodash-es';\nimport assert from 'node:assert';\nimport { describe, it } from 'node:test';\nimport type { OpenAPIObject, SchemaObject } from 'openapi3-ts/oas31';\n\nimport {\n type Varient,\n findPolymorphicVarients,\n findVarients,\n} from './find-polymorphic-varients.ts';\nimport { augmentSpec } from './ir.ts';\nimport type { OurOpenAPIObject } from './types.ts';\n\nfunction createSpec(openapi?: Partial<OpenAPIObject>): OurOpenAPIObject {\n return augmentSpec(\n {\n spec: merge(\n {\n openapi: '3.1.0',\n info: {\n title: 'Test API',\n version: '1.0.0',\n },\n components: {\n schemas: {},\n securitySchemes: {},\n },\n paths: {},\n },\n openapi,\n ),\n },\n true,\n );\n}\ndescribe('findVarients', () => {\n describe('strings', () => {\n it('names string type as text', () => {\n const spec = createSpec();\n const result = findVarients(spec, [{ type: 'string' }]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'text',\n position: 0,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n it('names string based on format', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n {\n type: 'string',\n format: 'date-time',\n },\n { type: 'string' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'dateTime',\n position: 0,\n priority: 90,\n type: 'string',\n },\n {\n name: 'text',\n position: 1,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it('names string based on const value', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n { type: 'string', const: 'active' },\n { type: 'string', const: '' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'active',\n position: 0,\n priority: 100,\n type: 'string',\n },\n {\n name: 'empty',\n position: 1,\n priority: 99,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it.skip('names string based on enum values', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n { type: 'string', enum: ['pending', 'completed', ''] },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'pending',\n position: 0,\n priority: 80,\n type: 'string',\n },\n {\n name: 'completed',\n position: 0,\n priority: 79,\n type: 'string',\n },\n {\n name: 'empty',\n position: 0,\n priority: 78,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it.skip('prioritizes const first', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n { type: 'string', format: 'email' },\n { type: 'string', const: 'fixed' },\n { type: 'string', enum: ['option1', 'option2'] },\n { type: 'string' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'fixed',\n position: 1,\n priority: 99,\n type: 'string',\n },\n {\n name: 'email',\n position: 0,\n priority: 90,\n type: 'string',\n },\n {\n name: 'option1',\n position: 2,\n priority: 78,\n type: 'string',\n },\n {\n name: 'option2',\n position: 2,\n priority: 77,\n type: 'string',\n },\n {\n name: 'text',\n position: 3,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it('handles format priority over enum', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n { type: 'string', format: 'email', enum: ['user@example.com'] },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'email',\n position: 0,\n priority: 90,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it('handles const priority over enum', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n { type: 'string', const: 'fixed', enum: ['option1', 'option2'] },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'fixed',\n position: 0,\n priority: 100,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it('handles complex format names with camelCase conversion', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n { type: 'string', format: 'date-time' },\n { type: 'string', format: 'iso-8601' },\n { type: 'string', format: 'binary' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'dateTime',\n position: 0,\n priority: 90,\n type: 'string',\n },\n {\n name: 'iso8601',\n position: 1,\n priority: 89,\n type: 'string',\n },\n {\n name: 'binary',\n position: 2,\n priority: 88,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n });\n\n describe('numbers', () => {\n it('names number type as number', () => {\n const spec = createSpec();\n const result = findVarients(spec, [{ type: 'number' }]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'number',\n position: 0,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n\n it('names integer type as integer', () => {\n const spec = createSpec();\n const result = findVarients(spec, [{ type: 'integer' }]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'number',\n position: 0,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n\n it('names number based on format', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n {\n type: 'number',\n format: 'float',\n },\n {\n type: 'number',\n format: 'double',\n },\n {\n type: 'integer',\n format: 'int64',\n },\n { type: 'number' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'float',\n position: 0,\n priority: 90,\n type: 'number',\n },\n {\n name: 'double',\n position: 1,\n priority: 89,\n type: 'number',\n },\n {\n name: 'integer',\n position: 2,\n priority: 87,\n type: 'number',\n },\n {\n name: 'number',\n position: 3,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n });\n\n describe('mixed types', () => {\n it('handles mixed string and number types', () => {\n const spec = createSpec();\n const result = findVarients(spec, [\n { type: 'number' },\n { type: 'string' },\n ]);\n assert.deepStrictEqual(result, [\n {\n name: 'text',\n position: 1,\n type: 'string',\n },\n {\n name: 'number',\n position: 0,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n });\n});\n\ndescribe('findPolymorphicVarients', () => {\n describe('strings', () => {\n it('returns single variant per position for multiple strings', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'string', format: 'date-time' },\n { type: 'string' },\n { type: 'string', const: 'active' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'active',\n position: 2,\n priority: 98,\n type: 'string',\n },\n {\n name: 'dateTime',\n position: 0,\n priority: 90,\n type: 'string',\n },\n {\n name: 'text',\n position: 1,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it.skip('returns first variant when multiple enums at same position', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'string', enum: ['first', 'second', 'third'] },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'first',\n position: 0,\n priority: 80,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it.skip('selects first variant from multiple at same position', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'string', enum: ['option1', 'option2'] },\n { type: 'string', format: 'email' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'email',\n position: 1,\n priority: 88,\n type: 'string',\n },\n {\n name: 'option1',\n position: 0,\n priority: 80,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n\n it.skip('handles mixed types selecting one per position', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'string', enum: ['a', 'b'] },\n { type: 'number' },\n { type: 'string', const: 'fixed' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'fixed',\n position: 2,\n priority: 98,\n type: 'string',\n },\n {\n name: 'a',\n position: 0,\n priority: 80,\n type: 'string',\n },\n {\n name: 'number',\n position: 1,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n\n it('handles plain strings mixed with formatted strings', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'string' },\n { type: 'string', format: 'password' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'password',\n position: 1,\n priority: 89,\n type: 'string',\n },\n {\n name: 'text',\n position: 0,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n it('ignore duplicates', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'string' },\n { type: 'string', format: 'password' },\n { type: 'string' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'password',\n position: 1,\n priority: 89,\n type: 'string',\n },\n {\n name: 'text',\n position: 0,\n type: 'string',\n },\n ] satisfies Varient[]);\n });\n });\n\n describe('numbers', () => {\n it('returns single variant per position for multiple numbers', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'number', format: 'float' },\n { type: 'integer' },\n { type: 'number', format: 'double' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'float',\n position: 0,\n priority: 90,\n type: 'number',\n },\n {\n name: 'double',\n position: 2,\n priority: 89,\n type: 'number',\n },\n {\n name: 'number',\n position: 1,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n\n it('returns first variant when multiple number formats at same position', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'number', format: 'float' },\n { type: 'number', format: 'double' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'float',\n position: 0,\n priority: 90,\n type: 'number',\n },\n {\n name: 'double',\n position: 1,\n priority: 89,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n\n it('handles mixed number and integer types', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'integer', format: 'int64' },\n { type: 'number' },\n { type: 'integer' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'integer',\n position: 0,\n priority: 89,\n type: 'number',\n },\n {\n name: 'number',\n position: 1,\n type: 'number',\n },\n {\n name: 'number',\n position: 2,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n\n it('handles plain numbers mixed with formatted numbers', () => {\n const spec = createSpec();\n const result = findPolymorphicVarients(spec, [\n { type: 'number' },\n { type: 'number', format: 'float' },\n { type: 'number' },\n ]);\n\n assert.deepStrictEqual(result, [\n {\n name: 'float',\n position: 1,\n priority: 89,\n type: 'number',\n },\n {\n name: 'number',\n position: 0,\n type: 'number',\n },\n {\n name: 'number',\n position: 2,\n type: 'number',\n },\n ] satisfies Varient[]);\n });\n });\n\n describe('arrays', () => {\n it.only('complex', () => {\n const spec = createSpec({\n components: {\n schemas: {\n RouteConfig: {\n anyOf: [\n {\n type: 'array',\n items: {\n anyOf: [\n {\n type: 'string',\n enum: ['image', 'video', 'audio'],\n },\n {\n type: 'string',\n enum: [\n 'application/andrew-inset',\n 'application/applixware',\n ],\n },\n ],\n },\n },\n {\n type: 'object',\n additionalProperties: {\n type: 'object',\n properties: {\n maxFileSize: {\n type: 'string',\n description:\n 'The maximum file size allowed for a given file type.',\n example: '4MB',\n },\n maxFileCount: {\n type: 'number',\n description:\n 'Maximum allowed files for a given file type.',\n example: 1,\n },\n contentDisposition: {\n type: 'string',\n enum: ['inline', 'attachment'],\n default: 'inline',\n },\n acl: {\n type: 'string',\n enum: ['public-read', 'private'],\n },\n },\n },\n },\n ],\n },\n },\n },\n });\n const varients = findVarients(\n spec,\n (spec.components.schemas.RouteConfig as SchemaObject).anyOf ?? [],\n );\n\n assert.deepStrictEqual(varients, [\n {\n name: 'textList',\n type: 'array',\n subtype: 'string',\n position: 0,\n },\n {\n static: true,\n subtype: 'string',\n source: 'public-read',\n name: 'public-read',\n type: 'object',\n position: 1,\n },\n ]);\n });\n });\n});\n"],
|
|
5
5
|
"mappings": "AAAA,SAAS,aAAa;AACtB,OAAO,YAAY;AACnB,SAAS,UAAU,UAAU;AAG7B;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAG5B,SAAS,WAAW,SAAoD;AACtE,SAAO;AAAA,IACL;AAAA,MACE,MAAM;AAAA,QACJ;AAAA,UACE,SAAS;AAAA,UACT,MAAM;AAAA,YACJ,OAAO;AAAA,YACP,SAAS;AAAA,UACX;AAAA,UACA,YAAY;AAAA,YACV,SAAS,CAAC;AAAA,YACV,iBAAiB,CAAC;AAAA,UACpB;AAAA,UACA,OAAO,CAAC;AAAA,QACV;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACF;AACA,SAAS,gBAAgB,MAAM;AAC7B,WAAS,WAAW,MAAM;AACxB,OAAG,6BAA6B,MAAM;AACpC,YAAM,OAAO,WAAW;AACxB,YAAM,SAAS,aAAa,MAAM,CAAC,EAAE,MAAM,SAAS,CAAC,CAAC;AAEtD,aAAO,gBAAgB,QAAQ;AAAA,QAC7B;AAAA,UACE,MAAM;AAAA,UACN,UAAU;AAAA,UACV,MAAM;AAAA,QACR;AAAA,MACF,CAAqB;AAAA,IACvB,CAAC;AACD,OAAG,gCAAgC,MAAM;AACvC,YAAM,OAAO,WAAW;AACxB,YAAM,SAAS,aAAa,MAAM;AAAA,QAChC;AAAA,UACE,MAAM;AAAA,UACN,QAAQ;AAAA,QACV;AAAA,QACA,EAAE,MAAM,SAAS;AAAA,MACnB,CAAC;AAED,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
2
2
|
import type { OurOpenAPIObject } from './types.js';
|
|
3
3
|
export declare function augmentSpec(config: GenerateSdkConfig, verbose?: boolean): OurOpenAPIObject;
|
|
4
|
-
//# sourceMappingURL=
|
|
4
|
+
//# sourceMappingURL=ir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir.d.ts","sourceRoot":"","sources":["../../src/lib/ir.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,iBAAiB,EAAiB,MAAM,cAAc,CAAC;AAMrE,OAAO,KAAK,EAAE,gBAAgB,EAAwB,MAAM,YAAY,CAAC;AAiCzE,wBAAgB,WAAW,CACzB,MAAM,EAAE,iBAAiB,EACzB,OAAO,UAAQ,GACd,gBAAgB,CAsGlB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/lib/
|
|
3
|
+
"sources": ["../../src/lib/ir.ts"],
|
|
4
4
|
"sourcesContent": ["import type {\n OperationObject,\n ParameterObject,\n PathsObject,\n SchemaObject,\n} from 'openapi3-ts/oas31';\n\nimport { type Method, methods } from '@sdk-it/core/paths.js';\nimport { resolveRef } from '@sdk-it/core/ref.js';\nimport { snakecase } from '@sdk-it/core/utils.js';\n\nimport { toResource } from './guess/guess-resource.js';\nimport { type GenerateSdkConfig, coeraceConfig } from './options.js';\nimport { extractOverviewDocs } from './overview-docs/overview-docs.js';\nimport { toPagination } from './pagination/pagination.js';\nimport { tuneRequestBody } from './tune-request-body.js';\nimport { resolveResponses } from './tune-response.js';\nimport { expandSpec, fixSpec } from './tune.js';\nimport type { OurOpenAPIObject, TunedOperationObject } from './types.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 // Try each prepend option\n const prependIndex = Math.min(counter - 1, choices.length - 1);\n const prefix = choices[prependIndex];\n\n if (prependIndex < choices.length - 1) {\n // Using one of the prepend options\n uniqueOperationId = formatter(\n `${prefix}${initialId.charAt(0).toUpperCase() + initialId.slice(1)}`,\n );\n } else {\n // If we've exhausted all prepend options, start adding numbers\n uniqueOperationId = formatter(\n `${prefix}${initialId.charAt(0).toUpperCase() + initialId.slice(1)}${counter - choices.length + 1}`,\n );\n }\n counter++;\n }\n\n return uniqueOperationId;\n}\n\nexport function augmentSpec(\n config: GenerateSdkConfig,\n verbose = false,\n): OurOpenAPIObject {\n const coearcedConfig = coeraceConfig(config);\n if ('x-sdk-augmented' in config.spec) {\n return config.spec as OurOpenAPIObject; // Already augmented\n }\n\n const paths: PathsObject = {};\n const usedOperationIds = new Set<string>();\n\n for (const [path, pathItem] of Object.entries(coearcedConfig.spec.paths)) {\n // Convert Express-style routes (:param) to OpenAPI-style routes ({param})\n const fixedPath = path.replace(/:([^/]+)/g, '{$1}');\n for (const [method, operation] of Object.entries(pathItem) as [\n Method,\n OperationObject,\n ][]) {\n if (!methods.includes(method)) {\n continue;\n }\n const { name } = toResource(operation, fixedPath, method);\n const operationTag = coearcedConfig.tag(operation, fixedPath);\n const operationId = findUniqueOperationId(\n usedOperationIds,\n coearcedConfig.operationId(operation, fixedPath, method),\n [operationTag, method, fixedPath.split('/').filter(Boolean).join('')],\n (id) =>\n coearcedConfig.operationId(\n { ...operation, operationId: id },\n fixedPath,\n method,\n ),\n );\n usedOperationIds.add(operationId);\n\n const parameters = [\n ...(pathItem.parameters ?? []),\n ...(operation.parameters ?? []),\n ].map((it) => resolveRef<ParameterObject>(coearcedConfig.spec, it));\n\n const tunedOperation: TunedOperationObject = {\n ...operation,\n parameters,\n 'x-fn-name': name,\n 'x-fn-group': operationTag,\n tags: [snakecase(operationTag)],\n operationId: operationId,\n responses: resolveResponses(\n coearcedConfig.spec,\n operationId,\n operation,\n coearcedConfig.responses,\n ),\n requestBody: tuneRequestBody(\n coearcedConfig.spec,\n operationId,\n // camelcase(`${name} ${operationTag}`),\n operation,\n parameters,\n operation.security ?? [],\n ),\n };\n\n if (coearcedConfig.pagination.enabled) {\n if (coearcedConfig.pagination.guess) {\n tunedOperation['x-pagination'] = toPagination(\n coearcedConfig.spec,\n tunedOperation,\n );\n }\n } else {\n delete tunedOperation['x-pagination'];\n }\n\n Object.assign(paths, {\n [fixedPath]: {\n ...paths[fixedPath],\n [method]: tunedOperation,\n },\n });\n }\n }\n\n fixSpec(\n coearcedConfig.spec,\n Object.values(coearcedConfig.spec.components.schemas),\n );\n\n if (verbose) {\n const newRefs: { name: string; value: SchemaObject }[] = [];\n expandSpec(\n coearcedConfig.spec,\n coearcedConfig.spec.components.schemas,\n newRefs,\n );\n }\n\n return {\n ...coearcedConfig.spec,\n paths,\n 'x-docs': extractOverviewDocs(coearcedConfig.spec),\n 'x-sdk-augmented': true,\n };\n}\n"],
|
|
5
5
|
"mappings": "AAOA,SAAsB,eAAe;AACrC,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAE1B,SAAS,kBAAkB;AAC3B,SAAiC,qBAAqB;AACtD,SAAS,2BAA2B;AACpC,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,YAAY,eAAe;AAGpC,SAAS,sBACP,kBACA,WACA,SACA,WACA;AACA,MAAI,UAAU;AACd,MAAI,oBAAoB,UAAU,SAAS;AAE3C,SAAO,iBAAiB,IAAI,iBAAiB,GAAG;AAE9C,UAAM,eAAe,KAAK,IAAI,UAAU,GAAG,QAAQ,SAAS,CAAC;AAC7D,UAAM,SAAS,QAAQ,YAAY;AAEnC,QAAI,eAAe,QAAQ,SAAS,GAAG;AAErC,0BAAoB;AAAA,QAClB,GAAG,MAAM,GAAG,UAAU,OAAO,CAAC,EAAE,YAAY,IAAI,UAAU,MAAM,CAAC,CAAC;AAAA,MACpE;AAAA,IACF,OAAO;AAEL,0BAAoB;AAAA,QAClB,GAAG,MAAM,GAAG,UAAU,OA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M,CAAC,UAAU,YAAY,CAAC;AAAA,QAC9B;AAAA,QACA,WAAW;AAAA,UACT,eAAe;AAAA,UACf;AAAA,UACA;AAAA,UACA,eAAe;AAAA,QACjB;AAAA,QACA,aAAa;AAAA,UACX,eAAe;AAAA,UACf;AAAA;AAAA,UAEA;AAAA,UACA;AAAA,UACA,UAAU,YAAY,CAAC;AAAA,QACzB;AAAA,MACF;AAEA,UAAI,eAAe,WAAW,SAAS;AACrC,YAAI,eAAe,WAAW,OAAO;AACnC,yBAAe,cAAc,IAAI;AAAA,YAC/B,eAAe;AAAA,YACf;AAAA,UACF;AAAA,QACF;AAAA,MACF,OAAO;AACL,eAAO,eAAe,cAAc;AAAA,MACtC;AAEA,aAAO,OAAO,OAAO;AAAA,QACnB,CAAC,SAAS,GAAG;AAAA,UACX,GAAG,MAAM,SAAS;AAAA,UAClB,CAAC,MAAM,GAAG;AAAA,QACZ;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA;AAAA,IACE,eAAe;AAAA,IACf,OAAO,OAAO,eAAe,KAAK,WAAW,OAAO;AAAA,EACtD;AAEA,MAAI,SAAS;AACX,UAAM,UAAmD,CAAC;AAC1D;AAAA,MACE,eAAe;AAAA,MACf,eAAe,KAAK,WAAW;AAAA,MAC/B;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG,eAAe;AAAA,IAClB;AAAA,IACA,UAAU,oBAAoB,eAAe,IAAI;AAAA,IACjD,mBAAmB;AAAA,EACrB;AACF;",
|
|
6
6
|
"names": []
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir.test.d.ts","sourceRoot":"","sources":["../../src/lib/ir.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/lib/
|
|
3
|
+
"sources": ["../../src/lib/ir.test.ts"],
|
|
4
4
|
"sourcesContent": ["import assert from 'node:assert/strict';\nimport { describe, test } from 'node:test';\nimport type { OperationObject } from 'openapi3-ts/oas31';\n\nimport { determineGenericTag } from './tag.ts';\n\nconst mockOperation = (operationId = ''): OperationObject => ({ operationId });\n\ndescribe('determineGenericTag', () => {\n describe('Heuristic 1: Path-Based Tag Determination', () => {\n test('should use the last non-parameter, non-version, non-@ segment', () => {\n assert.strictEqual(\n determineGenericTag('/users', mockOperation()),\n 'users',\n );\n assert.strictEqual(\n determineGenericTag('/users/{userId}/orders', mockOperation()),\n 'orders',\n );\n assert.strictEqual(\n determineGenericTag('/admin/system/logs', mockOperation()),\n 'logs',\n );\n });\n\n test('should ignore path parameters', () => {\n assert.strictEqual(\n determineGenericTag('/users/{userId}', mockOperation()),\n 'users',\n );\n assert.strictEqual(\n determineGenericTag('/items/{itemId}', mockOperation()),\n 'items',\n );\n });\n\n test('should ignore version segments', () => {\n assert.strictEqual(\n determineGenericTag('/v1/products', mockOperation()),\n 'products',\n );\n assert.strictEqual(\n determineGenericTag('/api/V2/items/{itemId}/details', mockOperation()),\n 'details',\n );\n assert.strictEqual(\n determineGenericTag('/api/resource/v2', mockOperation()),\n 'resource',\n );\n });\n\n test('should ignore segments starting with @', () => {\n assert.strictEqual(\n determineGenericTag('/users/@me', mockOperation()),\n 'users',\n );\n assert.strictEqual(\n determineGenericTag('/users/@me/guilds', mockOperation()),\n 'guilds',\n );\n assert.strictEqual(\n determineGenericTag(\n '/webhooks/{webhookId}/messages/@original',\n mockOperation(),\n ),\n 'messages',\n );\n assert.strictEqual(\n determineGenericTag('/@admin/users/{userId}', mockOperation()),\n 'users',\n );\n assert.strictEqual(\n determineGenericTag(\n '/guilds/{guild_id}/@audit-log/users/@me/settings',\n mockOperation(),\n ),\n 'settings',\n );\n assert.strictEqual(\n determineGenericTag('/system/tasks/@scheduled-jobs', mockOperation()),\n 'tasks',\n );\n });\n\n test('should sanitize results matching reserved keywords', () => {\n assert.strictEqual(\n determineGenericTag('/api/v1/public', mockOperation()),\n 'public_',\n );\n assert.strictEqual(\n determineGenericTag('/api/case/{id}', mockOperation()),\n 'case_',\n );\n assert.strictEqual(\n determineGenericTag('/permissions/check', mockOperation()),\n 'check_',\n );\n });\n\n test('should sanitize results starting with numbers', () => {\n // FIX: Expectation changed - last valid segment is 'enable'\n assert.strictEqual(\n determineGenericTag('/api/2fa/enable', mockOperation()),\n 'enable',\n );\n });\n\n test('should handle mixed separators via camelcase', () => {\n assert.strictEqual(\n determineGenericTag('/user-profiles/{id}', mockOperation()),\n 'userProfiles',\n );\n });\n });\n\n describe('Heuristic 2: OperationId Fallback', () => {\n test('should be used when path has no valid segments (root)', () => {\n assert.strictEqual(\n determineGenericTag('/', mockOperation('getRootResource')),\n 'rootResource',\n );\n // FIX: Expectation changed - 'healthCheck' is not reserved\n assert.strictEqual(\n determineGenericTag('/', mockOperation('healthCheck')),\n 'healthCheck',\n );\n });\n\n test('should be used when path has only params/version segments', () => {\n assert.strictEqual(\n determineGenericTag('/v3/{tenantId}/', mockOperation('getTenantRoot')),\n 'tenantRoot',\n );\n assert.strictEqual(\n determineGenericTag('/v1/{userId}/', mockOperation('listUserItems')),\n 'userItems',\n );\n });\n\n test('should extract nouns after common verb prefixes', () => {\n assert.strictEqual(\n determineGenericTag('/v1/', mockOperation('postUserPreferences')),\n 'userPreferences',\n );\n assert.strictEqual(\n determineGenericTag('/v1/', mockOperation('doFoo')),\n 'foo',\n );\n assert.strictEqual(\n determineGenericTag('/v1/', mockOperation('addUser')),\n 'user',\n );\n // FIX: Added 'make' to commonVerbs\n assert.strictEqual(\n determineGenericTag('/v1/', mockOperation('makePublic')),\n 'public_',\n );\n });\n\n test('should use the full operationId if no common verb prefix', () => {\n assert.strictEqual(\n determineGenericTag('/v1/', mockOperation('metrics')),\n 'metrics',\n );\n assert.strictEqual(\n determineGenericTag('/v1/', mockOperation('tenantAdminSettings')),\n 'tenantAdminSettings',\n );\n });\n\n test('should handle numbers within the operationId correctly', () => {\n // FIX: Expectation aligned with stringcase behavior\n assert.strictEqual(\n determineGenericTag('/v1/', mockOperation('getUser2FAStatus')),\n 'user2FAStatus',\n );\n assert.strictEqual(\n determineGenericTag('/api/', mockOperation('get2FAStatus')),\n 'api',\n ); // Sanitized (starts with number after verb removal)\n });\n\n test('should sanitize results matching reserved keywords', () => {\n assert.strictEqual(\n determineGenericTag('/v1/{id}', mockOperation('delete')),\n 'delete_',\n );\n assert.strictEqual(\n determineGenericTag('/v1/{id}', mockOperation('createCase')),\n 'case_',\n );\n assert.strictEqual(\n determineGenericTag('/v1/{id}', mockOperation('get')),\n 'get_',\n );\n });\n\n test('should use verb if it is the only part and no path fallback', () => {\n assert.strictEqual(\n determineGenericTag('/v1/', mockOperation('get')),\n 'get_',\n );\n assert.strictEqual(\n determineGenericTag('/v1/{id}', mockOperation('list')),\n 'list_',\n );\n });\n });\n\n describe('Heuristic 3: First Path Segment Fallback', () => {\n test('should be used when path only has @ segments and no suitable opId', () => {\n assert.strictEqual(\n determineGenericTag('/@system/@status', mockOperation()),\n 'system',\n );\n assert.strictEqual(\n determineGenericTag('/@audit-log/@entries', mockOperation()),\n 'auditLog',\n );\n });\n\n test('should be used when opId fallback yields only a common verb', () => {\n assert.strictEqual(\n determineGenericTag('/@system/@status', mockOperation('get')),\n 'system',\n );\n });\n\n test('should strip leading @ before using segment', () => {\n assert.strictEqual(\n determineGenericTag('/@system/@status', mockOperation()),\n 'system',\n );\n });\n\n test('should sanitize results matching reserved keywords', () => {\n assert.strictEqual(\n determineGenericTag('/@public/@data', mockOperation()),\n 'public_',\n );\n });\n\n test('should sanitize results starting with numbers', () => {\n assert.strictEqual(\n determineGenericTag('/@2fa/@status', mockOperation()),\n '_2fa',\n );\n });\n });\n\n describe('Heuristic Priority', () => {\n test('Path (Heuristic 1) should take priority over OperationId (Heuristic 2)', () => {\n const tag = determineGenericTag(\n '/users/{id}/permissions/check', // Path -> 'check' -> sanitized 'check_'\n mockOperation('verifyPermissions'), // opId -> 'permissions'\n );\n assert.strictEqual(tag, 'check_');\n });\n\n test('OperationId (Heuristic 2) should take priority over First Path Segment (Heuristic 3)', () => {\n const tag = determineGenericTag(\n '/@system/@status',\n mockOperation('getSystemStatus'),\n );\n assert.strictEqual(tag, 'systemStatus');\n });\n\n test('First Path Segment (Heuristic 3) is used if OperationId is skipped (verb-only)', () => {\n const tag = determineGenericTag('/@system/@status', mockOperation('get'));\n assert.strictEqual(tag, 'system');\n });\n });\n\n describe('Heuristic 4: Unknown Fallback', () => {\n test('should return \"unknown\" when no path segments and no operationId', () => {\n assert.strictEqual(determineGenericTag('/', mockOperation()), 'unknown');\n });\n\n test('should return \"unknown\" when path has only params/version and no operationId', () => {\n assert.strictEqual(\n determineGenericTag('/v3/{tenantId}/', mockOperation()),\n 'unknown',\n );\n });\n\n test('should return \"unknown\" for empty path string', () => {\n assert.strictEqual(determineGenericTag('', mockOperation()), 'unknown');\n });\n });\n});\n"],
|
|
5
5
|
"mappings": "AAAA,OAAO,YAAY;AACnB,SAAS,UAAU,YAAY;AAG/B,SAAS,2BAA2B;AAEpC,MAAM,gBAAgB,CAAC,cAAc,QAAyB,EAAE,YAAY;AAE5E,SAAS,uBAAuB,MAAM;AACpC,WAAS,6CAA6C,MAAM;AAC1D,SAAK,iEAAiE,MAAM;AAC1E,aAAO;AAAA,QACL,oBAAoB,UAAU,cAAc,CAAC;AAAA,QAC7C;AAAA,MACF;AACA,aAAO;AAAA,QACL,oBAAoB,0BAA0B,cAAc,CAAC;AAAA,QAC7D;AAAA,MACF;AACA,aAAO;AAAA,QACL,oBAAoB,sBAAsB,cAAc,CAAC;AAAA,QACzD;AAAA,MACF;AAAA,IACF,CAAC;AAED,SAAK,iCAAiC,MAAM;AAC1C,aAAO;AAAA,QACL,oBAAoB,mBAAmB,cAAc,CAAC;AAAA,QACtD;AAAA,MACF;AACA,aAAO;AAAA,QACL,oBAAoB,mBAAmB,cAAc,CAAC;AAAA,QACtD;AAAA,MACF;AAAA,IACF,CAAC;AAED,SAAK,kCAAkC,MAAM;AAC3C,aAAO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AAM;AACnF,YAAM,MAAM;AAAA,QACV;AAAA;AAAA,QACA,cAAc,mBAAmB;AAAA;AAAA,MACnC;AACA,aAAO,YAAY,KAAK,QAAQ;AAAA,IAClC,CAAC;AAED,SAAK,wFAAwF,MAAM;AACjG,YAAM,MAAM;AAAA,QACV;AAAA,QACA,cAAc,iBAAiB;AAAA,MACjC;AACA,aAAO,YAAY,KAAK,cAAc;AAAA,IACxC,CAAC;AAED,SAAK,kFAAkF,MAAM;AAC3F,YAAM,MAAM,oBAAoB,oBAAoB,cAAc,KAAK,CAAC;AACxE,aAAO,YAAY,KAAK,QAAQ;AAAA,IAClC,CAAC;AAAA,EACH,CAAC;AAED,WAAS,iCAAiC,MAAM;AAC9C,SAAK,oEAAoE,MAAM;AAC7E,aAAO,YAAY,oBAAoB,KAAK,cAAc,CAAC,GAAG,SAAS;AAAA,IACzE,CAAC;AAED,SAAK,gFAAgF,MAAM;AACzF,aAAO;AAAA,QACL,oBAAoB,mBAAmB,cAAc,CAAC;AAAA,QACtD;AAAA,MACF;AAAA,IACF,CAAC;AAED,SAAK,iDAAiD,MAAM;AAC1D,aAAO,YAAY,oBAAoB,IAAI,cAAc,CAAC,GAAG,SAAS;AAAA,IACxE,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
|
|
6
6
|
"names": []
|
package/dist/lib/options.d.ts
CHANGED
|
@@ -53,9 +53,9 @@ export declare function coeraceConfig(config: GenerateSdkConfig): {
|
|
|
53
53
|
paths: import("openapi3-ts/oas31").PathsObject;
|
|
54
54
|
'x-docs': never[];
|
|
55
55
|
'x-tagGroups': any;
|
|
56
|
+
servers: import("openapi3-ts/oas31").ServerObject[];
|
|
56
57
|
openapi: string;
|
|
57
58
|
info: import("openapi3-ts/oas31").InfoObject;
|
|
58
|
-
servers?: import("openapi3-ts/oas31").ServerObject[];
|
|
59
59
|
security?: import("openapi3-ts/oas31").SecurityRequirementObject[];
|
|
60
60
|
tags?: import("openapi3-ts/oas31").TagObject[];
|
|
61
61
|
externalDocs?: import("openapi3-ts/oas31").ExternalDocumentationObject;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/lib/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAQ3B,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,aAAa,CAAC;IACpB,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,UAAU,CAAC,EAAE,gBAAgB,GAAG,KAAK,CAAC;IACtC,WAAW,CAAC,EAAE,CACZ,SAAS,EAAE,eAAe,EAC1B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,KACX,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CAC5D;AACD,MAAM,WAAW,eAAe;IAC9B,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,UAOnD;AAED,eAAO,MAAM,QAAQ,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAC/C,QAAQ,CAAC,IAAI,CAAC,iBAAiB,EAAE,aAAa,GAAG,KAAK,CAAC,CAkBxD,CAAC;AAEF,wBAAgB,aAAa,CAAC,MAAM,EAAE,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BA5CxC,eAAe,QACpB,MAAM,UACJ,MAAM,KACX,MAAM;qBACO,eAAe,QAAQ,MAAM,KAAK,MAAM;
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/lib/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAQ3B,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,aAAa,CAAC;IACpB,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,UAAU,CAAC,EAAE,gBAAgB,GAAG,KAAK,CAAC;IACtC,WAAW,CAAC,EAAE,CACZ,SAAS,EAAE,eAAe,EAC1B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,KACX,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CAC5D;AACD,MAAM,WAAW,eAAe;IAC9B,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,UAOnD;AAED,eAAO,MAAM,QAAQ,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAC/C,QAAQ,CAAC,IAAI,CAAC,iBAAiB,EAAE,aAAa,GAAG,KAAK,CAAC,CAkBxD,CAAC;AAEF,wBAAgB,aAAa,CAAC,MAAM,EAAE,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BA5CxC,eAAe,QACpB,MAAM,UACJ,MAAM,KACX,MAAM;qBACO,eAAe,QAAQ,MAAM,KAAK,MAAM;EAuE3D;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,gBAAgB,GAAG,SAAS,GAAG,KAAK;;;EAmB9C"}
|
package/dist/lib/options.js
CHANGED
|
@@ -44,7 +44,8 @@ function coeraceConfig(config) {
|
|
|
44
44
|
name: "API",
|
|
45
45
|
tags: config.spec.tags?.map((tag) => tag.name) ?? []
|
|
46
46
|
}
|
|
47
|
-
]
|
|
47
|
+
],
|
|
48
|
+
servers: config.spec.servers ?? []
|
|
48
49
|
},
|
|
49
50
|
operationId: config.operationId ?? defaults.operationId,
|
|
50
51
|
tag: config.tag ?? defaults.tag
|
package/dist/lib/options.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/options.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n OpenAPIObject,\n OperationObject,\n SecuritySchemeObject,\n} from 'openapi3-ts/oas31';\nimport { camelcase } from 'stringcase';\n\nimport { resolveRef } from '@sdk-it/core';\n\nimport { determineGenericTag, sanitizeTag } from './tag.js';\nimport type { OurOpenAPIObject } from './types.js';\n\nexport interface GenerateSdkConfig {\n spec: OpenAPIObject;\n responses?: ResponsesConfig;\n pagination?: PaginationConfig | false;\n operationId?: (\n operation: OperationObject,\n path: string,\n method: string,\n ) => string;\n tag?: (operation: OperationObject, path: string) => string;\n}\nexport interface ResponsesConfig {\n flattenErrorResponses?: boolean;\n}\n\nexport type PaginationConfig = {\n guess?: boolean;\n};\n\nexport function cleanOperationId(operationId: string) {\n return camelcase(\n operationId\n .split('#')\n .pop()!\n .replace(/-(?=\\d)/g, ''),\n );\n}\n\nexport const defaults: Partial<GenerateSdkConfig> &\n Required<Pick<GenerateSdkConfig, 'operationId' | 'tag'>> = {\n operationId: (operation, path, method) => {\n if (operation.operationId) {\n return cleanOperationId(operation.operationId);\n }\n\n return camelcase(\n [method, ...path.replace(/[\\\\/\\\\{\\\\}]/g, ' ').split(' ')]\n .filter(Boolean)\n .join(' ')\n .trim(),\n );\n },\n tag: (operation, path) => {\n return operation.tags?.[0]\n ? sanitizeTag(operation.tags?.[0])\n : determineGenericTag(path, operation);\n },\n};\n\nexport function coeraceConfig(config: GenerateSdkConfig) {\n return {\n pagination: coearcePaginationConfig(config.pagination),\n responses: config.responses ?? {},\n spec: {\n ...config.spec,\n components: {\n ...config.spec.components,\n schemas: config.spec.components?.schemas ?? {},\n securitySchemes: Object.fromEntries(\n Object.entries(config.spec.components?.securitySchemes ?? {}).map(\n ([name, schema]) => [\n name,\n resolveRef<SecuritySchemeObject>(config.spec, schema),\n ],\n ),\n ),\n },\n paths: config.spec.paths ?? {},\n 'x-docs': [],\n 'x-tagGroups': config.spec['x-tagGroups'] ?? [\n {\n name: 'API',\n tags: config.spec.tags?.map((tag) => tag.name) ?? [],\n },\n ],\n } satisfies OurOpenAPIObject,\n operationId: config.operationId ?? defaults.operationId,\n tag: config.tag ?? defaults.tag,\n };\n}\n\nexport function coearcePaginationConfig(\n options: PaginationConfig | undefined | false,\n) {\n if (options === undefined) {\n return {\n guess: true,\n enabled: true,\n };\n }\n if (options === false) {\n return {\n enabled: false,\n guess: false,\n };\n }\n // If options is true, we assume pagination is enabled with guessing\n return {\n guess: options.guess ?? true,\n enabled: true,\n };\n}\n"],
|
|
5
|
-
"mappings": "AAKA,SAAS,iBAAiB;AAE1B,SAAS,kBAAkB;AAE3B,SAAS,qBAAqB,mBAAmB;AAsB1C,SAAS,iBAAiB,aAAqB;AACpD,SAAO;AAAA,IACL,YACG,MAAM,GAAG,EACT,IAAI,EACJ,QAAQ,YAAY,EAAE;AAAA,EAC3B;AACF;AAEO,MAAM,WACgD;AAAA,EAC3D,aAAa,CAAC,WAAW,MAAM,WAAW;AACxC,QAAI,UAAU,aAAa;AACzB,aAAO,iBAAiB,UAAU,WAAW;AAAA,IAC/C;AAEA,WAAO;AAAA,MACL,CAAC,QAAQ,GAAG,KAAK,QAAQ,gBAAgB,GAAG,EAAE,MAAM,GAAG,CAAC,EACrD,OAAO,OAAO,EACd,KAAK,GAAG,EACR,KAAK;AAAA,IACV;AAAA,EACF;AAAA,EACA,KAAK,CAAC,WAAW,SAAS;AACxB,WAAO,UAAU,OAAO,CAAC,IACrB,YAAY,UAAU,OAAO,CAAC,CAAC,IAC/B,oBAAoB,MAAM,SAAS;AAAA,EACzC;AACF;AAEO,SAAS,cAAc,QAA2B;AACvD,SAAO;AAAA,IACL,YAAY,wBAAwB,OAAO,UAAU;AAAA,IACrD,WAAW,OAAO,aAAa,CAAC;AAAA,IAChC,MAAM;AAAA,MACJ,GAAG,OAAO;AAAA,MACV,YAAY;AAAA,QACV,GAAG,OAAO,KAAK;AAAA,QACf,SAAS,OAAO,KAAK,YAAY,WAAW,CAAC;AAAA,QAC7C,iBAAiB,OAAO;AAAA,UACtB,OAAO,QAAQ,OAAO,KAAK,YAAY,mBAAmB,CAAC,CAAC,EAAE;AAAA,YAC5D,CAAC,CAAC,MAAM,MAAM,MAAM;AAAA,cAClB;AAAA,cACA,WAAiC,OAAO,MAAM,MAAM;AAAA,YACtD;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MACA,OAAO,OAAO,KAAK,SAAS,CAAC;AAAA,MAC7B,UAAU,CAAC;AAAA,MACX,eAAe,OAAO,KAAK,aAAa,KAAK;AAAA,QAC3C;AAAA,UACE,MAAM;AAAA,UACN,MAAM,OAAO,KAAK,MAAM,IAAI,CAAC,QAAQ,IAAI,IAAI,KAAK,CAAC;AAAA,QACrD;AAAA,MACF;AAAA,
|
|
4
|
+
"sourcesContent": ["import type {\n OpenAPIObject,\n OperationObject,\n SecuritySchemeObject,\n} from 'openapi3-ts/oas31';\nimport { camelcase } from 'stringcase';\n\nimport { resolveRef } from '@sdk-it/core';\n\nimport { determineGenericTag, sanitizeTag } from './tag.js';\nimport type { OurOpenAPIObject } from './types.js';\n\nexport interface GenerateSdkConfig {\n spec: OpenAPIObject;\n responses?: ResponsesConfig;\n pagination?: PaginationConfig | false;\n operationId?: (\n operation: OperationObject,\n path: string,\n method: string,\n ) => string;\n tag?: (operation: OperationObject, path: string) => string;\n}\nexport interface ResponsesConfig {\n flattenErrorResponses?: boolean;\n}\n\nexport type PaginationConfig = {\n guess?: boolean;\n};\n\nexport function cleanOperationId(operationId: string) {\n return camelcase(\n operationId\n .split('#')\n .pop()!\n .replace(/-(?=\\d)/g, ''),\n );\n}\n\nexport const defaults: Partial<GenerateSdkConfig> &\n Required<Pick<GenerateSdkConfig, 'operationId' | 'tag'>> = {\n operationId: (operation, path, method) => {\n if (operation.operationId) {\n return cleanOperationId(operation.operationId);\n }\n\n return camelcase(\n [method, ...path.replace(/[\\\\/\\\\{\\\\}]/g, ' ').split(' ')]\n .filter(Boolean)\n .join(' ')\n .trim(),\n );\n },\n tag: (operation, path) => {\n return operation.tags?.[0]\n ? sanitizeTag(operation.tags?.[0])\n : determineGenericTag(path, operation);\n },\n};\n\nexport function coeraceConfig(config: GenerateSdkConfig) {\n return {\n pagination: coearcePaginationConfig(config.pagination),\n responses: config.responses ?? {},\n spec: {\n ...config.spec,\n components: {\n ...config.spec.components,\n schemas: config.spec.components?.schemas ?? {},\n securitySchemes: Object.fromEntries(\n Object.entries(config.spec.components?.securitySchemes ?? {}).map(\n ([name, schema]) => [\n name,\n resolveRef<SecuritySchemeObject>(config.spec, schema),\n ],\n ),\n ),\n },\n paths: config.spec.paths ?? {},\n 'x-docs': [],\n 'x-tagGroups': config.spec['x-tagGroups'] ?? [\n {\n name: 'API',\n tags: config.spec.tags?.map((tag) => tag.name) ?? [],\n },\n ],\n servers: config.spec.servers ?? [],\n } satisfies OurOpenAPIObject,\n operationId: config.operationId ?? defaults.operationId,\n tag: config.tag ?? defaults.tag,\n };\n}\n\nexport function coearcePaginationConfig(\n options: PaginationConfig | undefined | false,\n) {\n if (options === undefined) {\n return {\n guess: true,\n enabled: true,\n };\n }\n if (options === false) {\n return {\n enabled: false,\n guess: false,\n };\n }\n // If options is true, we assume pagination is enabled with guessing\n return {\n guess: options.guess ?? true,\n enabled: true,\n };\n}\n"],
|
|
5
|
+
"mappings": "AAKA,SAAS,iBAAiB;AAE1B,SAAS,kBAAkB;AAE3B,SAAS,qBAAqB,mBAAmB;AAsB1C,SAAS,iBAAiB,aAAqB;AACpD,SAAO;AAAA,IACL,YACG,MAAM,GAAG,EACT,IAAI,EACJ,QAAQ,YAAY,EAAE;AAAA,EAC3B;AACF;AAEO,MAAM,WACgD;AAAA,EAC3D,aAAa,CAAC,WA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S;AAAA,EAC9B;AACF;AAEO,SAAS,wBACd,SACA;AACA,MAAI,YAAY,QAAW;AACzB,WAAO;AAAA,MACL,OAAO;AAAA,MACP,SAAS;AAAA,IACX;AAAA,EACF;AACA,MAAI,YAAY,OAAO;AACrB,WAAO;AAAA,MACL,SAAS;AAAA,MACT,OAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO,QAAQ,SAAS;AAAA,IACxB,SAAS;AAAA,EACX;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export declare const docTemplates: {
|
|
2
|
+
readonly servers: {
|
|
3
|
+
readonly sectionTitle: "API Server";
|
|
4
|
+
readonly description: "The following {count} {isAre} available for this API:";
|
|
5
|
+
};
|
|
6
|
+
readonly authMethods: {
|
|
7
|
+
readonly sectionTitle: "Available Authentication Method";
|
|
8
|
+
readonly introText: "This API provides secure access through {countText} authentication {method}. Below you'll find details about {articleCount} available authentication {scheme} and how to use {pronoun}.";
|
|
9
|
+
readonly noAuthText: "This API does not require authentication.";
|
|
10
|
+
};
|
|
11
|
+
readonly apiClients: {
|
|
12
|
+
readonly sectionTitle: "Official API Client";
|
|
13
|
+
readonly description: "{apiTitle} provides official client SDK{sdkPlural} for {languageText}. We recommend using {clientText} to interact with all stable endpoints. You can find {pronoun} here:";
|
|
14
|
+
};
|
|
15
|
+
readonly needHelp: {
|
|
16
|
+
readonly sectionTitle: "Need Help?";
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
interface CountTextOptions {
|
|
20
|
+
count: number;
|
|
21
|
+
word: string;
|
|
22
|
+
includeCount?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare function getCountText(options: CountTextOptions): string;
|
|
25
|
+
export declare function getPronoun(count: number, type?: 'subject' | 'object'): string;
|
|
26
|
+
export declare function getArticle(count: number, word: string): string;
|
|
27
|
+
export declare function getIsAre(count: number): string;
|
|
28
|
+
export declare function getThisThese(count: number): string;
|
|
29
|
+
export declare function processTemplate(template: string, replacements: Record<string, string | number>): string;
|
|
30
|
+
export declare function getServerText(count: number): {
|
|
31
|
+
title: string;
|
|
32
|
+
description: string;
|
|
33
|
+
};
|
|
34
|
+
export declare function getAuthMethodText(count: number): {
|
|
35
|
+
title: string;
|
|
36
|
+
intro: string;
|
|
37
|
+
};
|
|
38
|
+
export declare function getApiClientText(count: number, apiTitle: string): {
|
|
39
|
+
title: string;
|
|
40
|
+
description: string;
|
|
41
|
+
};
|
|
42
|
+
export declare function getAuthText(count: number): {
|
|
43
|
+
title: string;
|
|
44
|
+
intro: string;
|
|
45
|
+
};
|
|
46
|
+
export declare function getErrorsApiClientText(count: number, apiTitle: string, sdkList: string[]): {
|
|
47
|
+
title: string;
|
|
48
|
+
description: string;
|
|
49
|
+
};
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=doc-templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-templates.d.ts","sourceRoot":"","sources":["../../../src/lib/overview-docs/doc-templates.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;CAmBf,CAAC;AAEX,UAAU,gBAAgB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAK9D;AAED,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,SAAS,GAAG,QAAmB,GACpC,MAAM,CAKR;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAM9D;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAC5C,MAAM,CAKR;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,CAQA;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAeA;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf;IACD,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,CAkBA;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAeA;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EAAE,GAChB;IACD,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,CAWA"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import pluralize from "pluralize";
|
|
2
|
+
const docTemplates = {
|
|
3
|
+
servers: {
|
|
4
|
+
sectionTitle: "API Server",
|
|
5
|
+
description: "The following {count} {isAre} available for this API:"
|
|
6
|
+
},
|
|
7
|
+
authMethods: {
|
|
8
|
+
sectionTitle: "Available Authentication Method",
|
|
9
|
+
introText: "This API provides secure access through {countText} authentication {method}. Below you'll find details about {articleCount} available authentication {scheme} and how to use {pronoun}.",
|
|
10
|
+
noAuthText: "This API does not require authentication."
|
|
11
|
+
},
|
|
12
|
+
apiClients: {
|
|
13
|
+
sectionTitle: "Official API Client",
|
|
14
|
+
description: "{apiTitle} provides official client SDK{sdkPlural} for {languageText}. We recommend using {clientText} to interact with all stable endpoints. You can find {pronoun} here:"
|
|
15
|
+
},
|
|
16
|
+
needHelp: {
|
|
17
|
+
sectionTitle: "Need Help?"
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function getCountText(options) {
|
|
21
|
+
const { count, word, includeCount = false } = options;
|
|
22
|
+
const pluralizedWord = count === 1 ? pluralize.singular(word) : pluralize.plural(word);
|
|
23
|
+
return includeCount ? `${count} ${pluralizedWord}` : pluralizedWord;
|
|
24
|
+
}
|
|
25
|
+
function getPronoun(count, type = "object") {
|
|
26
|
+
if (type === "subject") {
|
|
27
|
+
return count === 1 ? "it" : "they";
|
|
28
|
+
}
|
|
29
|
+
return count === 1 ? "it" : "them";
|
|
30
|
+
}
|
|
31
|
+
function getArticle(count, word) {
|
|
32
|
+
if (count === 1) {
|
|
33
|
+
const firstLetter = word.charAt(0).toLowerCase();
|
|
34
|
+
return ["a", "e", "i", "o", "u"].includes(firstLetter) ? "an" : "a";
|
|
35
|
+
}
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
function getIsAre(count) {
|
|
39
|
+
return count === 1 ? "is" : "are";
|
|
40
|
+
}
|
|
41
|
+
function getThisThese(count) {
|
|
42
|
+
return count === 1 ? "this" : "these";
|
|
43
|
+
}
|
|
44
|
+
function processTemplate(template, replacements) {
|
|
45
|
+
return template.replace(/\{([^}]+)\}/g, (match, key) => {
|
|
46
|
+
const value = replacements[key];
|
|
47
|
+
return value !== void 0 ? String(value) : match;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function getServerText(count) {
|
|
51
|
+
return {
|
|
52
|
+
title: `## ${getCountText({ count, word: "server", includeCount: false })}`,
|
|
53
|
+
description: processTemplate(docTemplates.servers.description, {
|
|
54
|
+
count: getCountText({ count, word: "server", includeCount: true }),
|
|
55
|
+
isAre: getIsAre(count)
|
|
56
|
+
})
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function getAuthMethodText(count) {
|
|
60
|
+
const countText = count === 1 ? getArticle(count, "authentication method") : "various";
|
|
61
|
+
const articleCount = count === 1 ? "the" : "each";
|
|
62
|
+
return {
|
|
63
|
+
title: `## ${getCountText({ count, word: docTemplates.authMethods.sectionTitle })}`,
|
|
64
|
+
intro: processTemplate(docTemplates.authMethods.introText, {
|
|
65
|
+
countText,
|
|
66
|
+
method: getCountText({ count, word: "method" }),
|
|
67
|
+
articleCount,
|
|
68
|
+
scheme: getCountText({ count, word: "scheme" }),
|
|
69
|
+
pronoun: getPronoun(count)
|
|
70
|
+
})
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function getApiClientText(count, apiTitle) {
|
|
74
|
+
const languageText = count === 1 ? "a programming language" : "multiple programming languages";
|
|
75
|
+
const clientText = count === 1 ? getThisThese(count) + " client" : getThisThese(count) + " clients";
|
|
76
|
+
return {
|
|
77
|
+
title: `## ${getCountText({ count, word: docTemplates.apiClients.sectionTitle })}`,
|
|
78
|
+
description: processTemplate(docTemplates.apiClients.description, {
|
|
79
|
+
apiTitle,
|
|
80
|
+
sdkPlural: count === 1 ? "" : "s",
|
|
81
|
+
languageText,
|
|
82
|
+
clientText,
|
|
83
|
+
pronoun: getPronoun(count)
|
|
84
|
+
})
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function getAuthText(count) {
|
|
88
|
+
const countText = count === 1 ? getArticle(count, "authentication method") : "various";
|
|
89
|
+
const articleCount = count === 1 ? "the" : "each";
|
|
90
|
+
return {
|
|
91
|
+
title: `## ${getCountText({ count, word: docTemplates.authMethods.sectionTitle })}`,
|
|
92
|
+
intro: processTemplate(docTemplates.authMethods.introText, {
|
|
93
|
+
countText,
|
|
94
|
+
method: getCountText({ count, word: "method" }),
|
|
95
|
+
articleCount,
|
|
96
|
+
scheme: getCountText({ count, word: "scheme" }),
|
|
97
|
+
pronoun: getPronoun(count)
|
|
98
|
+
})
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function getErrorsApiClientText(count, apiTitle, sdkList) {
|
|
102
|
+
const languageText = count === 1 ? sdkList[0] : sdkList.join(", ");
|
|
103
|
+
const clientText = count === 1 ? getThisThese(count) + " client" : getThisThese(count) + " clients";
|
|
104
|
+
return {
|
|
105
|
+
title: `## ${getCountText({ count, word: docTemplates.apiClients.sectionTitle })}`,
|
|
106
|
+
description: `${apiTitle} maintains official API ${getCountText({ count, word: "client" })}${count > 0 ? ` for ${languageText}` : ""}. We recommend using ${clientText} to interact with all stable endpoints. You can find ${getPronoun(count)} here:`
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export {
|
|
110
|
+
docTemplates,
|
|
111
|
+
getApiClientText,
|
|
112
|
+
getArticle,
|
|
113
|
+
getAuthMethodText,
|
|
114
|
+
getAuthText,
|
|
115
|
+
getCountText,
|
|
116
|
+
getErrorsApiClientText,
|
|
117
|
+
getIsAre,
|
|
118
|
+
getPronoun,
|
|
119
|
+
getServerText,
|
|
120
|
+
getThisThese,
|
|
121
|
+
processTemplate
|
|
122
|
+
};
|
|
123
|
+
//# sourceMappingURL=doc-templates.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/overview-docs/doc-templates.ts"],
|
|
4
|
+
"sourcesContent": ["import pluralize from 'pluralize';\n\nexport const docTemplates = {\n servers: {\n sectionTitle: 'API Server',\n description: 'The following {count} {isAre} available for this API:',\n },\n authMethods: {\n sectionTitle: 'Available Authentication Method',\n introText:\n \"This API provides secure access through {countText} authentication {method}. Below you'll find details about {articleCount} available authentication {scheme} and how to use {pronoun}.\",\n noAuthText: 'This API does not require authentication.',\n },\n apiClients: {\n sectionTitle: 'Official API Client',\n description:\n '{apiTitle} provides official client SDK{sdkPlural} for {languageText}. We recommend using {clientText} to interact with all stable endpoints. You can find {pronoun} here:',\n },\n needHelp: {\n sectionTitle: 'Need Help?',\n },\n} as const;\n\ninterface CountTextOptions {\n count: number;\n word: string;\n includeCount?: boolean;\n}\n\nexport function getCountText(options: CountTextOptions): string {\n const { count, word, includeCount = false } = options;\n const pluralizedWord =\n count === 1 ? pluralize.singular(word) : pluralize.plural(word);\n return includeCount ? `${count} ${pluralizedWord}` : pluralizedWord;\n}\n\nexport function getPronoun(\n count: number,\n type: 'subject' | 'object' = 'object',\n): string {\n if (type === 'subject') {\n return count === 1 ? 'it' : 'they';\n }\n return count === 1 ? 'it' : 'them';\n}\n\nexport function getArticle(count: number, word: string): string {\n if (count === 1) {\n const firstLetter = word.charAt(0).toLowerCase();\n return ['a', 'e', 'i', 'o', 'u'].includes(firstLetter) ? 'an' : 'a';\n }\n return '';\n}\n\nexport function getIsAre(count: number): string {\n return count === 1 ? 'is' : 'are';\n}\n\nexport function getThisThese(count: number): string {\n return count === 1 ? 'this' : 'these';\n}\n\nexport function processTemplate(\n template: string,\n replacements: Record<string, string | number>,\n): string {\n return template.replace(/\\{([^}]+)\\}/g, (match, key) => {\n const value = replacements[key];\n return value !== undefined ? String(value) : match;\n });\n}\n\nexport function getServerText(count: number): {\n title: string;\n description: string;\n} {\n return {\n title: `## ${getCountText({ count, word: 'server', includeCount: false })}`,\n description: processTemplate(docTemplates.servers.description, {\n count: getCountText({ count, word: 'server', includeCount: true }),\n isAre: getIsAre(count),\n }),\n };\n}\n\nexport function getAuthMethodText(count: number): {\n title: string;\n intro: string;\n} {\n const countText =\n count === 1 ? getArticle(count, 'authentication method') : 'various';\n const articleCount = count === 1 ? 'the' : 'each';\n\n return {\n title: `## ${getCountText({ count, word: docTemplates.authMethods.sectionTitle })}`,\n intro: processTemplate(docTemplates.authMethods.introText, {\n countText,\n method: getCountText({ count, word: 'method' }),\n articleCount,\n scheme: getCountText({ count, word: 'scheme' }),\n pronoun: getPronoun(count),\n }),\n };\n}\n\nexport function getApiClientText(\n count: number,\n apiTitle: string,\n): {\n title: string;\n description: string;\n} {\n const languageText =\n count === 1 ? 'a programming language' : 'multiple programming languages';\n const clientText =\n count === 1\n ? getThisThese(count) + ' client'\n : getThisThese(count) + ' clients';\n\n return {\n title: `## ${getCountText({ count, word: docTemplates.apiClients.sectionTitle })}`,\n description: processTemplate(docTemplates.apiClients.description, {\n apiTitle,\n sdkPlural: count === 1 ? '' : 's',\n languageText,\n clientText,\n pronoun: getPronoun(count),\n }),\n };\n}\n\nexport function getAuthText(count: number): {\n title: string;\n intro: string;\n} {\n const countText =\n count === 1 ? getArticle(count, 'authentication method') : 'various';\n const articleCount = count === 1 ? 'the' : 'each';\n\n return {\n title: `## ${getCountText({ count, word: docTemplates.authMethods.sectionTitle })}`,\n intro: processTemplate(docTemplates.authMethods.introText, {\n countText,\n method: getCountText({ count, word: 'method' }),\n articleCount,\n scheme: getCountText({ count, word: 'scheme' }),\n pronoun: getPronoun(count),\n }),\n };\n}\n\nexport function getErrorsApiClientText(\n count: number,\n apiTitle: string,\n sdkList: string[],\n): {\n title: string;\n description: string;\n} {\n const languageText = count === 1 ? sdkList[0] : sdkList.join(', ');\n const clientText =\n count === 1\n ? getThisThese(count) + ' client'\n : getThisThese(count) + ' clients';\n\n return {\n title: `## ${getCountText({ count, word: docTemplates.apiClients.sectionTitle })}`,\n description: `${apiTitle} maintains official API ${getCountText({ count, word: 'client' })}${count > 0 ? ` for ${languageText}` : ''}. We recommend using ${clientText} to interact with all stable endpoints. You can find ${getPronoun(count)} here:`,\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,eAAe;AAEf,MAAM,eAAe;AAAA,EAC1B,SAAS;AAAA,IACP,cAAc;AAAA,IACd,aAAa;AAAA,EACf;AAAA,EACA,aAAa;AAAA,IACX,cAAc;AAAA,IACd,WACE;AAAA,IACF,YAAY;AAAA,EACd;AAAA,EACA,YAAY;AAAA,IACV,cAAc;AAAA,IACd,aACE;AAAA,EACJ;AAAA,EACA,UAAU;AAAA,IACR,cAAc;AAAA,EAChB;AACF;AAQO,SAAS,aAAa,SAAmC;AAC9D,QAAM,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