diff --git a/cli/constants.js b/cli/constants.js index 02b90d01..89e88623 100644 --- a/cli/constants.js +++ b/cli/constants.js @@ -3,8 +3,4 @@ const skip_command = Symbol("skip"); const reservedOptions = ["version", "help"]; -module.exports = { - root_command, - skip_command, - reservedOptions, -}; +export { root_command, skip_command, reservedOptions }; diff --git a/cli/execute.js b/cli/execute.js index ee403844..e0bed487 100644 --- a/cli/execute.js +++ b/cli/execute.js @@ -1,7 +1,7 @@ -const _ = require("lodash"); -const { root_command, skip_command } = require("./constants"); -const { parseArgs } = require("./parse-args"); -const didYouMean = require("didyoumean"); +import didYouMean from "didyoumean"; +import _ from "lodash"; +import { root_command, skip_command } from "./constants.js"; +import { parseArgs } from "./parse-args.js"; didYouMean.threshold = 0.5; @@ -177,6 +177,4 @@ const processArgs = (commands, args) => { }; }; -module.exports = { - execute, -}; +export { execute }; diff --git a/cli/index.d.ts b/cli/index.d.ts index 32e60d0a..d4fc8727 100644 --- a/cli/index.d.ts +++ b/cli/index.d.ts @@ -1,18 +1,19 @@ type CliStructOption = { - flags?: string; - description?: string; default?: unknown; + description?: string; + flags?: string; internal?: { name?: string; formatter?: (value: any) => any }; + required?: boolean; }; type CliStruct = { - inherited?: string | null; - name?: string; alias?: string; - version?: string; + commands?: CliStruct[]; description?: string; + inherited?: string | null; + name?: string; options: CliStructOption[]; - commands?: CliStruct[]; + version?: string; }; type ExecuteOptions = { diff --git a/cli/index.js b/cli/index.js index 13e85d19..a5b818a5 100644 --- a/cli/index.js +++ b/cli/index.js @@ -1,9 +1,9 @@ -const _ = require("lodash"); -const { reservedOptions, root_command } = require("./constants"); -const { processOption } = require("./process-option"); -const { execute } = require("./execute"); -const { displayHelp } = require("./operations/display-help"); -const { displayVersion } = require("./operations/display-version"); +import _ from "lodash"; +import { reservedOptions, root_command } from "./constants.js"; +import { execute } from "./execute.js"; +import { displayHelp } from "./operations/display-help.js"; +import { displayVersion } from "./operations/display-version.js"; +import { processOption } from "./process-option.js"; const cli = (input) => { const commands = {}; @@ -91,6 +91,4 @@ const cli = (input) => { return instance; }; -module.exports = { - cli, -}; +export { cli }; diff --git a/cli/operations/display-help.js b/cli/operations/display-help.js index 149209ea..f9d8beb2 100644 --- a/cli/operations/display-help.js +++ b/cli/operations/display-help.js @@ -1,5 +1,5 @@ -const _ = require("lodash"); -const { root_command } = require("../constants"); +import _ from "lodash"; +import { root_command } from "../constants.js"; const generateOptionsOutput = (options) => options.reduce( @@ -174,6 +174,4 @@ ${command.description}` ${outputTest}`); }; -module.exports = { - displayHelp, -}; +export { displayHelp }; diff --git a/cli/operations/display-version.js b/cli/operations/display-version.js index 6e928acd..2a793e36 100644 --- a/cli/operations/display-version.js +++ b/cli/operations/display-version.js @@ -2,4 +2,4 @@ const displayVersion = (instance) => { console.log(instance.input.version); }; -module.exports = { displayVersion }; +export { displayVersion }; diff --git a/cli/parse-args.js b/cli/parse-args.js index b99f14fc..405a6090 100644 --- a/cli/parse-args.js +++ b/cli/parse-args.js @@ -21,6 +21,4 @@ const parseArgs = (args, type) => { } }; -module.exports = { - parseArgs, -}; +export { parseArgs }; diff --git a/cli/process-option.js b/cli/process-option.js index 750ee67f..ab8a1de1 100644 --- a/cli/process-option.js +++ b/cli/process-option.js @@ -1,4 +1,4 @@ -const _ = require("lodash"); +import _ from "lodash"; const optionFormatters = { number: (str) => +str, @@ -72,6 +72,4 @@ const processOption = (option) => { }; }; -module.exports = { - processOption, -}; +export { processOption }; diff --git a/index.js b/index.js index 90a27324..0be9904e 100755 --- a/index.js +++ b/index.js @@ -1,28 +1,23 @@ #!/usr/bin/env node -// Copyright (c) 2019-present acacode -// Node module: swagger-typescript-api -// This file is licensed under the MIT License. -// License text available at https://opensource.org/licenses/MIT -// Repository https://github.com/acacode/swagger-typescript-api +import { createRequire } from "node:module"; +import { resolve } from "node:path"; +import { cli } from "./cli/index.js"; +import { TemplatesGenConfig } from "./src/commands/generate-templates/configuration.js"; +import { CodeGenConfig } from "./src/configuration.js"; +import { HTTP_CLIENT } from "./src/constants.js"; +import { generateApi, generateTemplates } from "./src/index.js"; -const { version, name } = require("./package.json"); -const { cli } = require("./cli"); -const { generateApi, generateTemplates } = require("./src"); -const { HTTP_CLIENT } = require("./src/constants"); -const { resolve } = require("node:path"); -const { CodeGenConfig } = require("./src/configuration"); -const { - TemplatesGenConfig, -} = require("./src/commands/generate-templates/configuration"); +const require = createRequire(import.meta.url); +const packageJson = require("./package.json"); const codeGenBaseConfig = new CodeGenConfig({}); const templateGenBaseConfig = new TemplatesGenConfig({}); const program = cli({ - name: name, + name: packageJson.name, alias: "sta", - version: version, + version: packageJson.version, description: "Generate api via swagger scheme.\nSupports OA 3.0, 2.0, JSON, yaml.", options: [ diff --git a/package.json b/package.json index cc782d87..df02a2b1 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "contributors": [ "Sora Morimoto " ], + "type": "module", "main": "./src/index.js", "types": "./index.d.ts", "bin": { @@ -50,6 +51,8 @@ }, "devDependencies": { "@biomejs/biome": "1.8.2", + "@tsconfig/node18": "18.2.4", + "@tsconfig/strictest": "2.0.5", "@types/didyoumean": "1.2.2", "@types/js-yaml": "4.0.9", "@types/lodash": "4.17.5", diff --git a/src/code-formatter.js b/src/code-formatter.js index af585e46..619f8493 100644 --- a/src/code-formatter.js +++ b/src/code-formatter.js @@ -1,6 +1,6 @@ -const _ = require("lodash"); -const ts = require("typescript"); -const prettier = require("prettier"); +import _ from "lodash"; +import prettier from "prettier"; +import ts from "typescript"; class CodeFormatter { /** @@ -111,6 +111,4 @@ class TsLanguageServiceHost { } } -module.exports = { - CodeFormatter, -}; +export { CodeFormatter }; diff --git a/src/code-gen-process.js b/src/code-gen-process.js index 1256c25d..712fe256 100644 --- a/src/code-gen-process.js +++ b/src/code-gen-process.js @@ -1,21 +1,21 @@ -const { SwaggerSchemaResolver } = require("./swagger-schema-resolver.js"); -const { SchemaComponentsMap } = require("./schema-components-map.js"); -const { NameResolver } = require("./util/name-resolver"); -const { Logger } = require("./util/logger.js"); -const { TypeNameFormatter } = require("./type-name-formatter.js"); -const _ = require("lodash"); -const { SchemaParserFabric } = require("./schema-parser/schema-parser-fabric"); -const { SchemaRoutes } = require("./schema-routes/schema-routes.js"); -const { CodeGenConfig } = require("./configuration.js"); -const { SchemaWalker } = require("./schema-walker"); -const { FileSystem } = require("./util/file-system"); -const { TemplatesWorker } = require("./templates-worker"); -const { JavascriptTranslator } = require("./translators/javascript"); -const ts = require("typescript"); -const { CodeFormatter } = require("./code-formatter"); -const { pascalCase } = require("./util/pascal-case"); -const { internalCase } = require("./util/internal-case"); -const { sortByProperty } = require("./util/sort-by-property"); +import _ from "lodash"; +import ts from "typescript"; +import { CodeFormatter } from "./code-formatter.js"; +import { CodeGenConfig } from "./configuration.js"; +import { SchemaComponentsMap } from "./schema-components-map.js"; +import { SchemaParserFabric } from "./schema-parser/schema-parser-fabric.js"; +import { SchemaRoutes } from "./schema-routes/schema-routes.js"; +import { SchemaWalker } from "./schema-walker.js"; +import { SwaggerSchemaResolver } from "./swagger-schema-resolver.js"; +import { TemplatesWorker } from "./templates-worker.js"; +import { JavascriptTranslator } from "./translators/javascript.js"; +import { TypeNameFormatter } from "./type-name-formatter.js"; +import { FileSystem } from "./util/file-system.js"; +import { internalCase } from "./util/internal-case.js"; +import { Logger } from "./util/logger.js"; +import { NameResolver } from "./util/name-resolver.js"; +import { pascalCase } from "./util/pascal-case.js"; +import { sortByProperty } from "./util/sort-by-property.js"; const PATCHABLE_INSTANCES = [ "schemaWalker", @@ -566,6 +566,4 @@ class CodeGenProcess { }; } -module.exports = { - CodeGenProcess, -}; +export { CodeGenProcess }; diff --git a/src/commands/generate-templates/configuration.js b/src/commands/generate-templates/configuration.js index dd1529c2..1c595e63 100644 --- a/src/commands/generate-templates/configuration.js +++ b/src/commands/generate-templates/configuration.js @@ -1,5 +1,5 @@ -const { objectAssign } = require("../../util/object-assign"); -const { HTTP_CLIENT, PROJECT_VERSION } = require("../../constants"); +import { HTTP_CLIENT, PROJECT_VERSION } from "../../constants.js"; +import { objectAssign } from "../../util/object-assign.js"; /** * @type {GenerateTemplatesParams}} @@ -28,6 +28,4 @@ class TemplatesGenConfig { }; } -module.exports = { - TemplatesGenConfig, -}; +export { TemplatesGenConfig }; diff --git a/src/commands/generate-templates/index.js b/src/commands/generate-templates/index.js index d32283b1..fd674193 100644 --- a/src/commands/generate-templates/index.js +++ b/src/commands/generate-templates/index.js @@ -1,16 +1,10 @@ #!/usr/bin/env node -// Copyright (c) 2019-present acacode -// Node module: swagger-typescript-api -// This file is licensed under the MIT License. -// License text available at https://opensource.org/licenses/MIT -// Repository https://github.com/acacode/swagger-typescript-api +import { TemplatesGenProcess } from "./templates-gen-process.js"; -const { TemplatesGenProcess } = require("./templates-gen-process"); +async function generateTemplates(config) { + const codeGenProcess = new TemplatesGenProcess(config); + return await codeGenProcess.start(); +} -module.exports = { - generateTemplates: async (config) => { - const codeGenProcess = new TemplatesGenProcess(config); - return await codeGenProcess.start(); - }, -}; +export { generateTemplates }; diff --git a/src/commands/generate-templates/templates-gen-process.js b/src/commands/generate-templates/templates-gen-process.js index 15ba87f3..6fe22618 100644 --- a/src/commands/generate-templates/templates-gen-process.js +++ b/src/commands/generate-templates/templates-gen-process.js @@ -1,7 +1,10 @@ -const { TemplatesGenConfig } = require("./configuration"); -const { FileSystem } = require("../../util/file-system"); -const { Logger } = require("../../util/logger"); -const path = require("node:path"); +import path from "node:path"; +import url from "node:url"; +import { FileSystem } from "../../util/file-system.js"; +import { Logger } from "../../util/logger.js"; +import { TemplatesGenConfig } from "./configuration.js"; + +const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); class TemplatesGenProcess { /** @@ -199,6 +202,4 @@ class TemplatesGenProcess { }; } -module.exports = { - TemplatesGenProcess, -}; +export { TemplatesGenProcess }; diff --git a/src/component-type-name-resolver.js b/src/component-type-name-resolver.js index 63dde60d..080036bb 100644 --- a/src/component-type-name-resolver.js +++ b/src/component-type-name-resolver.js @@ -1,5 +1,5 @@ -const { getRandomInt } = require("./util/random"); -const { NameResolver } = require("./util/name-resolver"); +import { NameResolver } from "./util/name-resolver.js"; +import { getRandomInt } from "./util/random.js"; class ComponentTypeNameResolver extends NameResolver { counter = 1; @@ -39,6 +39,4 @@ class ComponentTypeNameResolver extends NameResolver { } } -module.exports = { - ComponentTypeNameResolver, -}; +export { ComponentTypeNameResolver }; diff --git a/src/configuration.js b/src/configuration.js index 93d90b7b..15a6c53b 100644 --- a/src/configuration.js +++ b/src/configuration.js @@ -1,10 +1,9 @@ -/* eslint-disable no-unused-vars */ -const { objectAssign } = require("./util/object-assign"); -const _ = require("lodash"); -const CONSTANTS = require("./constants"); -const { ComponentTypeNameResolver } = require("./component-type-name-resolver"); -const { cosmiconfigSync } = require("cosmiconfig"); -const ts = require("typescript"); +import { cosmiconfigSync } from "cosmiconfig"; +import _ from "lodash"; +import ts from "typescript"; +import { ComponentTypeNameResolver } from "./component-type-name-resolver.js"; +import * as CONSTANTS from "./constants.js"; +import { objectAssign } from "./util/object-assign.js"; const TsKeyword = { Number: "number", @@ -443,6 +442,4 @@ const getDefaultPrettierOptions = () => { return { ...CONSTANTS.PRETTIER_OPTIONS }; }; -module.exports = { - CodeGenConfig, -}; +export { CodeGenConfig }; diff --git a/src/constants.js b/src/constants.js index d6916fd5..f34b3a31 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,14 +1,51 @@ +import { createRequire } from "node:module"; + +const require = createRequire(import.meta.url); const packageJson = require("../package.json"); -const RESERVED_QUERY_ARG_NAMES = ["query", "queryParams", "queryArg"]; + +const DEFAULT_BODY_ARG_NAME = "data"; + +const FILE_PREFIX = `/* eslint-disable */ +/* tslint:disable */ +/* + * --------------------------------------------------------------- + * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## + * ## ## + * ## AUTHOR: acacode ## + * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## + * --------------------------------------------------------------- + */ + +`; + +const HTTP_CLIENT = { + FETCH: "fetch", + AXIOS: "axios", +}; + +const PRETTIER_OPTIONS = { + printWidth: 120, + tabWidth: 2, + trailingComma: "all", + parser: "typescript", +}; + +const PROJECT_VERSION = packageJson.version; + const RESERVED_BODY_ARG_NAMES = ["data", "body", "reqBody"]; + +const RESERVED_HEADER_ARG_NAMES = ["headers", "headersParams"]; + +const RESERVED_PATH_ARG_NAMES = ["path", "pathParams"]; + +const RESERVED_QUERY_ARG_NAMES = ["query", "queryParams", "queryArg"]; + const RESERVED_REQ_PARAMS_ARG_NAMES = [ "params", "requestParams", "reqParams", "httpParams", ]; -const RESERVED_PATH_ARG_NAMES = ["path", "pathParams"]; -const RESERVED_HEADER_ARG_NAMES = ["headers", "headersParams"]; const SCHEMA_TYPES = { ARRAY: "array", @@ -25,41 +62,16 @@ const SCHEMA_TYPES = { COMPLEX_UNKNOWN: "__unknown", }; -const HTTP_CLIENT = { - FETCH: "fetch", - AXIOS: "axios", -}; - -const PROJECT_VERSION = packageJson.version; - -const FILE_PREFIX = `/* eslint-disable */ -/* tslint:disable */ -/* - * --------------------------------------------------------------- - * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## - * ## ## - * ## AUTHOR: acacode ## - * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## - * --------------------------------------------------------------- - */ - -`; - -module.exports = { +export { + DEFAULT_BODY_ARG_NAME, FILE_PREFIX, - DEFAULT_BODY_ARG_NAME: "data", - PROJECT_VERSION, - SCHEMA_TYPES, HTTP_CLIENT, - RESERVED_QUERY_ARG_NAMES, + PRETTIER_OPTIONS, + PROJECT_VERSION, RESERVED_BODY_ARG_NAMES, - RESERVED_REQ_PARAMS_ARG_NAMES, - RESERVED_PATH_ARG_NAMES, RESERVED_HEADER_ARG_NAMES, - PRETTIER_OPTIONS: { - printWidth: 120, - tabWidth: 2, - trailingComma: "all", - parser: "typescript", - }, + RESERVED_PATH_ARG_NAMES, + RESERVED_QUERY_ARG_NAMES, + RESERVED_REQ_PARAMS_ARG_NAMES, + SCHEMA_TYPES, }; diff --git a/src/index.js b/src/index.js index e8950158..140a70de 100644 --- a/src/index.js +++ b/src/index.js @@ -1,26 +1,16 @@ #!/usr/bin/env node -// Copyright (c) 2019-present acacode -// Node module: swagger-typescript-api -// This file is licensed under the MIT License. -// License text available at https://opensource.org/licenses/MIT -// Repository https://github.com/acacode/swagger-typescript-api +import { CodeGenProcess } from "./code-gen-process.js"; +import { generateTemplates } from "./commands/generate-templates/index.js"; +import * as constants from "./constants.js"; -const constants = require("./constants"); -const { CodeGenProcess } = require("./code-gen-process.js"); -const { generateTemplates } = require("./commands/generate-templates"); +async function generateApi({ name, prettier, ...config }) { + const codeGenProcess = new CodeGenProcess({ + ...config, + fileName: name, + prettierOptions: prettier, + }); + return await codeGenProcess.start(); +} -module.exports = { - constants: constants, - generateApi: async ({ name, prettier, ...config }) => { - const codeGenProcess = new CodeGenProcess({ - ...config, - fileName: name, - prettierOptions: prettier, - }); - return await codeGenProcess.start(); - }, - generateTemplates: async (config) => { - return await generateTemplates(config); - }, -}; +export { constants, generateApi, generateTemplates }; diff --git a/src/schema-components-map.js b/src/schema-components-map.js index d196636c..f0b6130b 100644 --- a/src/schema-components-map.js +++ b/src/schema-components-map.js @@ -1,4 +1,4 @@ -const _ = require("lodash"); +import _ from "lodash"; class SchemaComponentsMap { /** @type {SchemaComponent[]} */ @@ -73,6 +73,4 @@ class SchemaComponentsMap { } } -module.exports = { - SchemaComponentsMap, -}; +export { SchemaComponentsMap }; diff --git a/src/schema-parser/base-schema-parsers/array.js b/src/schema-parser/base-schema-parsers/array.js index 7245ca11..073386e8 100644 --- a/src/schema-parser/base-schema-parsers/array.js +++ b/src/schema-parser/base-schema-parsers/array.js @@ -1,6 +1,6 @@ -const { MonoSchemaParser } = require("../mono-schema-parser"); -const _ = require("lodash"); -const { SCHEMA_TYPES } = require("../../constants"); +import _ from "lodash"; +import { SCHEMA_TYPES } from "../../constants.js"; +import { MonoSchemaParser } from "../mono-schema-parser.js"; class ArraySchemaParser extends MonoSchemaParser { parse() { @@ -38,6 +38,4 @@ class ArraySchemaParser extends MonoSchemaParser { } } -module.exports = { - ArraySchemaParser, -}; +export { ArraySchemaParser }; diff --git a/src/schema-parser/base-schema-parsers/complex.js b/src/schema-parser/base-schema-parsers/complex.js index 49a46f28..08d15c49 100644 --- a/src/schema-parser/base-schema-parsers/complex.js +++ b/src/schema-parser/base-schema-parsers/complex.js @@ -1,6 +1,6 @@ -const { MonoSchemaParser } = require("../mono-schema-parser"); -const _ = require("lodash"); -const { SCHEMA_TYPES } = require("../../constants"); +import _ from "lodash"; +import { SCHEMA_TYPES } from "../../constants.js"; +import { MonoSchemaParser } from "../mono-schema-parser.js"; class ComplexSchemaParser extends MonoSchemaParser { parse() { @@ -46,6 +46,4 @@ class ComplexSchemaParser extends MonoSchemaParser { } } -module.exports = { - ComplexSchemaParser, -}; +export { ComplexSchemaParser }; diff --git a/src/schema-parser/base-schema-parsers/discriminator.js b/src/schema-parser/base-schema-parsers/discriminator.js index f28f6bea..49f48744 100644 --- a/src/schema-parser/base-schema-parsers/discriminator.js +++ b/src/schema-parser/base-schema-parsers/discriminator.js @@ -1,6 +1,6 @@ -const _ = require("lodash"); -const { SCHEMA_TYPES } = require("../../constants"); -const { MonoSchemaParser } = require("../mono-schema-parser"); +import _ from "lodash"; +import { SCHEMA_TYPES } from "../../constants.js"; +import { MonoSchemaParser } from "../mono-schema-parser.js"; class DiscriminatorSchemaParser extends MonoSchemaParser { parse() { @@ -302,6 +302,4 @@ class DiscriminatorSchemaParser extends MonoSchemaParser { }; } -module.exports = { - DiscriminatorSchemaParser, -}; +export { DiscriminatorSchemaParser }; diff --git a/src/schema-parser/base-schema-parsers/enum.js b/src/schema-parser/base-schema-parsers/enum.js index 98a05545..2be35842 100644 --- a/src/schema-parser/base-schema-parsers/enum.js +++ b/src/schema-parser/base-schema-parsers/enum.js @@ -1,7 +1,7 @@ -const { MonoSchemaParser } = require("../mono-schema-parser"); -const _ = require("lodash"); -const { SCHEMA_TYPES } = require("../../constants"); -const { EnumKeyResolver } = require("../util/enum-key-resolver"); +import _ from "lodash"; +import { SCHEMA_TYPES } from "../../constants.js"; +import { MonoSchemaParser } from "../mono-schema-parser.js"; +import { EnumKeyResolver } from "../util/enum-key-resolver.js"; class EnumSchemaParser extends MonoSchemaParser { /** @type {EnumKeyResolver} */ @@ -153,6 +153,4 @@ class EnumSchemaParser extends MonoSchemaParser { }; } -module.exports = { - EnumSchemaParser, -}; +export { EnumSchemaParser }; diff --git a/src/schema-parser/base-schema-parsers/object.js b/src/schema-parser/base-schema-parsers/object.js index 53fb7815..dae84bde 100644 --- a/src/schema-parser/base-schema-parsers/object.js +++ b/src/schema-parser/base-schema-parsers/object.js @@ -1,6 +1,6 @@ -const { MonoSchemaParser } = require("../mono-schema-parser"); -const _ = require("lodash"); -const { SCHEMA_TYPES } = require("../../constants"); +import _ from "lodash"; +import { SCHEMA_TYPES } from "../../constants.js"; +import { MonoSchemaParser } from "../mono-schema-parser.js"; class ObjectSchemaParser extends MonoSchemaParser { parse() { @@ -100,6 +100,4 @@ class ObjectSchemaParser extends MonoSchemaParser { }; } -module.exports = { - ObjectSchemaParser, -}; +export { ObjectSchemaParser }; diff --git a/src/schema-parser/base-schema-parsers/primitive.js b/src/schema-parser/base-schema-parsers/primitive.js index 3a01962d..fe3db0ac 100644 --- a/src/schema-parser/base-schema-parsers/primitive.js +++ b/src/schema-parser/base-schema-parsers/primitive.js @@ -1,6 +1,6 @@ -const { MonoSchemaParser } = require("../mono-schema-parser"); -const _ = require("lodash"); -const { SCHEMA_TYPES } = require("../../constants"); +import _ from "lodash"; +import { SCHEMA_TYPES } from "../../constants.js"; +import { MonoSchemaParser } from "../mono-schema-parser.js"; class PrimitiveSchemaParser extends MonoSchemaParser { parse() { @@ -58,6 +58,4 @@ class PrimitiveSchemaParser extends MonoSchemaParser { } } -module.exports = { - PrimitiveSchemaParser, -}; +export { PrimitiveSchemaParser }; diff --git a/src/schema-parser/complex-schema-parsers/all-of.js b/src/schema-parser/complex-schema-parsers/all-of.js index 8992c5fc..d0487022 100644 --- a/src/schema-parser/complex-schema-parsers/all-of.js +++ b/src/schema-parser/complex-schema-parsers/all-of.js @@ -1,5 +1,5 @@ -const { MonoSchemaParser } = require("../mono-schema-parser"); -const _ = require("lodash"); +import _ from "lodash"; +import { MonoSchemaParser } from "../mono-schema-parser.js"; // T1 & T2 class AllOfSchemaParser extends MonoSchemaParser { @@ -23,4 +23,4 @@ class AllOfSchemaParser extends MonoSchemaParser { } } -module.exports = { AllOfSchemaParser }; +export { AllOfSchemaParser }; diff --git a/src/schema-parser/complex-schema-parsers/any-of.js b/src/schema-parser/complex-schema-parsers/any-of.js index 667c307f..5f83e6d0 100644 --- a/src/schema-parser/complex-schema-parsers/any-of.js +++ b/src/schema-parser/complex-schema-parsers/any-of.js @@ -1,5 +1,5 @@ -const { MonoSchemaParser } = require("../mono-schema-parser"); -const _ = require("lodash"); +import _ from "lodash"; +import { MonoSchemaParser } from "../mono-schema-parser.js"; // T1 | T2 class AnyOfSchemaParser extends MonoSchemaParser { @@ -24,4 +24,4 @@ class AnyOfSchemaParser extends MonoSchemaParser { } } -module.exports = { AnyOfSchemaParser }; +export { AnyOfSchemaParser }; diff --git a/src/schema-parser/complex-schema-parsers/not.js b/src/schema-parser/complex-schema-parsers/not.js index cc6bfddd..1fb94363 100644 --- a/src/schema-parser/complex-schema-parsers/not.js +++ b/src/schema-parser/complex-schema-parsers/not.js @@ -1,4 +1,4 @@ -const { MonoSchemaParser } = require("../mono-schema-parser"); +import { MonoSchemaParser } from "../mono-schema-parser.js"; class NotSchemaParser extends MonoSchemaParser { parse() { @@ -6,4 +6,4 @@ class NotSchemaParser extends MonoSchemaParser { } } -module.exports = { NotSchemaParser }; +export { NotSchemaParser }; diff --git a/src/schema-parser/complex-schema-parsers/one-of.js b/src/schema-parser/complex-schema-parsers/one-of.js index 58117de0..f5c3247c 100644 --- a/src/schema-parser/complex-schema-parsers/one-of.js +++ b/src/schema-parser/complex-schema-parsers/one-of.js @@ -1,5 +1,5 @@ -const { MonoSchemaParser } = require("../mono-schema-parser"); -const _ = require("lodash"); +import _ from "lodash"; +import { MonoSchemaParser } from "../mono-schema-parser.js"; // T1 | T2 class OneOfSchemaParser extends MonoSchemaParser { @@ -24,4 +24,4 @@ class OneOfSchemaParser extends MonoSchemaParser { } } -module.exports = { OneOfSchemaParser }; +export { OneOfSchemaParser }; diff --git a/src/schema-parser/mono-schema-parser.js b/src/schema-parser/mono-schema-parser.js index f5d6e0d3..b53132c0 100644 --- a/src/schema-parser/mono-schema-parser.js +++ b/src/schema-parser/mono-schema-parser.js @@ -43,6 +43,4 @@ class MonoSchemaParser { }; } -module.exports = { - MonoSchemaParser, -}; +export { MonoSchemaParser }; diff --git a/src/schema-parser/schema-formatters.js b/src/schema-parser/schema-formatters.js index d1c65da4..88151d8b 100644 --- a/src/schema-parser/schema-formatters.js +++ b/src/schema-parser/schema-formatters.js @@ -1,5 +1,5 @@ -const { SCHEMA_TYPES } = require("../constants"); -const _ = require("lodash"); +import _ from "lodash"; +import { SCHEMA_TYPES } from "../constants.js"; class SchemaFormatters { /** @type {CodeGenConfig} */ @@ -161,6 +161,4 @@ class SchemaFormatters { }; } -module.exports = { - SchemaFormatters, -}; +export { SchemaFormatters }; diff --git a/src/schema-parser/schema-parser-fabric.js b/src/schema-parser/schema-parser-fabric.js index 044aa2c4..2f93d8d3 100644 --- a/src/schema-parser/schema-parser-fabric.js +++ b/src/schema-parser/schema-parser-fabric.js @@ -1,7 +1,7 @@ -const _ = require("lodash"); -const { SchemaFormatters } = require("./schema-formatters"); -const { SchemaUtils } = require("./schema-utils"); -const { SchemaParser } = require("./schema-parser"); +import _ from "lodash"; +import { SchemaFormatters } from "./schema-formatters.js"; +import { SchemaParser } from "./schema-parser.js"; +import { SchemaUtils } from "./schema-utils.js"; class SchemaParserFabric { /** @type {CodeGenConfig} */ @@ -127,6 +127,4 @@ class SchemaParserFabric { }; } -module.exports = { - SchemaParserFabric, -}; +export { SchemaParserFabric }; diff --git a/src/schema-parser/schema-parser.js b/src/schema-parser/schema-parser.js index 6b4cd7ad..bd8ec092 100644 --- a/src/schema-parser/schema-parser.js +++ b/src/schema-parser/schema-parser.js @@ -1,21 +1,18 @@ -/* eslint-disable no-unused-vars */ -const { SCHEMA_TYPES } = require("../constants.js"); -const _ = require("lodash"); -const { SchemaFormatters } = require("./schema-formatters"); -const { SchemaUtils } = require("./schema-utils"); -const { - DiscriminatorSchemaParser, -} = require("./base-schema-parsers/discriminator"); -const { EnumSchemaParser } = require("./base-schema-parsers/enum"); -const { ObjectSchemaParser } = require("./base-schema-parsers/object"); -const { PrimitiveSchemaParser } = require("./base-schema-parsers/primitive"); -const { ComplexSchemaParser } = require("./base-schema-parsers/complex"); -const { OneOfSchemaParser } = require("./complex-schema-parsers/one-of"); -const { AllOfSchemaParser } = require("./complex-schema-parsers/all-of"); -const { AnyOfSchemaParser } = require("./complex-schema-parsers/any-of"); -const { NotSchemaParser } = require("./complex-schema-parsers/not"); -const { ArraySchemaParser } = require("./base-schema-parsers/array"); -const { sortByProperty } = require("../util/sort-by-property"); +import _ from "lodash"; +import { SCHEMA_TYPES } from "../constants.js"; +import { sortByProperty } from "../util/sort-by-property.js"; +import { ArraySchemaParser } from "./base-schema-parsers/array.js"; +import { ComplexSchemaParser } from "./base-schema-parsers/complex.js"; +import { DiscriminatorSchemaParser } from "./base-schema-parsers/discriminator.js"; +import { EnumSchemaParser } from "./base-schema-parsers/enum.js"; +import { ObjectSchemaParser } from "./base-schema-parsers/object.js"; +import { PrimitiveSchemaParser } from "./base-schema-parsers/primitive.js"; +import { AllOfSchemaParser } from "./complex-schema-parsers/all-of.js"; +import { AnyOfSchemaParser } from "./complex-schema-parsers/any-of.js"; +import { NotSchemaParser } from "./complex-schema-parsers/not.js"; +import { OneOfSchemaParser } from "./complex-schema-parsers/one-of.js"; +import { SchemaFormatters } from "./schema-formatters.js"; +import { SchemaUtils } from "./schema-utils.js"; class SchemaParser { /** @type {SchemaParserFabric} */ @@ -295,6 +292,4 @@ class SchemaParser { }; } -module.exports = { - SchemaParser, -}; +export { SchemaParser }; diff --git a/src/schema-parser/schema-utils.js b/src/schema-parser/schema-utils.js index ddf058d1..1b155e05 100644 --- a/src/schema-parser/schema-utils.js +++ b/src/schema-parser/schema-utils.js @@ -1,8 +1,7 @@ -const _ = require("lodash"); -const { SCHEMA_TYPES } = require("../constants"); -const { internalCase } = require("../util/internal-case"); -const { pascalCase } = require("../util/pascal-case"); -const { camelCase } = require("lodash"); +import _ from "lodash"; +import { SCHEMA_TYPES } from "../constants.js"; +import { internalCase } from "../util/internal-case.js"; +import { pascalCase } from "../util/pascal-case.js"; class SchemaUtils { /** @type {CodeGenConfig} */ @@ -285,7 +284,7 @@ class SchemaUtils { if (!schemaPath || !schemaPath[0]) return null; return pascalCase( - camelCase( + _.camelCase( _.uniq([schemaPath[0], schemaPath[schemaPath.length - 1]]).join("_"), ), ); @@ -317,6 +316,4 @@ class SchemaUtils { }; } -module.exports = { - SchemaUtils, -}; +export { SchemaUtils }; diff --git a/src/schema-parser/util/enum-key-resolver.js b/src/schema-parser/util/enum-key-resolver.js index b609e5fa..844c9c51 100644 --- a/src/schema-parser/util/enum-key-resolver.js +++ b/src/schema-parser/util/enum-key-resolver.js @@ -1,4 +1,4 @@ -const { NameResolver } = require("../../util/name-resolver"); +import { NameResolver } from "../../util/name-resolver.js"; class EnumKeyResolver extends NameResolver { counter = 1; @@ -21,6 +21,4 @@ class EnumKeyResolver extends NameResolver { } } -module.exports = { - EnumKeyResolver, -}; +export { EnumKeyResolver }; diff --git a/src/schema-routes/schema-routes.js b/src/schema-routes/schema-routes.js index b94a00f7..9ac07d0b 100644 --- a/src/schema-routes/schema-routes.js +++ b/src/schema-routes/schema-routes.js @@ -1,16 +1,13 @@ -const _ = require("lodash"); -const { generateId } = require("../util/id.js"); -const { - SpecificArgNameResolver, -} = require("./util/specific-arg-name-resolver"); -const { +import _ from "lodash"; +import { DEFAULT_BODY_ARG_NAME, RESERVED_BODY_ARG_NAMES, RESERVED_HEADER_ARG_NAMES, RESERVED_PATH_ARG_NAMES, RESERVED_QUERY_ARG_NAMES, -} = require("../constants.js"); -const { camelCase } = require("lodash"); +} from "../constants.js"; +import { generateId } from "../util/id.js"; +import { SpecificArgNameResolver } from "./util/specific-arg-name-resolver.js"; const CONTENT_KIND = { JSON: "JSON", @@ -540,7 +537,7 @@ class SchemaRoutes { let usageName = `${schemaPart.name}`; if (usageName.includes(".")) { - usageName = camelCase(usageName); + usageName = _.camelCase(usageName); } return { @@ -1208,6 +1205,4 @@ class SchemaRoutes { }; } -module.exports = { - SchemaRoutes, -}; +export { SchemaRoutes }; diff --git a/src/schema-routes/util/specific-arg-name-resolver.js b/src/schema-routes/util/specific-arg-name-resolver.js index cd624f46..2adee8da 100644 --- a/src/schema-routes/util/specific-arg-name-resolver.js +++ b/src/schema-routes/util/specific-arg-name-resolver.js @@ -1,4 +1,4 @@ -const { NameResolver } = require("../../util/name-resolver"); +import { NameResolver } from "../../util/name-resolver.js"; class SpecificArgNameResolver extends NameResolver { counter = 1; @@ -21,6 +21,4 @@ class SpecificArgNameResolver extends NameResolver { } } -module.exports = { - SpecificArgNameResolver, -}; +export { SpecificArgNameResolver }; diff --git a/src/schema-walker.js b/src/schema-walker.js index e2055c31..7fd922f9 100644 --- a/src/schema-walker.js +++ b/src/schema-walker.js @@ -1,4 +1,4 @@ -const _ = require("lodash"); +import _ from "lodash"; // TODO: WIP // this class will be needed to walk by schema everywhere @@ -88,6 +88,4 @@ class SchemaWalker { }; } -module.exports = { - SchemaWalker, -}; +export { SchemaWalker }; diff --git a/src/swagger-schema-resolver.js b/src/swagger-schema-resolver.js index 1196650f..b79cd85a 100644 --- a/src/swagger-schema-resolver.js +++ b/src/swagger-schema-resolver.js @@ -1,7 +1,7 @@ -const _ = require("lodash"); -const converter = require("swagger2openapi"); -const yaml = require("js-yaml"); -const { Request } = require("./util/request"); +import yaml from "js-yaml"; +import _ from "lodash"; +import converter from "swagger2openapi"; +import { Request } from "./util/request.js"; class SwaggerSchemaResolver { /** @@ -192,6 +192,4 @@ class SwaggerSchemaResolver { } } -module.exports = { - SwaggerSchemaResolver, -}; +export { SwaggerSchemaResolver }; diff --git a/src/templates-worker.js b/src/templates-worker.js index 9d4e3214..9b834f0a 100644 --- a/src/templates-worker.js +++ b/src/templates-worker.js @@ -1,7 +1,8 @@ -const { resolve } = require("node:path"); -const _ = require("lodash"); -const Eta = require("eta"); -const path = require("node:path"); +import { resolve } from "node:path"; +import path from "node:path"; +import url from "node:url"; +import * as Eta from "eta"; +import _ from "lodash"; class TemplatesWorker { /** @@ -34,6 +35,7 @@ class TemplatesWorker { * @returns {CodeGenConfig.templatePaths} */ getTemplatePaths = (config) => { + const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); const baseTemplatesPath = resolve(__dirname, "../templates/base"); const defaultTemplatesPath = resolve(__dirname, "../templates/default"); const modularTemplatesPath = resolve(__dirname, "../templates/modular"); @@ -238,6 +240,4 @@ class TemplatesWorker { }; } -module.exports = { - TemplatesWorker, -}; +export { TemplatesWorker }; diff --git a/src/translators/javascript.js b/src/translators/javascript.js index 133980fc..f90f0d14 100644 --- a/src/translators/javascript.js +++ b/src/translators/javascript.js @@ -1,5 +1,5 @@ -const ts = require("typescript"); -const { Translator } = require("./translator"); +import ts from "typescript"; +import { Translator } from "./translator.js"; class JavascriptTranslator extends Translator { /** @@ -78,6 +78,4 @@ class JavascriptTranslator extends Translator { }; } -module.exports = { - JavascriptTranslator, -}; +export { JavascriptTranslator }; diff --git a/src/translators/translator.js b/src/translators/translator.js index 1d68168e..8c4ecc64 100644 --- a/src/translators/translator.js +++ b/src/translators/translator.js @@ -30,6 +30,4 @@ class Translator { } } -module.exports = { - Translator, -}; +export { Translator }; diff --git a/src/type-name-formatter.js b/src/type-name-formatter.js index f8806471..a5ed4b8a 100644 --- a/src/type-name-formatter.js +++ b/src/type-name-formatter.js @@ -1,4 +1,4 @@ -const _ = require("lodash"); +import _ from "lodash"; /** * @typedef {"enum-key" | "type-name"} FormattingSchemaType @@ -108,6 +108,4 @@ class TypeNameFormatter { }; } -module.exports = { - TypeNameFormatter, -}; +export { TypeNameFormatter }; diff --git a/src/util/file-system.js b/src/util/file-system.js index 15ea38bd..dfb1d472 100644 --- a/src/util/file-system.js +++ b/src/util/file-system.js @@ -1,7 +1,8 @@ -const fs = require("node:fs"); -const { resolve } = require("node:path"); -const _ = require("lodash"); -const { Logger } = require("./logger"); +import fs from "node:fs"; +import { dirname, resolve } from "node:path"; +import url from "node:url"; +import _ from "lodash"; +import { Logger } from "./logger.js"; const FILE_PREFIX = `/* eslint-disable */ /* tslint:disable */ @@ -83,6 +84,7 @@ class FileSystem { }; createFile = ({ path, fileName, content, withPrefix }) => { + const __dirname = dirname(url.fileURLToPath(import.meta.url)); const absolutePath = resolve(__dirname, path, `./${fileName}`); const fileContent = `${withPrefix ? FILE_PREFIX : ""}${content}`; @@ -90,6 +92,4 @@ class FileSystem { }; } -module.exports = { - FileSystem, -}; +export { FileSystem }; diff --git a/src/util/id.js b/src/util/id.js index d4c6b30e..043dadab 100644 --- a/src/util/id.js +++ b/src/util/id.js @@ -1,9 +1,7 @@ -const { customAlphabet } = require("nanoid"); +import { customAlphabet } from "nanoid"; const ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789"; const generateId = customAlphabet(ALPHABET, 12); -module.exports = { - generateId, -}; +export { generateId }; diff --git a/src/util/internal-case.js b/src/util/internal-case.js index 81ae2b60..78c2aa5b 100644 --- a/src/util/internal-case.js +++ b/src/util/internal-case.js @@ -1,5 +1,7 @@ -const _ = require("lodash"); +import _ from "lodash"; -module.exports = { - internalCase: (value) => _.camelCase(_.lowerCase(value)), -}; +function internalCase(value) { + return _.camelCase(_.lowerCase(value)); +} + +export { internalCase }; diff --git a/src/util/logger.js b/src/util/logger.js index 52119a8f..f671d528 100644 --- a/src/util/logger.js +++ b/src/util/logger.js @@ -1,5 +1,5 @@ -const { emojify } = require("node-emoji"); -const _ = require("lodash"); +import _ from "lodash"; +import { emojify } from "node-emoji"; class Logger { firstLog = true; @@ -139,6 +139,4 @@ class Logger { }; } -module.exports = { - Logger, -}; +export { Logger }; diff --git a/src/util/name-resolver.js b/src/util/name-resolver.js index 5c816407..8d0ca42f 100644 --- a/src/util/name-resolver.js +++ b/src/util/name-resolver.js @@ -1,4 +1,4 @@ -const _ = require("lodash"); +import _ from "lodash"; class NameResolver { reservedNames = []; @@ -100,6 +100,4 @@ class NameResolver { } } -module.exports = { - NameResolver, -}; +export { NameResolver }; diff --git a/src/util/object-assign.js b/src/util/object-assign.js index 365c5a18..3eaff3a8 100644 --- a/src/util/object-assign.js +++ b/src/util/object-assign.js @@ -1,4 +1,4 @@ -const _ = require("lodash"); +import _ from "lodash"; const objectAssign = (target, updaterFn) => { if (!updaterFn) return; @@ -14,6 +14,4 @@ const objectAssign = (target, updaterFn) => { }); }; -module.exports = { - objectAssign, -}; +export { objectAssign }; diff --git a/src/util/pascal-case.js b/src/util/pascal-case.js index 1bb41c49..eb6b37d9 100644 --- a/src/util/pascal-case.js +++ b/src/util/pascal-case.js @@ -1,5 +1,7 @@ -const _ = require("lodash"); +import _ from "lodash"; -module.exports = { - pascalCase: (value) => _.upperFirst(_.camelCase(value)), -}; +function pascalCase(value) { + return _.upperFirst(_.camelCase(value)); +} + +export { pascalCase }; diff --git a/src/util/random.js b/src/util/random.js index 046e3ec6..31fef748 100644 --- a/src/util/random.js +++ b/src/util/random.js @@ -8,7 +8,4 @@ const getRandomInt = (min = 0, max = 1) => { return Math.round(getRandomFloat(min, max)); }; -module.exports = { - getRandomInt, - getRandomFloat, -}; +export { getRandomInt, getRandomFloat }; diff --git a/src/util/request.js b/src/util/request.js index 870d7647..2efa39ee 100644 --- a/src/util/request.js +++ b/src/util/request.js @@ -1,4 +1,4 @@ -const _ = require("lodash"); +import _ from "lodash"; class Request { /** @@ -60,6 +60,4 @@ class Request { } } -module.exports = { - Request, -}; +export { Request }; diff --git a/src/util/sort-by-property.js b/src/util/sort-by-property.js index 69def8e9..82dd85a5 100644 --- a/src/util/sort-by-property.js +++ b/src/util/sort-by-property.js @@ -12,6 +12,4 @@ const sortByProperty = (propertyName) => (o1, o2) => { return 0; }; -module.exports = { - sortByProperty, -}; +export { sortByProperty }; diff --git a/tests/extended.test.ts b/tests/extended.test.ts index f9d36b8d..a13394b5 100644 --- a/tests/extended.test.ts +++ b/tests/extended.test.ts @@ -21,7 +21,6 @@ describe("extended", async () => { const schemas = await collectAllSchemas(); test.each(schemas)("$name", async (schema) => { - // @ts-expect-error await generateApi({ name: schema.name, input: schema.filePath, diff --git a/tests/simple.test.ts b/tests/simple.test.ts index 71d8b32e..5acd14f7 100644 --- a/tests/simple.test.ts +++ b/tests/simple.test.ts @@ -21,7 +21,6 @@ describe("simple", async () => { const schemas = await collectAllSchemas(); test.each(schemas)("$name", async (schema) => { - // @ts-expect-error await generateApi({ name: schema.name, input: schema.filePath, diff --git a/tests/spec/additional-properties-2.0/basic.test.ts b/tests/spec/additional-properties-2.0/basic.test.ts index c301edc6..ac1ec590 100644 --- a/tests/spec/additional-properties-2.0/basic.test.ts +++ b/tests/spec/additional-properties-2.0/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("additional properties 2.0", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, addReadonly: true, diff --git a/tests/spec/another-array-type/basic.test.ts b/tests/spec/another-array-type/basic.test.ts index 269b1119..aa74320d 100644 --- a/tests/spec/another-array-type/basic.test.ts +++ b/tests/spec/another-array-type/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--another-array-type", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, anotherArrayType: true, diff --git a/tests/spec/another-query-params/basic.test.ts b/tests/spec/another-query-params/basic.test.ts index 87eefd1e..c08abad8 100644 --- a/tests/spec/another-query-params/basic.test.ts +++ b/tests/spec/another-query-params/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("another-query-params", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, generateClient: true, diff --git a/tests/spec/axios/basic.test.ts b/tests/spec/axios/basic.test.ts index 9f470706..e0d180d5 100644 --- a/tests/spec/axios/basic.test.ts +++ b/tests/spec/axios/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--axios option", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, generateClient: true, diff --git a/tests/spec/axiosSingleHttpClient/basic.test.ts b/tests/spec/axiosSingleHttpClient/basic.test.ts index 935fc376..9145872b 100644 --- a/tests/spec/axiosSingleHttpClient/basic.test.ts +++ b/tests/spec/axiosSingleHttpClient/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--axios --single-http-client", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, generateClient: true, diff --git a/tests/spec/cli/schema.json b/tests/spec/cli/schema.json deleted file mode 100644 index 8c57124b..00000000 --- a/tests/spec/cli/schema.json +++ /dev/null @@ -1,779 +0,0 @@ -{ - "swagger": "2.0", - "schemes": ["https"], - "host": "6-dot-authentiqio.appspot.com", - "basePath": "/", - "info": { - "contact": { - "email": "hello@authentiq.com", - "name": "Authentiq team", - "url": "http://authentiq.io/support" - }, - "description": "Strong authentication, without the passwords.", - "license": { - "name": "Apache 2.0", - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" - }, - "termsOfService": "http://authentiq.com/terms/", - "title": "Authentiq", - "version": "6", - "x-apisguru-categories": ["security"], - "x-logo": { - "backgroundColor": "#F26641", - "url": "https://api.apis.guru/v2/cache/logo/https_www.authentiq.com_theme_images_authentiq-logo-a-inverse.svg" - }, - "x-origin": [ - { - "format": "swagger", - "url": "https://raw.githubusercontent.com/AuthentiqID/authentiq-docs/master/docs/swagger/issuer.yaml", - "version": "2.0" - } - ], - "x-preferred": true, - "x-providerName": "6-dot-authentiqio.appspot.com" - }, - "parameters": { - "AuthentiqID": { - "description": "Authentiq ID to register", - "in": "body", - "name": "body", - "required": true, - "schema": { - "$ref": "#/definitions/AuthentiqID" - } - }, - "JobID": { - "description": "Job ID (20 chars)", - "in": "path", - "name": "job", - "required": true, - "type": "string" - }, - "PK": { - "description": "Public Signing Key - Authentiq ID (43 chars)", - "in": "path", - "name": "PK", - "required": true, - "type": "string" - }, - "PushToken": { - "description": "Push Token.", - "in": "body", - "name": "body", - "required": true, - "schema": { - "$ref": "#/definitions/PushToken" - } - }, - "Scope": { - "description": "Claims of scope", - "in": "body", - "name": "body", - "required": true, - "schema": { - "$ref": "#/definitions/Claims" - } - } - }, - "responses": { - "ErrorResponse": { - "description": "Error response", - "schema": { - "$ref": "#/definitions/Error" - } - } - }, - "paths": { - "/key": { - "delete": { - "description": "Revoke an Authentiq ID using email & phone.\n\nIf called with `email` and `phone` only, a verification code \nwill be sent by email. Do a second call adding `code` to \ncomplete the revocation.\n", - "operationId": "key_revoke_nosecret", - "parameters": [ - { - "description": "primary email associated to Key (ID)", - "in": "query", - "name": "email", - "required": true, - "type": "string" - }, - { - "description": "primary phone number, international representation", - "in": "query", - "name": "phone", - "required": true, - "type": "string" - }, - { - "description": "verification code sent by email", - "in": "query", - "name": "code", - "required": false, - "type": "string" - } - ], - "produces": ["application/json"], - "responses": { - "200": { - "description": "Successfully deleted", - "schema": { - "properties": { - "status": { - "description": "pending or done", - "type": "string" - } - }, - "type": "object" - } - }, - "401": { - "description": "Authentication error `auth-error`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "404": { - "description": "Unknown key `unknown-key`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "409": { - "description": "Confirm with code sent `confirm-first`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "default": { - "$ref": "#/responses/ErrorResponse" - } - }, - "tags": ["key", "delete"] - }, - "post": { - "consumes": ["application/jwt"], - "description": "Register a new ID `JWT(sub, devtoken)`\n\nv5: `JWT(sub, pk, devtoken, ...)`\n\nSee: https://github.com/skion/authentiq/wiki/JWT-Examples\n", - "operationId": "key_register", - "parameters": [ - { - "$ref": "#/parameters/AuthentiqID" - } - ], - "produces": ["application/json"], - "responses": { - "201": { - "description": "Successfully registered", - "schema": { - "properties": { - "secret": { - "description": "revoke key", - "type": "string" - }, - "status": { - "description": "registered", - "type": "string" - } - }, - "type": "object" - } - }, - "409": { - "description": "Key already registered `duplicate-key`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "default": { - "$ref": "#/responses/ErrorResponse" - } - }, - "tags": ["key", "post"] - } - }, - "/key/{PK}": { - "delete": { - "description": "Revoke an Identity (Key) with a revocation secret", - "operationId": "key_revoke", - "parameters": [ - { - "$ref": "#/parameters/PK" - }, - { - "description": "revokation secret", - "in": "query", - "name": "secret", - "required": true, - "type": "string" - } - ], - "produces": ["application/json"], - "responses": { - "200": { - "description": "Successful response", - "schema": { - "properties": { - "status": { - "description": "done", - "type": "string" - } - }, - "type": "object" - } - }, - "401": { - "description": "Key not found / wrong code `auth-error`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "404": { - "description": "Unknown key `unknown-key`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "default": { - "$ref": "#/responses/ErrorResponse" - } - }, - "tags": ["key", "delete"] - }, - "get": { - "description": "Get public details of an Authentiq ID.\n", - "parameters": [ - { - "$ref": "#/parameters/PK" - } - ], - "produces": ["application/json"], - "responses": { - "200": { - "description": "Successfully retrieved", - "schema": { - "properties": { - "since": { - "format": "date-time", - "type": "string" - }, - "status": { - "type": "string" - }, - "sub": { - "description": "base64safe encoded public signing key", - "type": "string" - } - }, - "title": "JWT", - "type": "object" - } - }, - "404": { - "description": "Unknown key `unknown-key`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "410": { - "description": "Key is revoked (gone). `revoked-key`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "default": { - "$ref": "#/responses/ErrorResponse" - } - }, - "tags": ["key", "get"] - }, - "head": { - "description": "HEAD info on Authentiq ID\n", - "parameters": [ - { - "$ref": "#/parameters/PK" - } - ], - "responses": { - "200": { - "description": "Key exists" - }, - "404": { - "description": "Unknown key `unknown-key`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "410": { - "description": "Key is revoked `revoked-key`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "default": { - "$ref": "#/responses/ErrorResponse" - } - }, - "tags": ["key", "head"] - }, - "post": { - "consumes": ["application/jwt"], - "description": "update properties of an Authentiq ID.\n(not operational in v4; use PUT for now)\n\nv5: POST issuer-signed email & phone scopes in\na self-signed JWT\n\nSee: https://github.com/skion/authentiq/wiki/JWT-Examples\n", - "operationId": "key_update", - "parameters": [ - { - "$ref": "#/parameters/PK" - }, - { - "$ref": "#/parameters/AuthentiqID" - } - ], - "produces": ["application/json"], - "responses": { - "200": { - "description": "Successfully updated", - "schema": { - "properties": { - "status": { - "description": "confirmed", - "type": "string" - } - }, - "type": "object" - } - }, - "404": { - "description": "Unknown key `unknown-key`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "default": { - "$ref": "#/responses/ErrorResponse" - } - }, - "tags": ["key", "post"] - }, - "put": { - "consumes": ["application/jwt"], - "description": "Update Authentiq ID by replacing the object.\n\nv4: `JWT(sub,email,phone)` to bind email/phone hash; \n\nv5: POST issuer-signed email & phone scopes\nand PUT to update registration `JWT(sub, pk, devtoken, ...)`\n\nSee: https://github.com/skion/authentiq/wiki/JWT-Examples\n", - "operationId": "key_bind", - "parameters": [ - { - "$ref": "#/parameters/PK" - }, - { - "$ref": "#/parameters/AuthentiqID" - } - ], - "produces": ["application/json"], - "responses": { - "200": { - "description": "Successfully updated", - "schema": { - "properties": { - "status": { - "description": "confirmed", - "type": "string" - } - }, - "type": "object" - } - }, - "404": { - "description": "Unknown key `unknown-key`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "409": { - "description": "Already bound to another key `duplicate-hash`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "default": { - "$ref": "#/responses/ErrorResponse" - } - }, - "tags": ["key", "put"] - } - }, - "/login": { - "post": { - "consumes": ["application/jwt"], - "description": "push sign-in request\nSee: https://github.com/skion/authentiq/wiki/JWT-Examples\n", - "operationId": "push_login_request", - "parameters": [ - { - "$ref": "#/parameters/PushToken" - }, - { - "description": "URI App will connect to", - "in": "query", - "name": "callback", - "required": true, - "type": "string" - } - ], - "produces": ["application/json"], - "responses": { - "200": { - "description": "Successful response", - "schema": { - "properties": { - "status": { - "description": "sent", - "type": "string" - } - }, - "type": "object" - } - }, - "401": { - "description": "Unauthorized for this callback audience `aud-error` or JWT should be self-signed `auth-error`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "default": { - "$ref": "#/responses/ErrorResponse" - } - }, - "tags": ["login", "post"] - } - }, - "/scope": { - "post": { - "consumes": ["application/jwt"], - "description": "scope verification request\nSee: https://github.com/skion/authentiq/wiki/JWT-Examples\n", - "operationId": "sign_request", - "parameters": [ - { - "$ref": "#/parameters/Scope" - }, - { - "description": "test only mode, using test issuer", - "in": "query", - "name": "test", - "required": false, - "type": "integer" - } - ], - "produces": ["application/json"], - "responses": { - "201": { - "description": "Successful response", - "schema": { - "properties": { - "job": { - "description": "20-character ID", - "type": "string" - }, - "status": { - "description": "waiting", - "type": "string" - } - }, - "type": "object" - } - }, - "429": { - "description": "Too Many Requests on same address / number `rate-limit`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "default": { - "$ref": "#/responses/ErrorResponse" - } - }, - "tags": ["scope", "post"] - } - }, - "/scope/{job}": { - "delete": { - "description": "delete a verification job", - "operationId": "sign_delete", - "parameters": [ - { - "$ref": "#/parameters/JobID" - } - ], - "produces": ["application/json"], - "responses": { - "200": { - "description": "Successfully deleted", - "schema": { - "properties": { - "status": { - "description": "done", - "type": "string" - } - }, - "type": "object" - } - }, - "404": { - "description": "Job not found `unknown-job`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "default": { - "$ref": "#/responses/ErrorResponse" - } - }, - "tags": ["scope", "delete"] - }, - "get": { - "description": "get the status / current content of a verification job", - "operationId": "sign_retrieve", - "parameters": [ - { - "$ref": "#/parameters/JobID" - } - ], - "produces": ["application/json", "application/jwt"], - "responses": { - "200": { - "description": "Successful response (JWT)", - "schema": { - "properties": { - "exp": { - "type": "integer" - }, - "field": { - "type": "string" - }, - "sub": { - "description": "base64safe encoded public signing key", - "type": "string" - } - }, - "title": "JWT", - "type": "object" - } - }, - "204": { - "description": "Confirmed, waiting for signing" - }, - "404": { - "description": "Job not found `unknown-job`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "default": { - "$ref": "#/responses/ErrorResponse" - } - }, - "tags": ["scope", "get"] - }, - "head": { - "description": "HEAD to get the status of a verification job", - "operationId": "sign_retrieve_head", - "parameters": [ - { - "$ref": "#/parameters/JobID" - } - ], - "produces": ["application/json"], - "responses": { - "200": { - "description": "Confirmed and signed" - }, - "204": { - "description": "Confirmed, waiting for signing" - }, - "404": { - "description": "Job not found `unknown-job`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "default": { - "$ref": "#/responses/ErrorResponse" - } - }, - "tags": ["scope", "head"] - }, - "post": { - "consumes": ["application/json"], - "description": "this is a scope confirmation", - "operationId": "sign_confirm", - "parameters": [ - { - "$ref": "#/parameters/JobID" - } - ], - "produces": ["application/json"], - "responses": { - "202": { - "description": "Successfully confirmed", - "schema": { - "properties": { - "status": { - "description": "confirmed", - "type": "string" - } - }, - "type": "object" - } - }, - "401": { - "description": "Confirmation error `auth-error`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "404": { - "description": "Job not found `unknown-job`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "405": { - "description": "JWT POSTed to scope `not-supported`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "default": { - "$ref": "#/responses/ErrorResponse" - } - }, - "tags": ["scope", "post"] - }, - "put": { - "consumes": ["application/jwt"], - "description": "authority updates a JWT with its signature\nSee: https://github.com/skion/authentiq/wiki/JWT-Examples\n", - "operationId": "sign_update", - "parameters": [ - { - "$ref": "#/parameters/JobID" - } - ], - "produces": ["application/jwt"], - "responses": { - "200": { - "description": "Successfully updated", - "schema": { - "properties": { - "jwt": { - "description": "result is JWT or JSON??", - "type": "string" - }, - "status": { - "description": "ready", - "type": "string" - } - }, - "type": "object" - } - }, - "404": { - "description": "Job not found `unknown-job`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "409": { - "description": "Job not confirmed yet `confirm-first`", - "schema": { - "$ref": "#/definitions/Error" - } - }, - "default": { - "$ref": "#/responses/ErrorResponse" - } - }, - "tags": ["scope", "put"] - } - } - }, - "definitions": { - "AuthentiqID": { - "description": "Authentiq ID in JWT format, self-signed.\n", - "properties": { - "devtoken": { - "description": "device token for push messages", - "type": "string" - }, - "sub": { - "description": "UUID and public signing key", - "type": "string" - } - }, - "required": ["sub"] - }, - "Claims": { - "description": "Claim in JWT format, self- or issuer-signed. \n", - "properties": { - "email": { - "description": "", - "type": "string" - }, - "phone": { - "description": "", - "type": "string" - }, - "scope": { - "description": "claim scope", - "type": "string" - }, - "sub": { - "description": "UUID", - "type": "string" - }, - "type": { - "description": "", - "type": "string" - } - }, - "required": ["sub", "scope"] - }, - "Error": { - "properties": { - "detail": { - "type": "string" - }, - "error": { - "type": "integer" - }, - "title": { - "type": "string" - }, - "type": { - "description": "unique uri for this error", - "type": "string" - } - }, - "required": ["error"] - }, - "PushToken": { - "description": "PushToken in JWT format, self-signed. \n", - "properties": { - "aud": { - "description": "audience (URI)", - "type": "string" - }, - "exp": { - "type": "integer" - }, - "iat": { - "type": "integer" - }, - "iss": { - "description": "issuer (URI)", - "type": "string" - }, - "nbf": { - "type": "integer" - }, - "sub": { - "description": "UUID and public signing key", - "type": "string" - } - }, - "required": ["sub", "iss", "aud"] - } - } -} diff --git a/tests/spec/cli/test.js b/tests/spec/cli/test.js deleted file mode 100644 index 837b19c3..00000000 --- a/tests/spec/cli/test.js +++ /dev/null @@ -1,9 +0,0 @@ -const validateGeneratedModule = require("../../helpers/validateGeneratedModule"); -const { resolve } = require("node:path"); -const assertGeneratedModule = require("../../helpers/assertGeneratedModule"); - -validateGeneratedModule(resolve(__dirname, "./schema.ts")); -assertGeneratedModule( - resolve(__dirname, "./schema.ts"), - resolve(__dirname, "./expected.ts"), -); diff --git a/tests/spec/const-keyword/basic.test.ts b/tests/spec/const-keyword/basic.test.ts index 90d839bf..dbd0273c 100644 --- a/tests/spec/const-keyword/basic.test.ts +++ b/tests/spec/const-keyword/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("const-keyword", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, addReadonly: true, diff --git a/tests/spec/custom-extensions/basic.test.ts b/tests/spec/custom-extensions/basic.test.ts index 2c3279f9..caea62b8 100644 --- a/tests/spec/custom-extensions/basic.test.ts +++ b/tests/spec/custom-extensions/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("custom extensions", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, }); diff --git a/tests/spec/defaultAsSuccess/basic.test.ts b/tests/spec/defaultAsSuccess/basic.test.ts index 0369fc0d..01bd78d3 100644 --- a/tests/spec/defaultAsSuccess/basic.test.ts +++ b/tests/spec/defaultAsSuccess/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--default-as-success", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, defaultResponseAsSuccess: true, diff --git a/tests/spec/defaultResponse/basic.test.ts b/tests/spec/defaultResponse/basic.test.ts index a6cd8a56..87d96b6a 100644 --- a/tests/spec/defaultResponse/basic.test.ts +++ b/tests/spec/defaultResponse/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--default-response", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, defaultResponseType: "unknown", diff --git a/tests/spec/deprecated/basic.test.ts b/tests/spec/deprecated/basic.test.ts index f05b2375..e59796ee 100644 --- a/tests/spec/deprecated/basic.test.ts +++ b/tests/spec/deprecated/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("@deprecated", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, queryParamsWithBrackets: true, diff --git a/tests/spec/discriminator/basic.test.ts b/tests/spec/discriminator/basic.test.ts index b2acb7a2..b8698fac 100644 --- a/tests/spec/discriminator/basic.test.ts +++ b/tests/spec/discriminator/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("discriminator", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, addReadonly: true, diff --git a/tests/spec/dot-path-params/basic.test.ts b/tests/spec/dot-path-params/basic.test.ts index ec04f00e..9d1819e3 100644 --- a/tests/spec/dot-path-params/basic.test.ts +++ b/tests/spec/dot-path-params/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--dot-path-params", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, generateClient: true, diff --git a/tests/spec/enumNamesAsValues/basic.test.ts b/tests/spec/enumNamesAsValues/basic.test.ts index 76a7e323..718dc24f 100644 --- a/tests/spec/enumNamesAsValues/basic.test.ts +++ b/tests/spec/enumNamesAsValues/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--enum-names-as-values", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, enumNamesAsValues: true, diff --git a/tests/spec/enums-2.0/basic.test.ts b/tests/spec/enums-2.0/basic.test.ts index ebe7396e..a38be9c2 100644 --- a/tests/spec/enums-2.0/basic.test.ts +++ b/tests/spec/enums-2.0/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("enums-2.0", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, extractRequestParams: true, diff --git a/tests/spec/extractRequestBody/basic.test.ts b/tests/spec/extractRequestBody/basic.test.ts index 734bd017..c32859c0 100644 --- a/tests/spec/extractRequestBody/basic.test.ts +++ b/tests/spec/extractRequestBody/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--extract-request-body", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, extractRequestBody: true, diff --git a/tests/spec/extractRequestParams/basic.test.ts b/tests/spec/extractRequestParams/basic.test.ts index 130efc36..7391363b 100644 --- a/tests/spec/extractRequestParams/basic.test.ts +++ b/tests/spec/extractRequestParams/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--extract-request-params", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, extractRequestParams: true, diff --git a/tests/spec/extractResponseBody/basic.test.ts b/tests/spec/extractResponseBody/basic.test.ts index 049e4313..0df652ce 100644 --- a/tests/spec/extractResponseBody/basic.test.ts +++ b/tests/spec/extractResponseBody/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--extract-response-body", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, extractResponseBody: true, diff --git a/tests/spec/extractResponseError/basic.test.ts b/tests/spec/extractResponseError/basic.test.ts index 0d6e2355..0ff2cfee 100644 --- a/tests/spec/extractResponseError/basic.test.ts +++ b/tests/spec/extractResponseError/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--extract-response-body", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, extractResponseError: true, diff --git a/tests/spec/js/basic.test.ts b/tests/spec/js/basic.test.ts index b3cd3c71..899bda46 100644 --- a/tests/spec/js/basic.test.ts +++ b/tests/spec/js/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--js --axios", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, httpClientType: "axios", diff --git a/tests/spec/jsAxios/basic.test.ts b/tests/spec/jsAxios/basic.test.ts index 9249436d..0253f844 100644 --- a/tests/spec/jsAxios/basic.test.ts +++ b/tests/spec/jsAxios/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--js", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, toJS: true, diff --git a/tests/spec/moduleNameFirstTag/basic.test.ts b/tests/spec/moduleNameFirstTag/basic.test.ts index 5557663b..5c0f2956 100644 --- a/tests/spec/moduleNameFirstTag/basic.test.ts +++ b/tests/spec/moduleNameFirstTag/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--module-name-first-tag", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, moduleNameFirstTag: true, diff --git a/tests/spec/moduleNameIndex/basic.test.ts b/tests/spec/moduleNameIndex/basic.test.ts index ff6fca74..4e0716c9 100644 --- a/tests/spec/moduleNameIndex/basic.test.ts +++ b/tests/spec/moduleNameIndex/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--module-name-index", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, moduleNameIndex: 2, diff --git a/tests/spec/noClient/basic.test.ts b/tests/spec/noClient/basic.test.ts index f0b2bb52..f3e8f166 100644 --- a/tests/spec/noClient/basic.test.ts +++ b/tests/spec/noClient/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--no-client", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, generateClient: false, diff --git a/tests/spec/nullable-2.0/basic.test.ts b/tests/spec/nullable-2.0/basic.test.ts index 4c48503c..446de19f 100644 --- a/tests/spec/nullable-2.0/basic.test.ts +++ b/tests/spec/nullable-2.0/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("nullable-2.0 refs", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, addReadonly: true, diff --git a/tests/spec/nullable-3.0/basic.test.ts b/tests/spec/nullable-3.0/basic.test.ts index 72a29798..5a755ded 100644 --- a/tests/spec/nullable-3.0/basic.test.ts +++ b/tests/spec/nullable-3.0/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("nullable-3.0 refs", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, addReadonly: true, diff --git a/tests/spec/object-types/basic.test.ts b/tests/spec/object-types/basic.test.ts index 42554a9b..bfa60a76 100644 --- a/tests/spec/object-types/basic.test.ts +++ b/tests/spec/object-types/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("object-types", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, addReadonly: true, diff --git a/tests/spec/on-insert-path-param/basic.test.ts b/tests/spec/on-insert-path-param/basic.test.ts index c21d6ab7..f2612c4a 100644 --- a/tests/spec/on-insert-path-param/basic.test.ts +++ b/tests/spec/on-insert-path-param/basic.test.ts @@ -18,15 +18,13 @@ describe("basic", async () => { }); test("on-insert-path-param", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, generateClient: true, hooks: { - // @ts-expect-error onInsertPathParam: (paramName) => `encodeURIComponent(${paramName})`, }, }); diff --git a/tests/spec/patch/basic.test.ts b/tests/spec/patch/basic.test.ts index ef7bdf81..49f66697 100644 --- a/tests/spec/patch/basic.test.ts +++ b/tests/spec/patch/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--patch", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, patch: true, diff --git a/tests/spec/readonly/basic.test.ts b/tests/spec/readonly/basic.test.ts index c40e53a1..ee2be8ca 100644 --- a/tests/spec/readonly/basic.test.ts +++ b/tests/spec/readonly/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("readonly", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, addReadonly: true, diff --git a/tests/spec/responses/basic.test.ts b/tests/spec/responses/basic.test.ts index 94072d3a..14fa2cb1 100644 --- a/tests/spec/responses/basic.test.ts +++ b/tests/spec/responses/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("responses", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, generateResponses: true, diff --git a/tests/spec/routeTypes/basic.test.ts b/tests/spec/routeTypes/basic.test.ts index 8db09064..0226aad5 100644 --- a/tests/spec/routeTypes/basic.test.ts +++ b/tests/spec/routeTypes/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--route-types", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, generateClient: false, diff --git a/tests/spec/singleHttpClient/basic.test.ts b/tests/spec/singleHttpClient/basic.test.ts index e45e3070..1ea7f76b 100644 --- a/tests/spec/singleHttpClient/basic.test.ts +++ b/tests/spec/singleHttpClient/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--single-http-client", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, singleHttpClient: true, diff --git a/tests/spec/sortTypes-false/basic.test.ts b/tests/spec/sortTypes-false/basic.test.ts index ec1ff172..246aeedd 100644 --- a/tests/spec/sortTypes-false/basic.test.ts +++ b/tests/spec/sortTypes-false/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--sort-types=false", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, generateClient: true, diff --git a/tests/spec/sortTypes/basic.test.ts b/tests/spec/sortTypes/basic.test.ts index 3c858b04..0de7eedf 100644 --- a/tests/spec/sortTypes/basic.test.ts +++ b/tests/spec/sortTypes/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--sort-types", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, generateClient: true, diff --git a/tests/spec/specProperty/basic.test.ts b/tests/spec/specProperty/basic.test.ts index 74529555..cdcf98a4 100644 --- a/tests/spec/specProperty/basic.test.ts +++ b/tests/spec/specProperty/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("specProperty", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, generateClient: false, diff --git a/tests/spec/typeSuffixPrefix/basic.test.ts b/tests/spec/typeSuffixPrefix/basic.test.ts index 7af2c2b2..511bb319 100644 --- a/tests/spec/typeSuffixPrefix/basic.test.ts +++ b/tests/spec/typeSuffixPrefix/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--type-prefix and --type-suffix", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, generateClient: true, diff --git a/tests/spec/unionEnums/basic.test.ts b/tests/spec/unionEnums/basic.test.ts index 4e3d40dd..986e2e37 100644 --- a/tests/spec/unionEnums/basic.test.ts +++ b/tests/spec/unionEnums/basic.test.ts @@ -18,10 +18,9 @@ describe("basic", async () => { }); test("--union-enums", async () => { - // @ts-expect-error await generateApi({ name: "schema", - input: path.resolve(__dirname, "schema.json"), + input: path.resolve(import.meta.dirname, "schema.json"), output: tmpdir, silent: true, generateUnionEnums: true, diff --git a/tests/utils.ts b/tests/utils.ts index b17957fb..3178ec1a 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -3,7 +3,7 @@ import * as path from "node:path"; export async function collectAllSchemas() { const schemas = []; - const schemaPath = path.join(__dirname, "fixtures", "schemas"); + const schemaPath = path.join(import.meta.dirname, "fixtures", "schemas"); const schemaFiles = await fs.readdir(schemaPath, { recursive: true }); for (const schemaFile of schemaFiles) { if ( diff --git a/tsconfig.json b/tsconfig.json index aebd35a2..e8862870 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,9 @@ { + "extends": ["@tsconfig/strictest", "@tsconfig/node18"], "compilerOptions": { - "allowJs": true, + "checkJs": false, "noEmit": true, - "noEmitOnError": true, - "noImplicitAny": true, - "strict": true + "noPropertyAccessFromIndexSignature": false, + "resolveJsonModule": true } } diff --git a/vitest.config.mts b/vitest.config.ts similarity index 100% rename from vitest.config.mts rename to vitest.config.ts diff --git a/yarn.lock b/yarn.lock index 70fc80b1..c1286a7d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -478,6 +478,20 @@ __metadata: languageName: node linkType: hard +"@tsconfig/node18@npm:18.2.4": + version: 18.2.4 + resolution: "@tsconfig/node18@npm:18.2.4" + checksum: 10c0/cdfd17f212660374eb2765cd5907b2252e43cfa2623cd52307a49f004327ef49bbe7d53c78b0aca57f33e9a5cb0d7d2eb5ded9be1235e6212f65c9f0699322b6 + languageName: node + linkType: hard + +"@tsconfig/strictest@npm:2.0.5": + version: 2.0.5 + resolution: "@tsconfig/strictest@npm:2.0.5" + checksum: 10c0/cfc86da2d57f7b4b0827701b132c37a4974284e5c40649656c0e474866dfd8a69f57c6718230d8a8139967e2a95438586b8224c13ab0ff9d3a43eda771c50cc4 + languageName: node + linkType: hard + "@types/didyoumean@npm:1.2.2": version: 1.2.2 resolution: "@types/didyoumean@npm:1.2.2" @@ -2566,6 +2580,8 @@ __metadata: resolution: "swagger-typescript-api@workspace:." dependencies: "@biomejs/biome": "npm:1.8.2" + "@tsconfig/node18": "npm:18.2.4" + "@tsconfig/strictest": "npm:2.0.5" "@types/didyoumean": "npm:1.2.2" "@types/js-yaml": "npm:4.0.9" "@types/lodash": "npm:4.17.5"