diff --git a/.eslintrc b/.eslintrc index 52996b74bd..9ac4ab7223 100644 --- a/.eslintrc +++ b/.eslintrc @@ -6,7 +6,8 @@ "security", "github", "jest", - "prettier" + "prettier", + "unused-imports" ], "extends": [ "eslint:recommended", @@ -55,7 +56,7 @@ "no-empty-character-class": 2, "no-self-compare": 2, "valid-typeof": 2, - "no-unused-vars": 0, + "unused-imports/no-unused-imports": 2, "handle-callback-err": 2, "no-shadow-restricted-names": 2, "no-new-require": 2, @@ -138,7 +139,6 @@ "prefer-const": 2, "prefer-spread": 2, "prefer-template": 2, - "@typescript-eslint/no-unused-vars": 2, "prettier/prettier": 2, "sonarjs/no-identical-functions": "off", "sonarjs/prefer-single-boolean-return": "off", diff --git a/docs/migrations/version-2-to-3.md b/docs/migrations/version-2-to-3.md index e37f882a08..f0ffd6093d 100644 --- a/docs/migrations/version-2-to-3.md +++ b/docs/migrations/version-2-to-3.md @@ -282,3 +282,13 @@ Is not affected by this change. ### C++ Is not affected by this change. + +### Options in constraints + +As part of https://github.com/asyncapi/modelina/issues/1475 we had the need to access options in the constraint logic, therefore all constraints now have direct access to the provided options. + +To make it easier we now expose types for each of the constraints in each language to make it easier to re-use in TS integrations. They can be accessed as following: + +```ts +import { ConstantConstraint, EnumKeyConstraint, EnumValueConstraint, ModelNameConstraint, PropertyKeyConstraint } from @asyncapi/modelina +``` diff --git a/examples/overwrite-default-constraint/__snapshots__/index.spec.ts.snap b/examples/overwrite-default-constraint/__snapshots__/index.spec.ts.snap index efdd393efc..3c342c2d0b 100644 --- a/examples/overwrite-default-constraint/__snapshots__/index.spec.ts.snap +++ b/examples/overwrite-default-constraint/__snapshots__/index.spec.ts.snap @@ -3,16 +3,16 @@ exports[`Should be able to render models with custom constrain logic and should log expected output to console 1`] = ` Array [ "class MyOwnCustomModelName { - private _email?: string; + private _MyCustomPropertyKey?: string; constructor(input: { - email?: string, + MyCustomPropertyKey?: string, }) { - this._email = input.email; + this._MyCustomPropertyKey = input.MyCustomPropertyKey; } - get email(): string | undefined { return this._email; } - set email(email: string | undefined) { this._email = email; } + get MyCustomPropertyKey(): string | undefined { return this._MyCustomPropertyKey; } + set MyCustomPropertyKey(MyCustomPropertyKey: string | undefined) { this._MyCustomPropertyKey = MyCustomPropertyKey; } }", ] `; diff --git a/examples/overwrite-default-constraint/index.ts b/examples/overwrite-default-constraint/index.ts index 71c9258a4b..4cab0b0ca6 100644 --- a/examples/overwrite-default-constraint/index.ts +++ b/examples/overwrite-default-constraint/index.ts @@ -1,10 +1,27 @@ import { TypeScriptGenerator } from '../../src'; -import { pascalCase } from 'change-case'; const generator = new TypeScriptGenerator({ constraints: { - modelName: ({ modelName }) => { + modelName: ({ modelName, options }) => { return 'MyOwnCustomModelName'; + }, + constant: ({ constrainedMetaModel, options }) => { + return 'MyCustomConst'; + }, + enumKey: ({ constrainedEnumModel, enumKey, enumModel, options }) => { + return 'MyCustomKey'; + }, + enumValue: ({ constrainedEnumModel, enumValue, enumModel, options }) => { + return 'MyCustomValue'; + }, + propertyKey: ({ + constrainedObjectModel, + constrainedObjectPropertyModel, + objectModel, + objectPropertyModel, + options + }) => { + return 'MyCustomPropertyKey'; } } }); diff --git a/package-lock.json b/package-lock.json index 4d47b56f2b..489502707f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,6 +36,7 @@ "eslint-plugin-prettier": "^5.0.1", "eslint-plugin-security": "^1.7.1", "eslint-plugin-sonarjs": "^0.19.0", + "eslint-plugin-unused-imports": "^3.0.0", "jest": "^27.2.5", "markdown-toc": "^1.2.0", "ts-jest": "^27.0.5", diff --git a/package.json b/package.json index acb35dfe92..f4e0261923 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,8 @@ "dependencies": { "@apidevtools/json-schema-ref-parser": "^9.0.9", "@apidevtools/swagger-parser": "^10.0.3", - "@smoya/multi-parser": "^4.0.0", "@asyncapi/parser": "3.0.0-next-major-spec.8", + "@smoya/multi-parser": "^4.0.0", "@swc/core": "^1.3.5", "@swc/jest": "^0.2.23", "@types/node": "^20.3.3", @@ -62,6 +62,7 @@ "eslint-plugin-prettier": "^5.0.1", "eslint-plugin-security": "^1.7.1", "eslint-plugin-sonarjs": "^0.19.0", + "eslint-plugin-unused-imports": "^3.0.0", "jest": "^27.2.5", "markdown-toc": "^1.2.0", "ts-jest": "^27.0.5", diff --git a/src/generators/cplusplus/CplusplusGenerator.ts b/src/generators/cplusplus/CplusplusGenerator.ts index 77654d8e24..9cc74b9da3 100644 --- a/src/generators/cplusplus/CplusplusGenerator.ts +++ b/src/generators/cplusplus/CplusplusGenerator.ts @@ -20,8 +20,13 @@ import { EnumRenderer } from './renderers/EnumRenderer'; import { isReservedCplusplusKeyword } from './Constants'; import { Logger } from '../..'; import { + ConstantConstraint, constrainMetaModel, - Constraints + Constraints, + EnumKeyConstraint, + EnumValueConstraint, + ModelNameConstraint, + PropertyKeyConstraint } from '../../helpers/ConstrainHelpers'; import { CplusplusDefaultConstraints, @@ -33,9 +38,18 @@ import { CplusplusDependencyManager } from './CplusplusDependencyManager'; export interface CplusplusOptions extends CommonGeneratorOptions { typeMapping: TypeMapping; - constraints: Constraints; + constraints: Constraints; namespace: string; } +export type CplusplusConstantConstraint = ConstantConstraint; +export type CplusplusEnumKeyConstraint = EnumKeyConstraint; +export type CplusplusEnumValueConstraint = + EnumValueConstraint; +export type CplusplusModelNameConstraint = + ModelNameConstraint; +export type CplusplusPropertyKeyConstraint = + PropertyKeyConstraint; + // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface CplusplusRenderCompleteModelOptions {} export class CplusplusGenerator extends AbstractGenerator< diff --git a/src/generators/cplusplus/constrainer/ConstantConstrainer.ts b/src/generators/cplusplus/constrainer/ConstantConstrainer.ts index 2c076ad46d..571f14be90 100644 --- a/src/generators/cplusplus/constrainer/ConstantConstrainer.ts +++ b/src/generators/cplusplus/constrainer/ConstantConstrainer.ts @@ -1,6 +1,7 @@ import { ConstantConstraint } from '../../../helpers'; +import { CplusplusOptions } from '../CplusplusGenerator'; -export function defaultConstantConstraints(): ConstantConstraint { +export function defaultConstantConstraints(): ConstantConstraint { return () => { return undefined; }; diff --git a/src/generators/cplusplus/constrainer/EnumConstrainer.ts b/src/generators/cplusplus/constrainer/EnumConstrainer.ts index 63852d5da5..f6a122fe05 100644 --- a/src/generators/cplusplus/constrainer/EnumConstrainer.ts +++ b/src/generators/cplusplus/constrainer/EnumConstrainer.ts @@ -6,12 +6,12 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { - FormatHelpers, - EnumKeyConstraint, - EnumValueConstraint -} from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedCplusplusKeyword } from '../Constants'; +import { + CplusplusEnumKeyConstraint, + CplusplusEnumValueConstraint +} from '../CplusplusGenerator'; export type ModelEnumKeyConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -50,7 +50,7 @@ export const DefaultEnumKeyConstraints: ModelEnumKeyConstraints = { */ export function defaultEnumKeyConstraints( customConstraints?: Partial -): EnumKeyConstraint { +): CplusplusEnumKeyConstraint { const constraints = { ...DefaultEnumKeyConstraints, ...customConstraints }; return ({ enumKey, enumModel, constrainedEnumModel }) => { @@ -76,7 +76,7 @@ export function defaultEnumKeyConstraints( /** * Convert the enum value to a value that is compatible with Cplusplus */ -export function defaultEnumValueConstraints(): EnumValueConstraint { +export function defaultEnumValueConstraints(): CplusplusEnumValueConstraint { return ({ enumValue }) => { let constrainedEnumValue; switch (typeof enumValue) { diff --git a/src/generators/cplusplus/constrainer/ModelNameConstrainer.ts b/src/generators/cplusplus/constrainer/ModelNameConstrainer.ts index 8538f20dd7..a9d262f454 100644 --- a/src/generators/cplusplus/constrainer/ModelNameConstrainer.ts +++ b/src/generators/cplusplus/constrainer/ModelNameConstrainer.ts @@ -3,8 +3,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, ModelNameConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedCplusplusKeyword } from '../Constants'; +import { CplusplusModelNameConstraint } from '../CplusplusGenerator'; export type ModelNameConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -36,7 +37,7 @@ export const DefaultModelNameConstraints: ModelNameConstraints = { */ export function defaultModelNameConstraints( customConstraints?: Partial -): ModelNameConstraint { +): CplusplusModelNameConstraint { const constraints = { ...DefaultModelNameConstraints, ...customConstraints }; return ({ modelName }) => { diff --git a/src/generators/cplusplus/constrainer/PropertyKeyConstrainer.ts b/src/generators/cplusplus/constrainer/PropertyKeyConstrainer.ts index 427170e803..8c71619bd4 100644 --- a/src/generators/cplusplus/constrainer/PropertyKeyConstrainer.ts +++ b/src/generators/cplusplus/constrainer/PropertyKeyConstrainer.ts @@ -4,8 +4,9 @@ import { NO_DUPLICATE_PROPERTIES, NO_EMPTY_VALUE } from '../../../helpers/Constraints'; -import { FormatHelpers, PropertyKeyConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedCplusplusKeyword } from '../Constants'; +import { CplusplusPropertyKeyConstraint } from '../CplusplusGenerator'; export type PropertyKeyConstraintOptions = { NO_SPECIAL_CHAR: (value: string) => string; @@ -46,7 +47,7 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = { */ export function defaultPropertyKeyConstraints( customConstraints?: Partial -): PropertyKeyConstraint { +): CplusplusPropertyKeyConstraint { const constraints = { ...DefaultPropertyKeyConstraints, ...customConstraints diff --git a/src/generators/csharp/CSharpConstrainer.ts b/src/generators/csharp/CSharpConstrainer.ts index 912dcc08fa..e8b7301156 100644 --- a/src/generators/csharp/CSharpConstrainer.ts +++ b/src/generators/csharp/CSharpConstrainer.ts @@ -1,4 +1,3 @@ -import { Constraints } from '../../helpers'; import { ConstrainedEnumValueModel, ConstrainedObjectPropertyModel @@ -113,7 +112,7 @@ export const CSharpDefaultTypeMapping: CSharpTypeMapping = { } }; -export const CSharpDefaultConstraints: Constraints = { +export const CSharpDefaultConstraints = { enumKey: defaultEnumKeyConstraints(), enumValue: defaultEnumValueConstraints(), modelName: defaultModelNameConstraints(), diff --git a/src/generators/csharp/CSharpGenerator.ts b/src/generators/csharp/CSharpGenerator.ts index 39d14f7c2e..add9bab4ec 100644 --- a/src/generators/csharp/CSharpGenerator.ts +++ b/src/generators/csharp/CSharpGenerator.ts @@ -19,7 +19,12 @@ import { Constraints, constrainMetaModel, split, - SplitOptions + SplitOptions, + ConstantConstraint, + EnumKeyConstraint, + EnumValueConstraint, + ModelNameConstraint, + PropertyKeyConstraint } from '../../helpers'; import { CSharpPreset, CSHARP_DEFAULT_PRESET } from './CSharpPreset'; import { EnumRenderer } from './renderers/EnumRenderer'; @@ -37,11 +42,16 @@ import { CSharpDependencyManager } from './CSharpDependencyManager'; export interface CSharpOptions extends CommonGeneratorOptions { collectionType: 'List' | 'Array'; typeMapping: TypeMapping; - constraints: Constraints; + constraints: Constraints; autoImplementedProperties: boolean; modelType: 'class' | 'record'; handleNullable: boolean; } +export type CSharpConstantConstraint = ConstantConstraint; +export type CSharpEnumKeyConstraint = EnumKeyConstraint; +export type CSharpEnumValueConstraint = EnumValueConstraint; +export type CSharpModelNameConstraint = ModelNameConstraint; +export type CSharpPropertyKeyConstraint = PropertyKeyConstraint; export type CSharpTypeMapping = TypeMapping< CSharpOptions, CSharpDependencyManager diff --git a/src/generators/csharp/constrainer/ConstantConstrainer.ts b/src/generators/csharp/constrainer/ConstantConstrainer.ts index 2c076ad46d..797006c4ec 100644 --- a/src/generators/csharp/constrainer/ConstantConstrainer.ts +++ b/src/generators/csharp/constrainer/ConstantConstrainer.ts @@ -1,6 +1,6 @@ -import { ConstantConstraint } from '../../../helpers'; +import { CSharpConstantConstraint } from '../CSharpGenerator'; -export function defaultConstantConstraints(): ConstantConstraint { +export function defaultConstantConstraints(): CSharpConstantConstraint { return () => { return undefined; }; diff --git a/src/generators/csharp/constrainer/EnumConstrainer.ts b/src/generators/csharp/constrainer/EnumConstrainer.ts index fa22cc1a75..2b808a9527 100644 --- a/src/generators/csharp/constrainer/EnumConstrainer.ts +++ b/src/generators/csharp/constrainer/EnumConstrainer.ts @@ -5,12 +5,12 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { - EnumKeyConstraint, - EnumValueConstraint, - FormatHelpers -} from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedCSharpKeyword } from '../Constants'; +import { + CSharpEnumKeyConstraint, + CSharpEnumValueConstraint +} from '../CSharpGenerator'; export type ModelEnumKeyConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -49,7 +49,7 @@ export const DefaultEnumKeyConstraints: ModelEnumKeyConstraints = { export function defaultEnumKeyConstraints( customConstraints?: Partial -): EnumKeyConstraint { +): CSharpEnumKeyConstraint { const constraints = { ...DefaultEnumKeyConstraints, ...customConstraints }; return ({ enumKey, enumModel, constrainedEnumModel }) => { @@ -72,7 +72,7 @@ export function defaultEnumKeyConstraints( }; } -export function defaultEnumValueConstraints(): EnumValueConstraint { +export function defaultEnumValueConstraints(): CSharpEnumValueConstraint { return ({ enumValue }) => { let normalizedEnumValue; switch (typeof enumValue) { diff --git a/src/generators/csharp/constrainer/ModelNameConstrainer.ts b/src/generators/csharp/constrainer/ModelNameConstrainer.ts index b7a71c1a55..1d704d57fa 100644 --- a/src/generators/csharp/constrainer/ModelNameConstrainer.ts +++ b/src/generators/csharp/constrainer/ModelNameConstrainer.ts @@ -4,8 +4,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, ModelNameConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedCSharpKeyword } from '../Constants'; +import { CSharpModelNameConstraint } from '../CSharpGenerator'; export type ModelNameConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -35,7 +36,7 @@ export const DefaultModelNameConstraints: ModelNameConstraints = { }; export function defaultModelNameConstraints( customConstraints?: Partial -): ModelNameConstraint { +): CSharpModelNameConstraint { const constraints = { ...DefaultModelNameConstraints, ...customConstraints }; return ({ modelName }) => { diff --git a/src/generators/csharp/constrainer/PropertyKeyConstrainer.ts b/src/generators/csharp/constrainer/PropertyKeyConstrainer.ts index 647d4398d8..5bd1ed9651 100644 --- a/src/generators/csharp/constrainer/PropertyKeyConstrainer.ts +++ b/src/generators/csharp/constrainer/PropertyKeyConstrainer.ts @@ -5,8 +5,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, PropertyKeyConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedCSharpKeyword } from '../Constants'; +import { CSharpPropertyKeyConstraint } from '../CSharpGenerator'; export type PropertyKeyConstraintOptions = { NO_SPECIAL_CHAR: (value: string) => string; @@ -51,7 +52,7 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = { export function defaultPropertyKeyConstraints( customConstraints?: Partial -): PropertyKeyConstraint { +): CSharpPropertyKeyConstraint { const constraints = { ...DefaultPropertyKeyConstraints, ...customConstraints diff --git a/src/generators/dart/DartConstrainer.ts b/src/generators/dart/DartConstrainer.ts index cb154fb017..6c1397cf37 100644 --- a/src/generators/dart/DartConstrainer.ts +++ b/src/generators/dart/DartConstrainer.ts @@ -1,4 +1,3 @@ -import { Constraints } from '../../helpers'; import { defaultEnumKeyConstraints, defaultEnumValueConstraints @@ -71,7 +70,7 @@ export const DartDefaultTypeMapping: DartTypeMapping = { } }; -export const DartDefaultConstraints: Constraints = { +export const DartDefaultConstraints = { enumKey: defaultEnumKeyConstraints(), enumValue: defaultEnumValueConstraints(), modelName: defaultModelNameConstraints(), diff --git a/src/generators/dart/DartGenerator.ts b/src/generators/dart/DartGenerator.ts index c924f851ca..08885ba0f5 100644 --- a/src/generators/dart/DartGenerator.ts +++ b/src/generators/dart/DartGenerator.ts @@ -14,8 +14,13 @@ import { InputMetaModel } from '../../models'; import { + ConstantConstraint, constrainMetaModel, Constraints, + EnumKeyConstraint, + EnumValueConstraint, + ModelNameConstraint, + PropertyKeyConstraint, split, SplitOptions, TypeMapping @@ -34,8 +39,13 @@ import { DartDependencyManager } from './DartDependencyManager'; export interface DartOptions extends CommonGeneratorOptions { collectionType?: 'List'; typeMapping: TypeMapping; - constraints: Constraints; + constraints: Constraints; } +export type DartConstantConstraint = ConstantConstraint; +export type DartEnumKeyConstraint = EnumKeyConstraint; +export type DartEnumValueConstraint = EnumValueConstraint; +export type DartModelNameConstraint = ModelNameConstraint; +export type DartPropertyKeyConstraint = PropertyKeyConstraint; export type DartTypeMapping = TypeMapping; export interface DartRenderCompleteModelOptions { diff --git a/src/generators/dart/constrainer/ConstantConstrainer.ts b/src/generators/dart/constrainer/ConstantConstrainer.ts index 2c076ad46d..97938716cf 100644 --- a/src/generators/dart/constrainer/ConstantConstrainer.ts +++ b/src/generators/dart/constrainer/ConstantConstrainer.ts @@ -1,6 +1,6 @@ -import { ConstantConstraint } from '../../../helpers'; +import { DartConstantConstraint } from '../DartGenerator'; -export function defaultConstantConstraints(): ConstantConstraint { +export function defaultConstantConstraints(): DartConstantConstraint { return () => { return undefined; }; diff --git a/src/generators/dart/constrainer/EnumConstrainer.ts b/src/generators/dart/constrainer/EnumConstrainer.ts index 1d27cbe0f8..45ae32c88e 100644 --- a/src/generators/dart/constrainer/EnumConstrainer.ts +++ b/src/generators/dart/constrainer/EnumConstrainer.ts @@ -6,12 +6,12 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { - EnumKeyConstraint, - EnumValueConstraint, - FormatHelpers -} from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedDartKeyword } from '../Constants'; +import { + DartEnumKeyConstraint, + DartEnumValueConstraint +} from '../DartGenerator'; export type ModelEnumKeyConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -45,7 +45,7 @@ export const DefaultEnumKeyConstraints: ModelEnumKeyConstraints = { export function defaultEnumKeyConstraints( customConstraints?: Partial -): EnumKeyConstraint { +): DartEnumKeyConstraint { const constraints = { ...DefaultEnumKeyConstraints, ...customConstraints }; return ({ enumKey, enumModel, constrainedEnumModel }) => { @@ -68,7 +68,7 @@ export function defaultEnumKeyConstraints( }; } -export function defaultEnumValueConstraints(): EnumValueConstraint { +export function defaultEnumValueConstraints(): DartEnumValueConstraint { return ({ enumValue }) => { let constrainedEnumValue = enumValue; switch (typeof enumValue) { diff --git a/src/generators/dart/constrainer/ModelNameConstrainer.ts b/src/generators/dart/constrainer/ModelNameConstrainer.ts index 95acebaad6..c90040be6b 100644 --- a/src/generators/dart/constrainer/ModelNameConstrainer.ts +++ b/src/generators/dart/constrainer/ModelNameConstrainer.ts @@ -4,8 +4,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, ModelNameConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedDartKeyword } from '../Constants'; +import { DartModelNameConstraint } from '../DartGenerator'; export type ModelNameConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -34,7 +35,7 @@ export const DefaultModelNameConstraints: ModelNameConstraints = { export function defaultModelNameConstraints( customConstraints?: Partial -): ModelNameConstraint { +): DartModelNameConstraint { const constraints = { ...DefaultModelNameConstraints, ...customConstraints }; return ({ modelName }) => { diff --git a/src/generators/dart/constrainer/PropertyKeyConstrainer.ts b/src/generators/dart/constrainer/PropertyKeyConstrainer.ts index 6b14ab2452..06abcf4eec 100644 --- a/src/generators/dart/constrainer/PropertyKeyConstrainer.ts +++ b/src/generators/dart/constrainer/PropertyKeyConstrainer.ts @@ -5,8 +5,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, PropertyKeyConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedDartKeyword } from '../Constants'; +import { DartPropertyKeyConstraint } from '../DartGenerator'; export type PropertyKeyConstraintOptions = { NO_SPECIAL_CHAR: (value: string) => string; @@ -42,7 +43,7 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = { export function defaultPropertyKeyConstraints( customConstraints?: Partial -): PropertyKeyConstraint { +): DartPropertyKeyConstraint { const constraints = { ...DefaultPropertyKeyConstraints, ...customConstraints diff --git a/src/generators/go/GoConstrainer.ts b/src/generators/go/GoConstrainer.ts index b04f8cacc6..d634c12577 100644 --- a/src/generators/go/GoConstrainer.ts +++ b/src/generators/go/GoConstrainer.ts @@ -1,4 +1,3 @@ -import { Constraints } from '../../helpers'; import { defaultEnumKeyConstraints, defaultEnumValueConstraints @@ -49,7 +48,7 @@ export const GoDefaultTypeMapping: GoTypeMapping = { } }; -export const GoDefaultConstraints: Constraints = { +export const GoDefaultConstraints = { enumKey: defaultEnumKeyConstraints(), enumValue: defaultEnumValueConstraints(), modelName: defaultModelNameConstraints(), diff --git a/src/generators/go/GoGenerator.ts b/src/generators/go/GoGenerator.ts index 8fc5f5b3d3..12fbf55107 100644 --- a/src/generators/go/GoGenerator.ts +++ b/src/generators/go/GoGenerator.ts @@ -14,8 +14,13 @@ import { MetaModel } from '../../models'; import { + ConstantConstraint, constrainMetaModel, Constraints, + EnumKeyConstraint, + EnumValueConstraint, + ModelNameConstraint, + PropertyKeyConstraint, split, SplitOptions, TypeMapping @@ -30,8 +35,13 @@ import { GoDependencyManager } from './GoDependencyManager'; export interface GoOptions extends CommonGeneratorOptions { typeMapping: TypeMapping; - constraints: Constraints; + constraints: Constraints; } +export type GoConstantConstraint = ConstantConstraint; +export type GoEnumKeyConstraint = EnumKeyConstraint; +export type GoEnumValueConstraint = EnumValueConstraint; +export type GoModelNameConstraint = ModelNameConstraint; +export type GoPropertyKeyConstraint = PropertyKeyConstraint; export type GoTypeMapping = TypeMapping; export interface GoRenderCompleteModelOptions { diff --git a/src/generators/go/constrainer/ConstantConstrainer.ts b/src/generators/go/constrainer/ConstantConstrainer.ts index 2c076ad46d..d841ca4ef6 100644 --- a/src/generators/go/constrainer/ConstantConstrainer.ts +++ b/src/generators/go/constrainer/ConstantConstrainer.ts @@ -1,6 +1,6 @@ -import { ConstantConstraint } from '../../../helpers'; +import { GoConstantConstraint } from '../GoGenerator'; -export function defaultConstantConstraints(): ConstantConstraint { +export function defaultConstantConstraints(): GoConstantConstraint { return () => { return undefined; }; diff --git a/src/generators/go/constrainer/EnumConstrainer.ts b/src/generators/go/constrainer/EnumConstrainer.ts index 6eb0384e9c..c52815e2e7 100644 --- a/src/generators/go/constrainer/EnumConstrainer.ts +++ b/src/generators/go/constrainer/EnumConstrainer.ts @@ -5,12 +5,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { - FormatHelpers, - EnumKeyConstraint, - EnumValueConstraint -} from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedGoKeyword } from '../Constants'; +import { GoEnumKeyConstraint, GoEnumValueConstraint } from '../GoGenerator'; export type ModelEnumKeyConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -48,7 +45,7 @@ export const DefaultEnumKeyConstraints: ModelEnumKeyConstraints = { export function defaultEnumKeyConstraints( customConstraints?: Partial -): EnumKeyConstraint { +): GoEnumKeyConstraint { const constraints = { ...DefaultEnumKeyConstraints, ...customConstraints }; return ({ enumKey, enumModel, constrainedEnumModel }) => { @@ -80,7 +77,7 @@ export function defaultEnumKeyConstraints( }; } -export function defaultEnumValueConstraints(): EnumValueConstraint { +export function defaultEnumValueConstraints(): GoEnumValueConstraint { return ({ enumValue }) => { let constrainedEnumValue: any = JSON.stringify(enumValue); switch (typeof enumValue) { diff --git a/src/generators/go/constrainer/ModelNameConstrainer.ts b/src/generators/go/constrainer/ModelNameConstrainer.ts index 890eba255f..161b41f0dc 100644 --- a/src/generators/go/constrainer/ModelNameConstrainer.ts +++ b/src/generators/go/constrainer/ModelNameConstrainer.ts @@ -3,8 +3,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, ModelNameConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedGoKeyword } from '../Constants'; +import { GoModelNameConstraint } from '../GoGenerator'; export type ModelNameConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -35,7 +36,7 @@ export const DefaultModelNameConstraints: ModelNameConstraints = { export function defaultModelNameConstraints( customConstraints?: Partial -): ModelNameConstraint { +): GoModelNameConstraint { const constraints = { ...DefaultModelNameConstraints, ...customConstraints }; return ({ modelName }) => { diff --git a/src/generators/go/constrainer/PropertyKeyConstrainer.ts b/src/generators/go/constrainer/PropertyKeyConstrainer.ts index bb040de0c7..b7c542f27c 100644 --- a/src/generators/go/constrainer/PropertyKeyConstrainer.ts +++ b/src/generators/go/constrainer/PropertyKeyConstrainer.ts @@ -5,8 +5,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, PropertyKeyConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedGoKeyword } from '../Constants'; +import { GoPropertyKeyConstraint } from '../GoGenerator'; export type PropertyKeyConstraintOptions = { NO_SPECIAL_CHAR: (value: string) => string; @@ -42,7 +43,7 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = { export function defaultPropertyKeyConstraints( customConstraints?: Partial -): PropertyKeyConstraint { +): GoPropertyKeyConstraint { const constraints = { ...DefaultPropertyKeyConstraints, ...customConstraints diff --git a/src/generators/java/JavaConstrainer.ts b/src/generators/java/JavaConstrainer.ts index ca11eca215..fc850c81cb 100644 --- a/src/generators/java/JavaConstrainer.ts +++ b/src/generators/java/JavaConstrainer.ts @@ -1,4 +1,3 @@ -import { Constraints } from '../../helpers'; import { ConstrainedEnumValueModel, ConstrainedMetaModel, @@ -240,7 +239,7 @@ export const JavaDefaultTypeMapping: JavaTypeMapping = { } }; -export const JavaDefaultConstraints: Constraints = { +export const JavaDefaultConstraints = { enumKey: defaultEnumKeyConstraints(), enumValue: defaultEnumValueConstraints(), modelName: defaultModelNameConstraints(), diff --git a/src/generators/java/JavaGenerator.ts b/src/generators/java/JavaGenerator.ts index 00407aed48..c2033ad93d 100644 --- a/src/generators/java/JavaGenerator.ts +++ b/src/generators/java/JavaGenerator.ts @@ -19,7 +19,12 @@ import { SplitOptions, TypeMapping, constrainMetaModel, - Constraints + Constraints, + ConstantConstraint, + EnumKeyConstraint, + EnumValueConstraint, + PropertyKeyConstraint, + ModelNameConstraint } from '../../helpers'; import { JavaPreset, JAVA_DEFAULT_PRESET } from './JavaPreset'; import { ClassRenderer } from './renderers/ClassRenderer'; @@ -38,8 +43,13 @@ import { UnionRenderer } from './renderers/UnionRenderer'; export interface JavaOptions extends CommonGeneratorOptions { collectionType: 'List' | 'Array'; typeMapping: TypeMapping; - constraints: Constraints; + constraints: Constraints; } +export type JavaConstantConstraint = ConstantConstraint; +export type JavaEnumKeyConstraint = EnumKeyConstraint; +export type JavaEnumValueConstraint = EnumValueConstraint; +export type JavaModelNameConstraint = ModelNameConstraint; +export type JavaPropertyKeyConstraint = PropertyKeyConstraint; export type JavaTypeMapping = TypeMapping; export interface JavaRenderCompleteModelOptions { packageName: string; diff --git a/src/generators/java/constrainer/ConstantConstrainer.ts b/src/generators/java/constrainer/ConstantConstrainer.ts index b21eaf5ba6..fc98b58410 100644 --- a/src/generators/java/constrainer/ConstantConstrainer.ts +++ b/src/generators/java/constrainer/ConstantConstrainer.ts @@ -5,8 +5,8 @@ import { ConstrainedReferenceModel, ConstrainedStringModel } from '../../../models'; -import { ConstantConstraint } from '../../../helpers'; import { JavaRenderer } from '../JavaRenderer'; +import { JavaConstantConstraint } from '../JavaGenerator'; const getConstrainedEnumModelConstant = (args: { constrainedMetaModel: ConstrainedMetaModel; @@ -22,7 +22,7 @@ const getConstrainedEnumModelConstant = (args: { } }; -export function defaultConstantConstraints(): ConstantConstraint { +export function defaultConstantConstraints(): JavaConstantConstraint { return ({ constrainedMetaModel }) => { const constOptions = constrainedMetaModel.options.const; diff --git a/src/generators/java/constrainer/EnumConstrainer.ts b/src/generators/java/constrainer/EnumConstrainer.ts index b427be75cd..836683c807 100644 --- a/src/generators/java/constrainer/EnumConstrainer.ts +++ b/src/generators/java/constrainer/EnumConstrainer.ts @@ -6,12 +6,12 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { - FormatHelpers, - EnumKeyConstraint, - EnumValueConstraint -} from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedJavaKeyword } from '../Constants'; +import { + JavaEnumKeyConstraint, + JavaEnumValueConstraint +} from '../JavaGenerator'; export type ModelEnumKeyConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -46,7 +46,7 @@ export const DefaultEnumKeyConstraints: ModelEnumKeyConstraints = { export function defaultEnumKeyConstraints( customConstraints?: Partial -): EnumKeyConstraint { +): JavaEnumKeyConstraint { const constraints = { ...DefaultEnumKeyConstraints, ...customConstraints }; return ({ enumKey, enumModel, constrainedEnumModel }) => { @@ -69,7 +69,7 @@ export function defaultEnumKeyConstraints( }; } -export function defaultEnumValueConstraints(): EnumValueConstraint { +export function defaultEnumValueConstraints(): JavaEnumValueConstraint { return ({ enumValue }) => { let constrainedEnumValue = enumValue; switch (typeof enumValue) { diff --git a/src/generators/java/constrainer/ModelNameConstrainer.ts b/src/generators/java/constrainer/ModelNameConstrainer.ts index 2411c1d15d..2f141ca357 100644 --- a/src/generators/java/constrainer/ModelNameConstrainer.ts +++ b/src/generators/java/constrainer/ModelNameConstrainer.ts @@ -3,8 +3,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, ModelNameConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedJavaKeyword } from '../Constants'; +import { JavaModelNameConstraint } from '../JavaGenerator'; export type ModelNameConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -34,7 +35,7 @@ export const DefaultModelNameConstraints: ModelNameConstraints = { }; export function defaultModelNameConstraints( customConstraints?: Partial -): ModelNameConstraint { +): JavaModelNameConstraint { const constraints = { ...DefaultModelNameConstraints, ...customConstraints }; return ({ modelName }) => { diff --git a/src/generators/java/constrainer/PropertyKeyConstrainer.ts b/src/generators/java/constrainer/PropertyKeyConstrainer.ts index 2301051992..5a3c2d8ffe 100644 --- a/src/generators/java/constrainer/PropertyKeyConstrainer.ts +++ b/src/generators/java/constrainer/PropertyKeyConstrainer.ts @@ -5,8 +5,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, PropertyKeyConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedJavaKeyword } from '../Constants'; +import { JavaPropertyKeyConstraint } from '../JavaGenerator'; export type PropertyKeyConstraintOptions = { NO_SPECIAL_CHAR: (value: string) => string; @@ -42,7 +43,7 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = { export function defaultPropertyKeyConstraints( customConstraints?: Partial -): PropertyKeyConstraint { +): JavaPropertyKeyConstraint { const constraints = { ...DefaultPropertyKeyConstraints, ...customConstraints diff --git a/src/generators/javascript/JavaScriptConstrainer.ts b/src/generators/javascript/JavaScriptConstrainer.ts index 9b579d0048..e8173ad005 100644 --- a/src/generators/javascript/JavaScriptConstrainer.ts +++ b/src/generators/javascript/JavaScriptConstrainer.ts @@ -4,7 +4,6 @@ import { defaultEnumKeyConstraints, defaultEnumValueConstraints } from './constrainer/EnumConstrainer'; -import { Constraints } from '../../helpers'; import { JavaScriptTypeMapping } from './JavaScriptGenerator'; import { defaultConstantConstraints } from './constrainer/ConstantConstrainer'; @@ -47,7 +46,7 @@ export const JavaScriptDefaultTypeMapping: JavaScriptTypeMapping = { } }; -export const JavaScriptDefaultConstraints: Constraints = { +export const JavaScriptDefaultConstraints = { enumKey: defaultEnumKeyConstraints(), enumValue: defaultEnumValueConstraints(), modelName: defaultModelNameConstraints(), diff --git a/src/generators/javascript/JavaScriptGenerator.ts b/src/generators/javascript/JavaScriptGenerator.ts index 84b8d9cd32..c665555347 100644 --- a/src/generators/javascript/JavaScriptGenerator.ts +++ b/src/generators/javascript/JavaScriptGenerator.ts @@ -17,7 +17,12 @@ import { Constraints, split, constrainMetaModel, - SplitOptions + SplitOptions, + ConstantConstraint, + EnumKeyConstraint, + EnumValueConstraint, + ModelNameConstraint, + PropertyKeyConstraint } from '../../helpers'; import { JavaScriptPreset, JS_DEFAULT_PRESET } from './JavaScriptPreset'; import { ClassRenderer } from './renderers/ClassRenderer'; @@ -31,9 +36,18 @@ import { JavaScriptDependencyManager } from './JavaScriptDependencyManager'; export interface JavaScriptOptions extends CommonGeneratorOptions { typeMapping: TypeMapping; - constraints: Constraints; + constraints: Constraints; moduleSystem: 'ESM' | 'CJS'; } +export type JavaScriptConstantConstraint = + ConstantConstraint; +export type JavaScriptEnumKeyConstraint = EnumKeyConstraint; +export type JavaScriptEnumValueConstraint = + EnumValueConstraint; +export type JavaScriptModelNameConstraint = + ModelNameConstraint; +export type JavaScriptPropertyKeyConstraint = + PropertyKeyConstraint; export type JavaScriptTypeMapping = TypeMapping< JavaScriptOptions, JavaScriptDependencyManager diff --git a/src/generators/javascript/constrainer/ConstantConstrainer.ts b/src/generators/javascript/constrainer/ConstantConstrainer.ts index 2c076ad46d..030ca50470 100644 --- a/src/generators/javascript/constrainer/ConstantConstrainer.ts +++ b/src/generators/javascript/constrainer/ConstantConstrainer.ts @@ -1,6 +1,6 @@ -import { ConstantConstraint } from '../../../helpers'; +import { JavaScriptConstantConstraint } from '../JavaScriptGenerator'; -export function defaultConstantConstraints(): ConstantConstraint { +export function defaultConstantConstraints(): JavaScriptConstantConstraint { return () => { return undefined; }; diff --git a/src/generators/javascript/constrainer/EnumConstrainer.ts b/src/generators/javascript/constrainer/EnumConstrainer.ts index 46e230ea69..4f54000627 100644 --- a/src/generators/javascript/constrainer/EnumConstrainer.ts +++ b/src/generators/javascript/constrainer/EnumConstrainer.ts @@ -1,14 +1,17 @@ -import { EnumKeyConstraint, EnumValueConstraint } from '../../../helpers'; +import { + JavaScriptEnumKeyConstraint, + JavaScriptEnumValueConstraint +} from '../JavaScriptGenerator'; /** * Enums for JS do not have any constraints because we never render anything specific for enums. **/ -export function defaultEnumKeyConstraints(): EnumKeyConstraint { +export function defaultEnumKeyConstraints(): JavaScriptEnumKeyConstraint { return ({ enumKey }) => { return enumKey; }; } -export function defaultEnumValueConstraints(): EnumValueConstraint { +export function defaultEnumValueConstraints(): JavaScriptEnumValueConstraint { return ({ enumValue }) => { return enumValue; }; diff --git a/src/generators/javascript/constrainer/ModelNameConstrainer.ts b/src/generators/javascript/constrainer/ModelNameConstrainer.ts index b016689ae9..2551e783d5 100644 --- a/src/generators/javascript/constrainer/ModelNameConstrainer.ts +++ b/src/generators/javascript/constrainer/ModelNameConstrainer.ts @@ -3,8 +3,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, ModelNameConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedJavaScriptKeyword } from '../Constants'; +import { JavaScriptModelNameConstraint } from '../JavaScriptGenerator'; export type ModelNameConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -34,7 +35,7 @@ export const DefaultModelNameConstraints: ModelNameConstraints = { }; export function defaultModelNameConstraints( customConstraints?: Partial -): ModelNameConstraint { +): JavaScriptModelNameConstraint { const constraints = { ...DefaultModelNameConstraints, ...customConstraints }; return ({ modelName }) => { diff --git a/src/generators/javascript/constrainer/PropertyKeyConstrainer.ts b/src/generators/javascript/constrainer/PropertyKeyConstrainer.ts index 5299519ea5..190ab233b7 100644 --- a/src/generators/javascript/constrainer/PropertyKeyConstrainer.ts +++ b/src/generators/javascript/constrainer/PropertyKeyConstrainer.ts @@ -5,8 +5,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, PropertyKeyConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedJavaScriptKeyword } from '../Constants'; +import { JavaScriptPropertyKeyConstraint } from '../JavaScriptGenerator'; export type PropertyKeyConstraintOptions = { NO_SPECIAL_CHAR: (value: string) => string; @@ -42,7 +43,7 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = { export function defaultPropertyKeyConstraints( customConstraints?: Partial -): PropertyKeyConstraint { +): JavaScriptPropertyKeyConstraint { const constraints = { ...DefaultPropertyKeyConstraints, ...customConstraints diff --git a/src/generators/kotlin/KotlinConstrainer.ts b/src/generators/kotlin/KotlinConstrainer.ts index d85d053e0d..686f483460 100644 --- a/src/generators/kotlin/KotlinConstrainer.ts +++ b/src/generators/kotlin/KotlinConstrainer.ts @@ -1,4 +1,3 @@ -import { Constraints } from '../../helpers'; import { ConstrainedEnumValueModel } from '../../models'; import { defaultEnumKeyConstraints, @@ -147,7 +146,7 @@ export const KotlinDefaultTypeMapping: KotlinTypeMapping = { } }; -export const KotlinDefaultConstraints: Constraints = { +export const KotlinDefaultConstraints = { enumKey: defaultEnumKeyConstraints(), enumValue: defaultEnumValueConstraints(), modelName: defaultModelNameConstraints(), diff --git a/src/generators/kotlin/KotlinGenerator.ts b/src/generators/kotlin/KotlinGenerator.ts index c9b5ca1523..bc00a3186a 100644 --- a/src/generators/kotlin/KotlinGenerator.ts +++ b/src/generators/kotlin/KotlinGenerator.ts @@ -20,8 +20,13 @@ import { EnumRenderer } from './renderers/EnumRenderer'; import { isReservedKotlinKeyword } from './Constants'; import { Logger } from '../..'; import { + ConstantConstraint, constrainMetaModel, - Constraints + Constraints, + EnumKeyConstraint, + EnumValueConstraint, + ModelNameConstraint, + PropertyKeyConstraint } from '../../helpers/ConstrainHelpers'; import { KotlinDefaultConstraints, @@ -32,9 +37,14 @@ import { KotlinDependencyManager } from './KotlinDependencyManager'; export interface KotlinOptions extends CommonGeneratorOptions { typeMapping: TypeMapping; - constraints: Constraints; + constraints: Constraints; collectionType: 'List' | 'Array'; } +export type KotlinConstantConstraint = ConstantConstraint; +export type KotlinEnumKeyConstraint = EnumKeyConstraint; +export type KotlinEnumValueConstraint = EnumValueConstraint; +export type KotlinModelNameConstraint = ModelNameConstraint; +export type KotlinPropertyKeyConstraint = PropertyKeyConstraint; export type KotlinTypeMapping = TypeMapping< KotlinOptions, KotlinDependencyManager diff --git a/src/generators/kotlin/constrainer/ConstantConstrainer.ts b/src/generators/kotlin/constrainer/ConstantConstrainer.ts index 2c076ad46d..f6696e95c3 100644 --- a/src/generators/kotlin/constrainer/ConstantConstrainer.ts +++ b/src/generators/kotlin/constrainer/ConstantConstrainer.ts @@ -1,6 +1,6 @@ -import { ConstantConstraint } from '../../../helpers'; +import { KotlinConstantConstraint } from '../KotlinGenerator'; -export function defaultConstantConstraints(): ConstantConstraint { +export function defaultConstantConstraints(): KotlinConstantConstraint { return () => { return undefined; }; diff --git a/src/generators/kotlin/constrainer/EnumConstrainer.ts b/src/generators/kotlin/constrainer/EnumConstrainer.ts index 62bad7b4b3..3cd28d2ea8 100644 --- a/src/generators/kotlin/constrainer/EnumConstrainer.ts +++ b/src/generators/kotlin/constrainer/EnumConstrainer.ts @@ -5,11 +5,13 @@ import { NO_DUPLICATE_ENUM_KEYS, NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS, - FormatHelpers, - EnumKeyConstraint, - EnumValueConstraint + FormatHelpers } from '../../../helpers'; import { isInvalidKotlinEnumKey } from '../Constants'; +import { + KotlinEnumKeyConstraint, + KotlinEnumValueConstraint +} from '../KotlinGenerator'; export type ModelEnumKeyConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -44,7 +46,7 @@ export const DefaultEnumKeyConstraints: ModelEnumKeyConstraints = { export function defaultEnumKeyConstraints( customConstraints?: Partial -): EnumKeyConstraint { +): KotlinEnumKeyConstraint { const constraints = { ...DefaultEnumKeyConstraints, ...customConstraints }; return ({ enumKey, enumModel, constrainedEnumModel }) => { @@ -67,7 +69,7 @@ export function defaultEnumKeyConstraints( }; } -export function defaultEnumValueConstraints(): EnumValueConstraint { +export function defaultEnumValueConstraints(): KotlinEnumValueConstraint { return ({ enumValue }) => { switch (typeof enumValue) { case 'string': diff --git a/src/generators/kotlin/constrainer/ModelNameConstrainer.ts b/src/generators/kotlin/constrainer/ModelNameConstrainer.ts index 6477940ae5..a1ed73a8fc 100644 --- a/src/generators/kotlin/constrainer/ModelNameConstrainer.ts +++ b/src/generators/kotlin/constrainer/ModelNameConstrainer.ts @@ -3,8 +3,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, ModelNameConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedKotlinKeyword } from '../Constants'; +import { KotlinModelNameConstraint } from '../KotlinGenerator'; export type ModelNameConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -35,7 +36,7 @@ export const DefaultModelNameConstraints: ModelNameConstraints = { export function defaultModelNameConstraints( customConstraints?: Partial -): ModelNameConstraint { +): KotlinModelNameConstraint { const constraints = { ...DefaultModelNameConstraints, ...customConstraints }; return ({ modelName }) => { diff --git a/src/generators/kotlin/constrainer/PropertyKeyConstrainer.ts b/src/generators/kotlin/constrainer/PropertyKeyConstrainer.ts index 6ae658ff4c..27733491ba 100644 --- a/src/generators/kotlin/constrainer/PropertyKeyConstrainer.ts +++ b/src/generators/kotlin/constrainer/PropertyKeyConstrainer.ts @@ -5,8 +5,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, PropertyKeyConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedKotlinKeyword } from '../Constants'; +import { KotlinPropertyKeyConstraint } from '../KotlinGenerator'; export type PropertyKeyConstraintOptions = { NO_SPECIAL_CHAR: (value: string) => string; @@ -42,7 +43,7 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = { export function defaultPropertyKeyConstraints( customConstraints?: Partial -): PropertyKeyConstraint { +): KotlinPropertyKeyConstraint { const constraints = { ...DefaultPropertyKeyConstraints, ...customConstraints diff --git a/src/generators/php/PhpGenerator.ts b/src/generators/php/PhpGenerator.ts index 833b9ebfdc..fa19930ab9 100644 --- a/src/generators/php/PhpGenerator.ts +++ b/src/generators/php/PhpGenerator.ts @@ -20,8 +20,13 @@ import { EnumRenderer } from './renderers/EnumRenderer'; import { isReservedPhpKeyword } from './Constants'; import { Logger } from '../..'; import { + ConstantConstraint, constrainMetaModel, - Constraints + Constraints, + EnumKeyConstraint, + EnumValueConstraint, + ModelNameConstraint, + PropertyKeyConstraint } from '../../helpers/ConstrainHelpers'; import { PhpDefaultConstraints, PhpDefaultTypeMapping } from './PhpConstrainer'; import { DeepPartial, mergePartialAndDefault } from '../../utils/Partials'; @@ -29,8 +34,13 @@ import { PhpDependencyManager } from './PhpDependencyManager'; export interface PhpOptions extends CommonGeneratorOptions { typeMapping: TypeMapping; - constraints: Constraints; + constraints: Constraints; } +export type PhpConstantConstraint = ConstantConstraint; +export type PhpEnumKeyConstraint = EnumKeyConstraint; +export type PhpEnumValueConstraint = EnumValueConstraint; +export type PhpModelNameConstraint = ModelNameConstraint; +export type PhpPropertyKeyConstraint = PropertyKeyConstraint; export interface PhpRenderCompleteModelOptions { namespace: string; declareStrictTypes: boolean; diff --git a/src/generators/php/constrainer/ConstantConstrainer.ts b/src/generators/php/constrainer/ConstantConstrainer.ts index 2c076ad46d..25112e2cfe 100644 --- a/src/generators/php/constrainer/ConstantConstrainer.ts +++ b/src/generators/php/constrainer/ConstantConstrainer.ts @@ -1,6 +1,6 @@ -import { ConstantConstraint } from '../../../helpers'; +import { PhpConstantConstraint } from '../PhpGenerator'; -export function defaultConstantConstraints(): ConstantConstraint { +export function defaultConstantConstraints(): PhpConstantConstraint { return () => { return undefined; }; diff --git a/src/generators/php/constrainer/EnumConstrainer.ts b/src/generators/php/constrainer/EnumConstrainer.ts index 49b23bae76..f73be2ff4d 100644 --- a/src/generators/php/constrainer/EnumConstrainer.ts +++ b/src/generators/php/constrainer/EnumConstrainer.ts @@ -6,12 +6,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { - FormatHelpers, - EnumKeyConstraint, - EnumValueConstraint -} from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedPhpKeyword } from '../Constants'; +import { PhpEnumKeyConstraint, PhpEnumValueConstraint } from '../PhpGenerator'; export type ModelEnumKeyConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -50,7 +47,7 @@ export const DefaultEnumKeyConstraints: ModelEnumKeyConstraints = { */ export function defaultEnumKeyConstraints( customConstraints?: Partial -): EnumKeyConstraint { +): PhpEnumKeyConstraint { const constraints = { ...DefaultEnumKeyConstraints, ...customConstraints }; return ({ enumKey, enumModel, constrainedEnumModel }) => { @@ -76,7 +73,7 @@ export function defaultEnumKeyConstraints( /** * Convert the enum value to a value that is compatible with Php */ -export function defaultEnumValueConstraints(): EnumValueConstraint { +export function defaultEnumValueConstraints(): PhpEnumValueConstraint { return ({ enumValue }) => { let constrainedEnumValue = enumValue; switch (typeof enumValue) { diff --git a/src/generators/php/constrainer/ModelNameConstrainer.ts b/src/generators/php/constrainer/ModelNameConstrainer.ts index 004d6b2d10..dab67c12e4 100644 --- a/src/generators/php/constrainer/ModelNameConstrainer.ts +++ b/src/generators/php/constrainer/ModelNameConstrainer.ts @@ -3,8 +3,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, ModelNameConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedPhpKeyword } from '../Constants'; +import { PhpModelNameConstraint } from '../PhpGenerator'; export type ModelNameConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -38,7 +39,7 @@ export const DefaultModelNameConstraints: ModelNameConstraints = { */ export function defaultModelNameConstraints( customConstraints?: Partial -): ModelNameConstraint { +): PhpModelNameConstraint { const constraints = { ...DefaultModelNameConstraints, ...customConstraints }; return ({ modelName }) => { diff --git a/src/generators/php/constrainer/PropertyKeyConstrainer.ts b/src/generators/php/constrainer/PropertyKeyConstrainer.ts index 565b824058..251f6969c2 100644 --- a/src/generators/php/constrainer/PropertyKeyConstrainer.ts +++ b/src/generators/php/constrainer/PropertyKeyConstrainer.ts @@ -5,8 +5,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, PropertyKeyConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedPhpKeyword } from '../Constants'; +import { PhpPropertyKeyConstraint } from '../PhpGenerator'; export type PropertyKeyConstraintOptions = { NO_SPECIAL_CHAR: (value: string) => string; @@ -44,7 +45,7 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = { */ export function defaultPropertyKeyConstraints( customConstraints?: Partial -): PropertyKeyConstraint { +): PhpPropertyKeyConstraint { const constraints = { ...DefaultPropertyKeyConstraints, ...customConstraints diff --git a/src/generators/python/PythonConstrainer.ts b/src/generators/python/PythonConstrainer.ts index e1328c3ac4..26ff8aea7a 100644 --- a/src/generators/python/PythonConstrainer.ts +++ b/src/generators/python/PythonConstrainer.ts @@ -6,7 +6,7 @@ import { import { defaultModelNameConstraints } from './constrainer/ModelNameConstrainer'; import { defaultPropertyKeyConstraints } from './constrainer/PropertyKeyConstrainer'; import { defaultConstantConstraints } from './constrainer/ConstantConstrainer'; -import { PythonTypeMapping } from './PythonGenerator'; +import { PythonOptions, PythonTypeMapping } from './PythonGenerator'; export const PythonDefaultTypeMapping: PythonTypeMapping = { Object({ constrainedModel }): string { @@ -55,7 +55,7 @@ export const PythonDefaultTypeMapping: PythonTypeMapping = { } }; -export const PythonDefaultConstraints: Constraints = { +export const PythonDefaultConstraints: Constraints = { enumKey: defaultEnumKeyConstraints(), enumValue: defaultEnumValueConstraints(), modelName: defaultModelNameConstraints(), diff --git a/src/generators/python/PythonGenerator.ts b/src/generators/python/PythonGenerator.ts index 2d20bd0e5f..f517d1b05d 100644 --- a/src/generators/python/PythonGenerator.ts +++ b/src/generators/python/PythonGenerator.ts @@ -20,8 +20,13 @@ import { ClassRenderer } from './renderers/ClassRenderer'; import { EnumRenderer } from './renderers/EnumRenderer'; import { Logger } from '../..'; import { + ConstantConstraint, constrainMetaModel, - Constraints + Constraints, + EnumKeyConstraint, + EnumValueConstraint, + ModelNameConstraint, + PropertyKeyConstraint } from '../../helpers/ConstrainHelpers'; import { PythonDefaultConstraints, @@ -32,9 +37,14 @@ import { PythonDependencyManager } from './PythonDependencyManager'; export interface PythonOptions extends CommonGeneratorOptions { typeMapping: TypeMapping; - constraints: Constraints; + constraints: Constraints; importsStyle: 'explicit' | 'implicit'; } +export type PythonConstantConstraint = ConstantConstraint; +export type PythonEnumKeyConstraint = EnumKeyConstraint; +export type PythonEnumValueConstraint = EnumValueConstraint; +export type PythonModelNameConstraint = ModelNameConstraint; +export type PythonPropertyKeyConstraint = PropertyKeyConstraint; export type PythonTypeMapping = TypeMapping< PythonOptions, PythonDependencyManager diff --git a/src/generators/python/constrainer/ConstantConstrainer.ts b/src/generators/python/constrainer/ConstantConstrainer.ts index 2c076ad46d..44bd50358d 100644 --- a/src/generators/python/constrainer/ConstantConstrainer.ts +++ b/src/generators/python/constrainer/ConstantConstrainer.ts @@ -1,6 +1,6 @@ -import { ConstantConstraint } from '../../../helpers'; +import { PythonConstantConstraint } from '../PythonGenerator'; -export function defaultConstantConstraints(): ConstantConstraint { +export function defaultConstantConstraints(): PythonConstantConstraint { return () => { return undefined; }; diff --git a/src/generators/python/constrainer/EnumConstrainer.ts b/src/generators/python/constrainer/EnumConstrainer.ts index c6ed1b4ef2..877ad876d4 100644 --- a/src/generators/python/constrainer/EnumConstrainer.ts +++ b/src/generators/python/constrainer/EnumConstrainer.ts @@ -6,12 +6,12 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { - FormatHelpers, - EnumKeyConstraint, - EnumValueConstraint -} from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedPythonKeyword } from '../Constants'; +import { + PythonEnumKeyConstraint, + PythonEnumValueConstraint +} from '../PythonGenerator'; export type ModelEnumKeyConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -50,7 +50,7 @@ export const DefaultEnumKeyConstraints: ModelEnumKeyConstraints = { */ export function defaultEnumKeyConstraints( customConstraints?: Partial -): EnumKeyConstraint { +): PythonEnumKeyConstraint { const constraints = { ...DefaultEnumKeyConstraints, ...customConstraints }; return ({ enumKey, enumModel, constrainedEnumModel }) => { @@ -76,7 +76,7 @@ export function defaultEnumKeyConstraints( /** * Convert the enum value to a value that is compatible with Python */ -export function defaultEnumValueConstraints(): EnumValueConstraint { +export function defaultEnumValueConstraints(): PythonEnumValueConstraint { return ({ enumValue }) => { let constrainedEnumValue = enumValue; switch (typeof enumValue) { diff --git a/src/generators/python/constrainer/ModelNameConstrainer.ts b/src/generators/python/constrainer/ModelNameConstrainer.ts index 42e9ac994f..31c940e701 100644 --- a/src/generators/python/constrainer/ModelNameConstrainer.ts +++ b/src/generators/python/constrainer/ModelNameConstrainer.ts @@ -3,8 +3,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, ModelNameConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedPythonKeyword } from '../Constants'; +import { PythonModelNameConstraint } from '../PythonGenerator'; export type ModelNameConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -38,7 +39,7 @@ export const DefaultModelNameConstraints: ModelNameConstraints = { */ export function defaultModelNameConstraints( customConstraints?: Partial -): ModelNameConstraint { +): PythonModelNameConstraint { const constraints = { ...DefaultModelNameConstraints, ...customConstraints }; return ({ modelName }) => { diff --git a/src/generators/python/constrainer/PropertyKeyConstrainer.ts b/src/generators/python/constrainer/PropertyKeyConstrainer.ts index 93e01576a6..c86f4d8223 100644 --- a/src/generators/python/constrainer/PropertyKeyConstrainer.ts +++ b/src/generators/python/constrainer/PropertyKeyConstrainer.ts @@ -5,8 +5,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, PropertyKeyConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedPythonKeyword } from '../Constants'; +import { PythonPropertyKeyConstraint } from '../PythonGenerator'; export type PropertyKeyConstraintOptions = { NO_SPECIAL_CHAR: (value: string) => string; @@ -44,7 +45,7 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = { */ export function defaultPropertyKeyConstraints( customConstraints?: Partial -): PropertyKeyConstraint { +): PythonPropertyKeyConstraint { const constraints = { ...DefaultPropertyKeyConstraints, ...customConstraints diff --git a/src/generators/rust/RustConstrainer.ts b/src/generators/rust/RustConstrainer.ts index 8253d11030..735dbcd0f4 100644 --- a/src/generators/rust/RustConstrainer.ts +++ b/src/generators/rust/RustConstrainer.ts @@ -5,7 +5,7 @@ import { import { defaultModelNameConstraints } from './constrainer/ModelNameConstrainer'; import { defaultPropertyKeyConstraints } from './constrainer/PropertyKeyConstrainer'; import { RustTypeMapping } from './RustGenerator'; -import { FormatHelpers, Constraints } from '../../helpers'; +import { FormatHelpers } from '../../helpers'; import { ConstrainedAnyModel, ConstrainedArrayModel, @@ -345,7 +345,7 @@ export const RustDefaultTypeMapping: RustTypeMapping = { } }; -export const RustDefaultConstraints: Constraints = { +export const RustDefaultConstraints = { enumKey: defaultEnumKeyConstraints(), enumValue: defaultEnumValueConstraints(), modelName: defaultModelNameConstraints(), diff --git a/src/generators/rust/RustGenerator.ts b/src/generators/rust/RustGenerator.ts index c979bebbaa..14d743e4da 100644 --- a/src/generators/rust/RustGenerator.ts +++ b/src/generators/rust/RustGenerator.ts @@ -17,9 +17,14 @@ import { ConstrainedUnionModel } from '../../models'; import { + ConstantConstraint, constrainMetaModel, Constraints, + EnumKeyConstraint, + EnumValueConstraint, IndentationTypes, + ModelNameConstraint, + PropertyKeyConstraint, split, SplitOptions, TypeMapping @@ -40,8 +45,13 @@ import { RustDependencyManager } from './RustDependencyManager'; export interface RustOptions extends CommonGeneratorOptions { typeMapping: TypeMapping; - constraints: Constraints; + constraints: Constraints; } +export type RustConstantConstraint = ConstantConstraint; +export type RustEnumKeyConstraint = EnumKeyConstraint; +export type RustEnumValueConstraint = EnumValueConstraint; +export type RustModelNameConstraint = ModelNameConstraint; +export type RustPropertyKeyConstraint = PropertyKeyConstraint; export type RustTypeMapping = TypeMapping; export enum RustPackageFeatures { diff --git a/src/generators/rust/constrainer/ConstantConstrainer.ts b/src/generators/rust/constrainer/ConstantConstrainer.ts index 2c076ad46d..16875bdf9c 100644 --- a/src/generators/rust/constrainer/ConstantConstrainer.ts +++ b/src/generators/rust/constrainer/ConstantConstrainer.ts @@ -1,6 +1,6 @@ -import { ConstantConstraint } from '../../../helpers'; +import { RustConstantConstraint } from '../RustGenerator'; -export function defaultConstantConstraints(): ConstantConstraint { +export function defaultConstantConstraints(): RustConstantConstraint { return () => { return undefined; }; diff --git a/src/generators/rust/constrainer/EnumConstrainer.ts b/src/generators/rust/constrainer/EnumConstrainer.ts index 7915d3f893..8ba049d37d 100644 --- a/src/generators/rust/constrainer/EnumConstrainer.ts +++ b/src/generators/rust/constrainer/EnumConstrainer.ts @@ -6,12 +6,12 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { - FormatHelpers, - EnumKeyConstraint, - EnumValueConstraint -} from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedRustKeyword } from '../Constants'; +import { + RustEnumKeyConstraint, + RustEnumValueConstraint +} from '../RustGenerator'; export type ModelEnumKeyConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -46,7 +46,7 @@ export const DefaultEnumKeyConstraints: ModelEnumKeyConstraints = { export function defaultEnumKeyConstraints( customConstraints?: Partial -): EnumKeyConstraint { +): RustEnumKeyConstraint { const constraints = { ...DefaultEnumKeyConstraints, ...customConstraints }; return ({ enumKey, enumModel, constrainedEnumModel }) => { @@ -72,7 +72,7 @@ export function defaultEnumKeyConstraints( }; } -export function defaultEnumValueConstraints(): EnumValueConstraint { +export function defaultEnumValueConstraints(): RustEnumValueConstraint { return ({ enumValue }) => { return enumValue; }; diff --git a/src/generators/rust/constrainer/ModelNameConstrainer.ts b/src/generators/rust/constrainer/ModelNameConstrainer.ts index 599c69ab11..78c88efe84 100644 --- a/src/generators/rust/constrainer/ModelNameConstrainer.ts +++ b/src/generators/rust/constrainer/ModelNameConstrainer.ts @@ -3,8 +3,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, ModelNameConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedRustKeyword } from '../Constants'; +import { RustModelNameConstraint } from '../RustGenerator'; export type ModelNameConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -34,7 +35,7 @@ export const DefaultModelNameConstraints: ModelNameConstraints = { }; export function defaultModelNameConstraints( customConstraints?: Partial -): ModelNameConstraint { +): RustModelNameConstraint { const constraints = { ...DefaultModelNameConstraints, ...customConstraints }; return ({ modelName }) => { diff --git a/src/generators/rust/constrainer/PropertyKeyConstrainer.ts b/src/generators/rust/constrainer/PropertyKeyConstrainer.ts index 656c7a4618..e4a27f4bfb 100644 --- a/src/generators/rust/constrainer/PropertyKeyConstrainer.ts +++ b/src/generators/rust/constrainer/PropertyKeyConstrainer.ts @@ -5,8 +5,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, PropertyKeyConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedRustKeyword } from '../Constants'; +import { RustPropertyKeyConstraint } from '../RustGenerator'; export type PropertyKeyConstraintOptions = { NO_SPECIAL_CHAR: (value: string) => string; @@ -42,7 +43,7 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = { export function defaultPropertyKeyConstraints( customConstraints?: Partial -): PropertyKeyConstraint { +): RustPropertyKeyConstraint { const constraints = { ...DefaultPropertyKeyConstraints, ...customConstraints diff --git a/src/generators/rust/renderers/PackageRenderer.ts b/src/generators/rust/renderers/PackageRenderer.ts index 9b4a2461c1..27cad91740 100644 --- a/src/generators/rust/renderers/PackageRenderer.ts +++ b/src/generators/rust/renderers/PackageRenderer.ts @@ -20,14 +20,14 @@ export const RUST_DEFAULT_PACKAGE_PRESET: PackagePresetType = { return renderer.defaultSelf(); }, - lib({ inputModel, renderer }) { + lib({ inputModel, renderer, options }) { const modelNames: string[] = Object.values(inputModel.models).map( (m: MetaModel) => m.name ); const imports = renderer.renderBlock( modelNames .map((modelName) => { - let mod = defaultModelNameConstraints()({ modelName }); + let mod = defaultModelNameConstraints()({ modelName, options }); mod = FormatHelpers.snakeCase(mod); return ` pub mod ${mod}; diff --git a/src/generators/template/TemplateConstrainer.ts b/src/generators/template/TemplateConstrainer.ts index 4465ba6cbc..86fc24e62d 100644 --- a/src/generators/template/TemplateConstrainer.ts +++ b/src/generators/template/TemplateConstrainer.ts @@ -53,7 +53,7 @@ export const TemplateDefaultTypeMapping: TypeMapping< } }; -export const TemplateDefaultConstraints: Constraints = { +export const TemplateDefaultConstraints = { enumKey: defaultEnumKeyConstraints(), enumValue: defaultEnumValueConstraints(), modelName: defaultModelNameConstraints(), diff --git a/src/generators/template/TemplateGenerator.ts b/src/generators/template/TemplateGenerator.ts index afa1f7db91..d7033fcb85 100644 --- a/src/generators/template/TemplateGenerator.ts +++ b/src/generators/template/TemplateGenerator.ts @@ -20,8 +20,13 @@ import { EnumRenderer } from './renderers/EnumRenderer'; import { isReservedTemplateKeyword } from './Constants'; import { Logger } from '../..'; import { + ConstantConstraint, constrainMetaModel, - Constraints + Constraints, + EnumKeyConstraint, + EnumValueConstraint, + ModelNameConstraint, + PropertyKeyConstraint } from '../../helpers/ConstrainHelpers'; import { TemplateDefaultConstraints, @@ -33,8 +38,14 @@ import { TemplateDependencyManager } from './TemplateDependencyManager'; export interface TemplateOptions extends CommonGeneratorOptions { typeMapping: TypeMapping; - constraints: Constraints; + constraints: Constraints; } +export type TemplateConstantConstraint = ConstantConstraint; +export type TemplateEnumKeyConstraint = EnumKeyConstraint; +export type TemplateEnumValueConstraint = EnumValueConstraint; +export type TemplateModelNameConstraint = ModelNameConstraint; +export type TemplatePropertyKeyConstraint = + PropertyKeyConstraint; export interface TemplateRenderCompleteModelOptions { packageName: string; } diff --git a/src/generators/template/constrainer/ConstantConstrainer.ts b/src/generators/template/constrainer/ConstantConstrainer.ts index 2c076ad46d..ad1cf21366 100644 --- a/src/generators/template/constrainer/ConstantConstrainer.ts +++ b/src/generators/template/constrainer/ConstantConstrainer.ts @@ -1,6 +1,7 @@ import { ConstantConstraint } from '../../../helpers'; +import { TemplateConstantConstraint } from '../TemplateGenerator'; -export function defaultConstantConstraints(): ConstantConstraint { +export function defaultConstantConstraints(): TemplateConstantConstraint { return () => { return undefined; }; diff --git a/src/generators/template/constrainer/EnumConstrainer.ts b/src/generators/template/constrainer/EnumConstrainer.ts index eec1a43306..cedc96bd48 100644 --- a/src/generators/template/constrainer/EnumConstrainer.ts +++ b/src/generators/template/constrainer/EnumConstrainer.ts @@ -12,6 +12,10 @@ import { EnumValueConstraint } from '../../../helpers'; import { isReservedTemplateKeyword } from '../Constants'; +import { + TemplateEnumKeyConstraint, + TemplateEnumValueConstraint +} from '../TemplateGenerator'; export type ModelEnumKeyConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -50,7 +54,7 @@ export const DefaultEnumKeyConstraints: ModelEnumKeyConstraints = { */ export function defaultEnumKeyConstraints( customConstraints?: Partial -): EnumKeyConstraint { +): TemplateEnumKeyConstraint { const constraints = { ...DefaultEnumKeyConstraints, ...customConstraints }; return ({ enumKey, enumModel, constrainedEnumModel }) => { @@ -76,7 +80,7 @@ export function defaultEnumKeyConstraints( /** * Convert the enum value to a value that is compatible with Template */ -export function defaultEnumValueConstraints(): EnumValueConstraint { +export function defaultEnumValueConstraints(): TemplateEnumValueConstraint { return ({ enumValue }) => { let constrainedEnumValue = enumValue; switch (typeof enumValue) { diff --git a/src/generators/template/constrainer/ModelNameConstrainer.ts b/src/generators/template/constrainer/ModelNameConstrainer.ts index 8f96bc2ef0..f8e87b5cab 100644 --- a/src/generators/template/constrainer/ModelNameConstrainer.ts +++ b/src/generators/template/constrainer/ModelNameConstrainer.ts @@ -5,6 +5,7 @@ import { } from '../../../helpers/Constraints'; import { FormatHelpers, ModelNameConstraint } from '../../../helpers'; import { isReservedTemplateKeyword } from '../Constants'; +import { TemplateModelNameConstraint } from '../TemplateGenerator'; export type ModelNameConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -38,7 +39,7 @@ export const DefaultModelNameConstraints: ModelNameConstraints = { */ export function defaultModelNameConstraints( customConstraints?: Partial -): ModelNameConstraint { +): TemplateModelNameConstraint { const constraints = { ...DefaultModelNameConstraints, ...customConstraints }; return ({ modelName }) => { diff --git a/src/generators/template/constrainer/PropertyKeyConstrainer.ts b/src/generators/template/constrainer/PropertyKeyConstrainer.ts index 19ee7546b6..d3df2e15e5 100644 --- a/src/generators/template/constrainer/PropertyKeyConstrainer.ts +++ b/src/generators/template/constrainer/PropertyKeyConstrainer.ts @@ -7,6 +7,7 @@ import { } from '../../../helpers/Constraints'; import { FormatHelpers, PropertyKeyConstraint } from '../../../helpers'; import { isReservedTemplateKeyword } from '../Constants'; +import { TemplatePropertyKeyConstraint } from '../TemplateGenerator'; export type PropertyKeyConstraintOptions = { NO_SPECIAL_CHAR: (value: string) => string; @@ -44,7 +45,7 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = { */ export function defaultPropertyKeyConstraints( customConstraints?: Partial -): PropertyKeyConstraint { +): TemplatePropertyKeyConstraint { const constraints = { ...DefaultPropertyKeyConstraints, ...customConstraints diff --git a/src/generators/typescript/TypeScriptConstrainer.ts b/src/generators/typescript/TypeScriptConstrainer.ts index feec116bff..6eaf9279f1 100644 --- a/src/generators/typescript/TypeScriptConstrainer.ts +++ b/src/generators/typescript/TypeScriptConstrainer.ts @@ -8,7 +8,6 @@ import { defaultModelNameConstraints } from './constrainer/ModelNameConstrainer' import { defaultPropertyKeyConstraints } from './constrainer/PropertyKeyConstrainer'; import { defaultConstantConstraints } from './constrainer/ConstantConstrainer'; import { TypeScriptTypeMapping } from './TypeScriptGenerator'; -import { Constraints } from '../../helpers'; function applyNullable(model: ConstrainedMetaModel, type: string) { if (model.options.isNullable) { return `${type} | null`; @@ -92,7 +91,7 @@ export const TypeScriptDefaultTypeMapping: TypeScriptTypeMapping = { } }; -export const TypeScriptDefaultConstraints: Constraints = { +export const TypeScriptDefaultConstraints = { enumKey: defaultEnumKeyConstraints(), enumValue: defaultEnumValueConstraints(), modelName: defaultModelNameConstraints(), diff --git a/src/generators/typescript/TypeScriptGenerator.ts b/src/generators/typescript/TypeScriptGenerator.ts index e9058f4be8..e2a43e2ed8 100644 --- a/src/generators/typescript/TypeScriptGenerator.ts +++ b/src/generators/typescript/TypeScriptGenerator.ts @@ -14,8 +14,13 @@ import { RenderOutput } from '../../models'; import { + ConstantConstraint, constrainMetaModel, Constraints, + EnumKeyConstraint, + EnumValueConstraint, + ModelNameConstraint, + PropertyKeyConstraint, split, SplitOptions, TypeMapping @@ -44,9 +49,23 @@ export interface TypeScriptOptions enumType: 'enum' | 'union'; mapType: 'indexedObject' | 'map' | 'record'; typeMapping: TypeMapping; - constraints: Constraints; + constraints: Constraints; moduleSystem: TypeScriptModuleSystemType; + /** + * Use raw property names instead of constrained ones, + * where you most likely need to access them with obj["propertyName"] instead of obj.propertyName + */ + rawPropertyNames: boolean; } +export type TypeScriptConstantConstraint = + ConstantConstraint; +export type TypeScriptEnumKeyConstraint = EnumKeyConstraint; +export type TypeScriptEnumValueConstraint = + EnumValueConstraint; +export type TypeScriptModelNameConstraint = + ModelNameConstraint; +export type TypeScriptPropertyKeyConstraint = + PropertyKeyConstraint; export type TypeScriptTypeMapping = TypeMapping< TypeScriptOptions, TypeScriptDependencyManager @@ -72,6 +91,7 @@ export class TypeScriptGenerator extends AbstractGenerator< typeMapping: TypeScriptDefaultTypeMapping, constraints: TypeScriptDefaultConstraints, moduleSystem: 'ESM', + rawPropertyNames: false, // Temporarily set dependencyManager: () => { return {} as TypeScriptDependencyManager; diff --git a/src/generators/typescript/TypeScriptObjectRenderer.ts b/src/generators/typescript/TypeScriptObjectRenderer.ts index 79ce45b89f..be0eab12d0 100644 --- a/src/generators/typescript/TypeScriptObjectRenderer.ts +++ b/src/generators/typescript/TypeScriptObjectRenderer.ts @@ -1,12 +1,8 @@ -import { TypeScriptGenerator, TypeScriptOptions } from './TypeScriptGenerator'; import { ConstrainedObjectModel, - ConstrainedObjectPropertyModel, - InputMetaModel, - Preset + ConstrainedObjectPropertyModel } from '../../models'; import { TypeScriptRenderer } from './TypeScriptRenderer'; -import { TypeScriptDependencyManager } from './TypeScriptDependencyManager'; /** * Common renderer for TypeScript types @@ -14,17 +10,6 @@ import { TypeScriptDependencyManager } from './TypeScriptDependencyManager'; * @extends AbstractRenderer */ export abstract class TypeScriptObjectRenderer extends TypeScriptRenderer { - constructor( - options: TypeScriptOptions, - generator: TypeScriptGenerator, - presets: Array<[Preset, unknown]>, - model: ConstrainedObjectModel, - inputModel: InputMetaModel, - dependencyManager: TypeScriptDependencyManager - ) { - super(options, generator, presets, model, inputModel, dependencyManager); - } - /** * Render all the properties for the model by calling the property preset per property. */ diff --git a/src/generators/typescript/constrainer/ConstantConstrainer.ts b/src/generators/typescript/constrainer/ConstantConstrainer.ts index 22a7f7dee2..295ca3462f 100644 --- a/src/generators/typescript/constrainer/ConstantConstrainer.ts +++ b/src/generators/typescript/constrainer/ConstantConstrainer.ts @@ -5,7 +5,7 @@ import { ConstrainedReferenceModel, ConstrainedStringModel } from '../../../models'; -import { ConstantConstraint } from '../../../helpers'; +import { TypeScriptConstantConstraint } from '../TypeScriptGenerator'; const getConstrainedEnumModelConstant = (args: { constrainedMetaModel: ConstrainedMetaModel; @@ -21,7 +21,7 @@ const getConstrainedEnumModelConstant = (args: { } }; -export function defaultConstantConstraints(): ConstantConstraint { +export function defaultConstantConstraints(): TypeScriptConstantConstraint { return ({ constrainedMetaModel }) => { const constOptions = constrainedMetaModel.options.const; diff --git a/src/generators/typescript/constrainer/EnumConstrainer.ts b/src/generators/typescript/constrainer/EnumConstrainer.ts index 06485c62c3..4cd119f4fd 100644 --- a/src/generators/typescript/constrainer/EnumConstrainer.ts +++ b/src/generators/typescript/constrainer/EnumConstrainer.ts @@ -5,12 +5,12 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { - EnumKeyConstraint, - EnumValueConstraint, - FormatHelpers -} from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedTypeScriptKeyword } from '../Constants'; +import { + TypeScriptEnumKeyConstraint, + TypeScriptEnumValueConstraint +} from '../TypeScriptGenerator'; export type ModelEnumKeyConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -45,7 +45,7 @@ export const DefaultEnumKeyConstraints: ModelEnumKeyConstraints = { export function defaultEnumKeyConstraints( customConstraints?: Partial -): EnumKeyConstraint { +): TypeScriptEnumKeyConstraint { const constraints = { ...DefaultEnumKeyConstraints, ...customConstraints }; return ({ enumKey, enumModel, constrainedEnumModel }) => { @@ -68,7 +68,7 @@ export function defaultEnumKeyConstraints( }; } -export function defaultEnumValueConstraints(): EnumValueConstraint { +export function defaultEnumValueConstraints(): TypeScriptEnumValueConstraint { return ({ enumValue }) => { let normalizedEnumValue; switch (typeof enumValue) { diff --git a/src/generators/typescript/constrainer/ModelNameConstrainer.ts b/src/generators/typescript/constrainer/ModelNameConstrainer.ts index 935b745db6..5e6c110224 100644 --- a/src/generators/typescript/constrainer/ModelNameConstrainer.ts +++ b/src/generators/typescript/constrainer/ModelNameConstrainer.ts @@ -3,8 +3,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, ModelNameConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedTypeScriptKeyword } from '../Constants'; +import { TypeScriptModelNameConstraint } from '../TypeScriptGenerator'; export type ModelNameConstraints = { NO_SPECIAL_CHAR: (value: string) => string; @@ -34,7 +35,7 @@ export const DefaultModelNameConstraints: ModelNameConstraints = { }; export function defaultModelNameConstraints( customConstraints?: Partial -): ModelNameConstraint { +): TypeScriptModelNameConstraint { const constraints = { ...DefaultModelNameConstraints, ...customConstraints }; return ({ modelName }) => { diff --git a/src/generators/typescript/constrainer/PropertyKeyConstrainer.ts b/src/generators/typescript/constrainer/PropertyKeyConstrainer.ts index ca130ad858..92f66e7d46 100644 --- a/src/generators/typescript/constrainer/PropertyKeyConstrainer.ts +++ b/src/generators/typescript/constrainer/PropertyKeyConstrainer.ts @@ -5,8 +5,9 @@ import { NO_EMPTY_VALUE, NO_RESERVED_KEYWORDS } from '../../../helpers/Constraints'; -import { FormatHelpers, PropertyKeyConstraint } from '../../../helpers'; +import { FormatHelpers } from '../../../helpers'; import { isReservedTypeScriptKeyword } from '../Constants'; +import { TypeScriptPropertyKeyConstraint } from '../TypeScriptGenerator'; export type PropertyKeyConstraintOptions = { NO_SPECIAL_CHAR: (value: string) => string; @@ -41,7 +42,7 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = { }; export function defaultPropertyKeyConstraints( customConstraints?: Partial -): PropertyKeyConstraint { +): TypeScriptPropertyKeyConstraint { const constraints = { ...DefaultPropertyKeyConstraints, ...customConstraints diff --git a/src/helpers/ConstrainHelpers.ts b/src/helpers/ConstrainHelpers.ts index 4077a4ab36..8370f4ec9f 100644 --- a/src/helpers/ConstrainHelpers.ts +++ b/src/helpers/ConstrainHelpers.ts @@ -49,46 +49,61 @@ export type ConstrainContext< dependencyManager: DependencyManager; }; -export type EnumKeyContext = { +export type EnumKeyContext = { enumKey: string; constrainedEnumModel: ConstrainedEnumModel; enumModel: EnumModel; + options: Options; }; -export type EnumKeyConstraint = (context: EnumKeyContext) => string; +export type EnumKeyConstraint = ( + context: EnumKeyContext +) => string; -export type EnumValueContext = { +export type EnumValueContext = { enumValue: any; constrainedEnumModel: ConstrainedEnumModel; enumModel: EnumModel; + options: Options; }; -export type EnumValueConstraint = (context: EnumValueContext) => any; +export type EnumValueConstraint = ( + context: EnumValueContext +) => any; -export type ModelNameContext = { +export type ModelNameContext = { modelName: string; + options: Options; }; -export type ModelNameConstraint = (context: ModelNameContext) => string; +export type ModelNameConstraint = ( + context: ModelNameContext +) => string; -export type PropertyKeyContext = { +export type PropertyKeyContext = { constrainedObjectPropertyModel: ConstrainedObjectPropertyModel; objectPropertyModel: ObjectPropertyModel; constrainedObjectModel: ConstrainedObjectModel; objectModel: ObjectModel; + options: Options; }; -export type PropertyKeyConstraint = (context: PropertyKeyContext) => string; +export type PropertyKeyConstraint = ( + context: PropertyKeyContext +) => string; -export type ConstantContext = { +export type ConstantContext = { constrainedMetaModel: ConstrainedMetaModel; + options: Options; }; -export type ConstantConstraint = (context: ConstantContext) => unknown; +export type ConstantConstraint = ( + context: ConstantContext +) => unknown; -export interface Constraints { - enumKey: EnumKeyConstraint; - enumValue: EnumValueConstraint; - modelName: ModelNameConstraint; - propertyKey: PropertyKeyConstraint; - constant: ConstantConstraint; +export interface Constraints { + enumKey: EnumKeyConstraint; + enumValue: EnumValueConstraint; + modelName: ModelNameConstraint; + propertyKey: PropertyKeyConstraint; + constant: ConstantConstraint; } const placeHolderConstrainedObject = new ConstrainedAnyModel( @@ -117,7 +132,7 @@ function constrainReferenceModel< DependencyManager extends AbstractDependencyManager >( typeMapping: TypeMapping, - constrainRules: Constraints, + constrainRules: Constraints, context: ConstrainContext, alreadySeenModels: Map ): ConstrainedReferenceModel { @@ -146,7 +161,8 @@ function constrainReferenceModel< if (constrainedModel.options.const) { const constrainedConstant = constrainRules.constant({ - constrainedMetaModel: constrainedModel + constrainedMetaModel: constrainedModel, + options: context.options }); constrainedModel.options.const.value = constrainedConstant; } @@ -263,7 +279,7 @@ function constrainTupleModel< DependencyManager extends AbstractDependencyManager >( typeMapping: TypeMapping, - constrainRules: Constraints, + constrainRules: Constraints, context: ConstrainContext, alreadySeenModels: Map ): ConstrainedTupleModel { @@ -299,7 +315,7 @@ function constrainArrayModel< DependencyManager extends AbstractDependencyManager >( typeMapping: TypeMapping, - constrainRules: Constraints, + constrainRules: Constraints, context: ConstrainContext, alreadySeenModels: Map ): ConstrainedArrayModel { @@ -368,7 +384,7 @@ function constrainUnionModel< DependencyManager extends AbstractDependencyManager >( typeMapping: TypeMapping, - constrainRules: Constraints, + constrainRules: Constraints, context: ConstrainContext, alreadySeenModels: Map ): ConstrainedUnionModel { @@ -407,7 +423,7 @@ function constrainDictionaryModel< DependencyManager extends AbstractDependencyManager >( typeMapping: TypeMapping, - constrainRules: Constraints, + constrainRules: Constraints, context: ConstrainContext, alreadySeenModels: Map ): ConstrainedDictionaryModel { @@ -454,7 +470,7 @@ function constrainObjectModel< DependencyManager extends AbstractDependencyManager >( typeMapping: TypeMapping, - constrainRules: Constraints, + constrainRules: Constraints, context: ConstrainContext, alreadySeenModels: Map ): ConstrainedObjectModel { @@ -499,7 +515,8 @@ function constrainObjectModel< objectPropertyModel: propertyMetaModel, constrainedObjectPropertyModel: constrainedPropertyModel, constrainedObjectModel: constrainedModel, - objectModel: context.metaModel + objectModel: context.metaModel, + options: context.options }); constrainedPropertyModel.propertyName = constrainedPropertyName; const constrainedProperty = constrainMetaModel( @@ -532,7 +549,7 @@ function ConstrainEnumModel< DependencyManager extends AbstractDependencyManager >( typeMapping: TypeMapping, - constrainRules: Constraints, + constrainRules: Constraints, context: ConstrainContext ): ConstrainedEnumModel { const constrainedModel = new ConstrainedEnumModel( @@ -549,12 +566,14 @@ function ConstrainEnumModel< const constrainedEnumKey = constrainRules.enumKey({ enumKey: String(enumValue.key), enumModel: context.metaModel, - constrainedEnumModel: constrainedModel + constrainedEnumModel: constrainedModel, + options: context.options }); const constrainedEnumValue = constrainRules.enumValue({ enumValue: enumValue.value, enumModel: context.metaModel, - constrainedEnumModel: constrainedModel + constrainedEnumModel: constrainedModel, + options: context.options }); return new ConstrainedEnumValueModel( constrainedEnumKey, @@ -585,7 +604,7 @@ export function constrainMetaModel< DependencyManager extends AbstractDependencyManager >( typeMapping: TypeMapping, - constrainRules: Constraints, + constrainRules: Constraints, context: ConstrainContext, alreadySeenModels: Map = new Map() ): ConstrainedMetaModel { @@ -593,7 +612,8 @@ export function constrainMetaModel< return alreadySeenModels.get(context.metaModel) as ConstrainedMetaModel; } const constrainedName = constrainRules.modelName({ - modelName: context.metaModel.name + modelName: context.metaModel.name, + options: context.options }); const newContext = { ...context, constrainedName }; if (newContext.metaModel instanceof ObjectModel) { @@ -675,7 +695,8 @@ export function constrainMetaModel< if (simpleModel !== undefined) { if (simpleModel.options.const) { const constrainedConstant = constrainRules.constant({ - constrainedMetaModel: simpleModel + constrainedMetaModel: simpleModel, + options: context.options }); simpleModel.options.const.value = constrainedConstant; } diff --git a/test/generators/csharp/constrainer/EnumConstrainer.spec.ts b/test/generators/csharp/constrainer/EnumConstrainer.spec.ts index 1ec31923d8..42f72d23d4 100644 --- a/test/generators/csharp/constrainer/EnumConstrainer.spec.ts +++ b/test/generators/csharp/constrainer/EnumConstrainer.spec.ts @@ -1,6 +1,7 @@ import { CSharpDefaultConstraints } from '../../../../src/generators/csharp/CSharpConstrainer'; import { EnumModel } from '../../../../src/models/MetaModel'; import { + CSharpGenerator, ConstrainedEnumModel, ConstrainedEnumValueModel } from '../../../../src'; @@ -24,7 +25,8 @@ describe('EnumConstrainer', () => { const constrainedKey = CSharpDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '%' + enumKey: '%', + options: CSharpGenerator.defaultOptions }); expect(constrainedKey).toEqual('PERCENT'); }); @@ -32,7 +34,8 @@ describe('EnumConstrainer', () => { const constrainedKey = CSharpDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '1' + enumKey: '1', + options: CSharpGenerator.defaultOptions }); expect(constrainedKey).toEqual('NUMBER_1'); }); @@ -52,7 +55,8 @@ describe('EnumConstrainer', () => { const constrainedKey = CSharpDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: CSharpGenerator.defaultOptions }); expect(constrainedKey).toEqual('RESERVED_EMPTY'); }); @@ -60,7 +64,8 @@ describe('EnumConstrainer', () => { const constrainedKey = CSharpDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: CSharpGenerator.defaultOptions }); expect(constrainedKey).toEqual('EMPTY'); }); @@ -68,7 +73,8 @@ describe('EnumConstrainer', () => { const constrainedKey = CSharpDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: 'some weird_value!"#2' + enumKey: 'some weird_value!"#2', + options: CSharpGenerator.defaultOptions }); expect(constrainedKey).toEqual( 'SOME_SPACE_WEIRD_VALUE_EXCLAMATION_QUOTATION_HASH_2' @@ -78,7 +84,8 @@ describe('EnumConstrainer', () => { const constrainedKey = CSharpDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: 'return' + enumKey: 'return', + options: CSharpGenerator.defaultOptions }); expect(constrainedKey).toEqual('RESERVED_RETURN'); }); @@ -88,7 +95,8 @@ describe('EnumConstrainer', () => { const constrainedValue = CSharpDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: 'string value' + enumValue: 'string value', + options: CSharpGenerator.defaultOptions }); expect(constrainedValue).toEqual('"string value"'); }); @@ -96,7 +104,8 @@ describe('EnumConstrainer', () => { const constrainedValue = CSharpDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: true + enumValue: true, + options: CSharpGenerator.defaultOptions }); expect(constrainedValue).toEqual(true); }); @@ -104,7 +113,8 @@ describe('EnumConstrainer', () => { const constrainedValue = CSharpDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: 123 + enumValue: 123, + options: CSharpGenerator.defaultOptions }); expect(constrainedValue).toEqual(123); }); @@ -112,7 +122,8 @@ describe('EnumConstrainer', () => { const constrainedValue = CSharpDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: { test: 'test' } + enumValue: { test: 'test' }, + options: CSharpGenerator.defaultOptions }); expect(constrainedValue).toEqual('"{\\"test\\":\\"test\\"}"'); }); @@ -120,7 +131,8 @@ describe('EnumConstrainer', () => { const constrainedValue = CSharpDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: undefined + enumValue: undefined, + options: CSharpGenerator.defaultOptions }); expect(constrainedValue).toEqual('"undefined"'); }); @@ -137,7 +149,12 @@ describe('EnumConstrainer', () => { const constrainFunction = defaultEnumKeyConstraints( mockedConstraintCallbacks ); - constrainFunction({ enumModel, constrainedEnumModel, enumKey: '' }); + constrainFunction({ + enumModel, + constrainedEnumModel, + enumKey: '', + options: CSharpGenerator.defaultOptions + }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { expect(jestMockCallback).toHaveBeenCalled(); @@ -159,7 +176,8 @@ describe('EnumConstrainer', () => { const constrainedValue = constrainFunction({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: CSharpGenerator.defaultOptions }); expect(constrainedValue).toEqual(''); for (const jestMockCallback of spies) { diff --git a/test/generators/csharp/constrainer/ModelNameConstrainer.spec.ts b/test/generators/csharp/constrainer/ModelNameConstrainer.spec.ts index 9aa2f539f9..ac62267856 100644 --- a/test/generators/csharp/constrainer/ModelNameConstrainer.spec.ts +++ b/test/generators/csharp/constrainer/ModelNameConstrainer.spec.ts @@ -1,3 +1,4 @@ +import { CSharpGenerator } from '../../../../src'; import { CSharpDefaultConstraints } from '../../../../src/generators/csharp/CSharpConstrainer'; import { DefaultModelNameConstraints, @@ -7,31 +8,36 @@ import { describe('ModelNameConstrainer', () => { test('should never render special chars', () => { const constrainedKey = CSharpDefaultConstraints.modelName({ - modelName: '%' + modelName: '%', + options: CSharpGenerator.defaultOptions }); expect(constrainedKey).toEqual('Percent'); }); test('should never render number as start char', () => { const constrainedKey = CSharpDefaultConstraints.modelName({ - modelName: '1' + modelName: '1', + options: CSharpGenerator.defaultOptions }); expect(constrainedKey).toEqual('Number_1'); }); test('should never contain empty name', () => { const constrainedKey = CSharpDefaultConstraints.modelName({ - modelName: '' + modelName: '', + options: CSharpGenerator.defaultOptions }); expect(constrainedKey).toEqual('Empty'); }); test('should use constant naming format', () => { const constrainedKey = CSharpDefaultConstraints.modelName({ - modelName: 'some weird_value!"#2' + modelName: 'some weird_value!"#2', + options: CSharpGenerator.defaultOptions }); expect(constrainedKey).toEqual('SomeWeirdValueExclamationQuotationHash_2'); }); test('should never render reserved keywords', () => { const constrainedKey = CSharpDefaultConstraints.modelName({ - modelName: 'return' + modelName: 'return', + options: CSharpGenerator.defaultOptions }); expect(constrainedKey).toEqual('ReservedReturn'); }); @@ -47,7 +53,10 @@ describe('ModelNameConstrainer', () => { const constrainFunction = defaultModelNameConstraints( mockedConstraintCallbacks ); - constrainFunction({ modelName: '' }); + constrainFunction({ + modelName: '', + options: CSharpGenerator.defaultOptions + }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { expect(jestMockCallback).toHaveBeenCalled(); @@ -65,7 +74,10 @@ describe('ModelNameConstrainer', () => { const constrainFunction = defaultModelNameConstraints({ NAMING_FORMATTER: jestCallback }); - const constrainedValue = constrainFunction({ modelName: '' }); + const constrainedValue = constrainFunction({ + modelName: '', + options: CSharpGenerator.defaultOptions + }); expect(constrainedValue).toEqual(''); for (const jestMockCallback of spies) { expect(jestMockCallback).toHaveBeenCalled(); diff --git a/test/generators/csharp/constrainer/PropertyKeyConstrainer.spec.ts b/test/generators/csharp/constrainer/PropertyKeyConstrainer.spec.ts index 2c2e86c94c..2d5291ba40 100644 --- a/test/generators/csharp/constrainer/PropertyKeyConstrainer.spec.ts +++ b/test/generators/csharp/constrainer/PropertyKeyConstrainer.spec.ts @@ -1,5 +1,6 @@ import { CSharpDefaultConstraints } from '../../../../src/generators/csharp/CSharpConstrainer'; import { + CSharpGenerator, ConstrainedObjectModel, ConstrainedObjectPropertyModel, ObjectModel, @@ -36,7 +37,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: CSharpGenerator.defaultOptions }); }; @@ -99,7 +101,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel: objectPropertyModel2, - constrainedObjectPropertyModel: constrainedObjectPropertyModel2 + constrainedObjectPropertyModel: constrainedObjectPropertyModel2, + options: CSharpGenerator.defaultOptions }); expect(constrainedKey).toEqual('reservedReservedReturn'); }); @@ -135,7 +138,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: CSharpGenerator.defaultOptions }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { @@ -174,7 +178,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: CSharpGenerator.defaultOptions }); expect(constrainedValue).toEqual(''); expect(jestCallback).toHaveBeenCalled(); diff --git a/test/generators/csharp/presets/CommonPreset.spec.ts b/test/generators/csharp/presets/CommonPreset.spec.ts index 4ba4258fac..6d37a2b93b 100644 --- a/test/generators/csharp/presets/CommonPreset.spec.ts +++ b/test/generators/csharp/presets/CommonPreset.spec.ts @@ -1,7 +1,6 @@ import { CSharpGenerator, - CSHARP_COMMON_PRESET, - CSHARP_DEFAULT_PRESET + CSHARP_COMMON_PRESET } from '../../../../src/generators'; const doc = { $id: 'Test', diff --git a/test/generators/dart/DartConstrainer.spec.ts b/test/generators/dart/DartConstrainer.spec.ts index 4f2d72bbd2..04050180ef 100644 --- a/test/generators/dart/DartConstrainer.spec.ts +++ b/test/generators/dart/DartConstrainer.spec.ts @@ -13,8 +13,7 @@ import { ConstrainedReferenceModel, ConstrainedStringModel, ConstrainedTupleModel, - ConstrainedUnionModel, - InputMetaModel + ConstrainedUnionModel } from '../../../src/models'; describe('DartConstrainer', () => { diff --git a/test/generators/dart/DartRenderer.spec.ts b/test/generators/dart/DartRenderer.spec.ts index bc41f65695..afdc9e04f2 100644 --- a/test/generators/dart/DartRenderer.spec.ts +++ b/test/generators/dart/DartRenderer.spec.ts @@ -1,7 +1,4 @@ -import { - defaultGeneratorOptions, - DartGenerator -} from '../../../src/generators'; +import { DartGenerator } from '../../../src/generators'; import { DartDependencyManager } from '../../../src/generators/dart/DartDependencyManager'; import { DartRenderer } from '../../../src/generators/dart/DartRenderer'; import { ConstrainedObjectModel, InputMetaModel } from '../../../src/models'; diff --git a/test/generators/dart/constrainer/EnumConstrainer.spec.ts b/test/generators/dart/constrainer/EnumConstrainer.spec.ts index aedbc3dda2..d020608787 100644 --- a/test/generators/dart/constrainer/EnumConstrainer.spec.ts +++ b/test/generators/dart/constrainer/EnumConstrainer.spec.ts @@ -2,7 +2,8 @@ import { DartDefaultConstraints } from '../../../../src/generators/dart/DartCons import { EnumModel } from '../../../../src/models/MetaModel'; import { ConstrainedEnumModel, - ConstrainedEnumValueModel + ConstrainedEnumValueModel, + DartGenerator } from '../../../../src'; import { defaultEnumKeyConstraints, @@ -24,7 +25,8 @@ describe('EnumConstrainer', () => { const constrainedKey = DartDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '%' + enumKey: '%', + options: DartGenerator.defaultOptions }); expect(constrainedKey).toEqual('PERCENT'); }); @@ -32,7 +34,8 @@ describe('EnumConstrainer', () => { const constrainedKey = DartDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '1' + enumKey: '1', + options: DartGenerator.defaultOptions }); expect(constrainedKey).toEqual('NUMBER_1'); }); @@ -52,7 +55,8 @@ describe('EnumConstrainer', () => { const constrainedKey = DartDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: DartGenerator.defaultOptions }); expect(constrainedKey).toEqual('RESERVED_EMPTY'); }); @@ -60,7 +64,8 @@ describe('EnumConstrainer', () => { const constrainedKey = DartDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: DartGenerator.defaultOptions }); expect(constrainedKey).toEqual('EMPTY'); }); @@ -68,7 +73,8 @@ describe('EnumConstrainer', () => { const constrainedKey = DartDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: 'some weird_value!"#2' + enumKey: 'some weird_value!"#2', + options: DartGenerator.defaultOptions }); expect(constrainedKey).toEqual( 'SOME_WEIRD_VALUE_EXCLAMATION_QUOTATION_HASH_2' @@ -78,7 +84,8 @@ describe('EnumConstrainer', () => { const constrainedKey = DartDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: 'return' + enumKey: 'return', + options: DartGenerator.defaultOptions }); expect(constrainedKey).toEqual('RESERVED_RETURN'); }); @@ -88,7 +95,8 @@ describe('EnumConstrainer', () => { const constrainedValue = DartDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: 'string value' + enumValue: 'string value', + options: DartGenerator.defaultOptions }); expect(constrainedValue).toEqual('"string value"'); }); @@ -96,7 +104,8 @@ describe('EnumConstrainer', () => { const constrainedValue = DartDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: true + enumValue: true, + options: DartGenerator.defaultOptions }); expect(constrainedValue).toEqual('"true"'); }); @@ -104,7 +113,8 @@ describe('EnumConstrainer', () => { const constrainedValue = DartDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: 123 + enumValue: 123, + options: DartGenerator.defaultOptions }); expect(constrainedValue).toEqual(123); }); @@ -112,7 +122,8 @@ describe('EnumConstrainer', () => { const constrainedValue = DartDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: { test: 'test' } + enumValue: { test: 'test' }, + options: DartGenerator.defaultOptions }); expect(constrainedValue).toEqual('"{\\"test\\":\\"test\\"}"'); }); @@ -120,7 +131,8 @@ describe('EnumConstrainer', () => { const constrainedValue = DartDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: undefined + enumValue: undefined, + options: DartGenerator.defaultOptions }); expect(constrainedValue).toEqual('"undefined"'); }); @@ -137,7 +149,12 @@ describe('EnumConstrainer', () => { const constrainFunction = defaultEnumKeyConstraints( mockedConstraintCallbacks ); - constrainFunction({ enumModel, constrainedEnumModel, enumKey: '' }); + constrainFunction({ + enumModel, + constrainedEnumModel, + enumKey: '', + options: DartGenerator.defaultOptions + }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { expect(jestMockCallback).toHaveBeenCalled(); @@ -159,7 +176,8 @@ describe('EnumConstrainer', () => { const constrainedValue = constrainFunction({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: DartGenerator.defaultOptions }); expect(constrainedValue).toEqual(''); for (const jestMockCallback of spies) { diff --git a/test/generators/dart/constrainer/ModelNameConstrainer.spec.ts b/test/generators/dart/constrainer/ModelNameConstrainer.spec.ts index 1a6ad450a6..9b1f26f482 100644 --- a/test/generators/dart/constrainer/ModelNameConstrainer.spec.ts +++ b/test/generators/dart/constrainer/ModelNameConstrainer.spec.ts @@ -1,3 +1,4 @@ +import { DartGenerator } from '../../../../src'; import { DartDefaultConstraints } from '../../../../src/generators/dart/DartConstrainer'; import { DefaultModelNameConstraints, @@ -6,20 +7,30 @@ import { } from '../../../../src/generators/dart/constrainer/ModelNameConstrainer'; describe('ModelNameConstrainer', () => { test('should never render special chars', () => { - const constrainedKey = DartDefaultConstraints.modelName({ modelName: '%' }); + const constrainedKey = DartDefaultConstraints.modelName({ + modelName: '%', + options: DartGenerator.defaultOptions + }); expect(constrainedKey).toEqual('Percent'); }); test('should never render number as start char', () => { - const constrainedKey = DartDefaultConstraints.modelName({ modelName: '1' }); + const constrainedKey = DartDefaultConstraints.modelName({ + modelName: '1', + options: DartGenerator.defaultOptions + }); expect(constrainedKey).toEqual('Number_1'); }); test('should never contain empty name', () => { - const constrainedKey = DartDefaultConstraints.modelName({ modelName: '' }); + const constrainedKey = DartDefaultConstraints.modelName({ + modelName: '', + options: DartGenerator.defaultOptions + }); expect(constrainedKey).toEqual('Empty'); }); test('should use constant naming format', () => { const constrainedKey = DartDefaultConstraints.modelName({ - modelName: 'some weird_value!"#2' + modelName: 'some weird_value!"#2', + options: DartGenerator.defaultOptions }); expect(constrainedKey).toEqual( 'SomeSpaceWeirdUnderscoreValueExclamationQuotationHash_2' @@ -27,7 +38,8 @@ describe('ModelNameConstrainer', () => { }); test('should never render reserved keywords', () => { const constrainedKey = DartDefaultConstraints.modelName({ - modelName: 'return' + modelName: 'return', + options: DartGenerator.defaultOptions }); expect(constrainedKey).toEqual('ReservedReturn'); }); @@ -43,7 +55,10 @@ describe('ModelNameConstrainer', () => { const constrainFunction = defaultModelNameConstraints( mockedConstraintCallbacks ); - constrainFunction({ modelName: '' }); + constrainFunction({ + modelName: '', + options: DartGenerator.defaultOptions + }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { expect(jestMockCallback).toHaveBeenCalled(); @@ -61,7 +76,10 @@ describe('ModelNameConstrainer', () => { const constrainFunction = defaultModelNameConstraints({ NAMING_FORMATTER: jestCallback }); - const constrainedValue = constrainFunction({ modelName: '' }); + const constrainedValue = constrainFunction({ + modelName: '', + options: DartGenerator.defaultOptions + }); expect(constrainedValue).toEqual(''); for (const jestMockCallback of spies) { expect(jestMockCallback).toHaveBeenCalled(); diff --git a/test/generators/dart/constrainer/PropertyKeyConstrainer.spec.ts b/test/generators/dart/constrainer/PropertyKeyConstrainer.spec.ts index 4e88ec352c..b110e2ffeb 100644 --- a/test/generators/dart/constrainer/PropertyKeyConstrainer.spec.ts +++ b/test/generators/dart/constrainer/PropertyKeyConstrainer.spec.ts @@ -2,6 +2,7 @@ import { DartDefaultConstraints } from '../../../../src/generators/dart/DartCons import { ConstrainedObjectModel, ConstrainedObjectPropertyModel, + DartGenerator, ObjectModel, ObjectPropertyModel } from '../../../../src'; @@ -36,7 +37,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: DartGenerator.defaultOptions }); }; afterEach(() => { @@ -98,7 +100,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel: objectPropertyModel2, - constrainedObjectPropertyModel: constrainedObjectPropertyModel2 + constrainedObjectPropertyModel: constrainedObjectPropertyModel2, + options: DartGenerator.defaultOptions }); expect(constrainedKey).toEqual('reservedReservedReturn'); }); @@ -133,7 +136,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: DartGenerator.defaultOptions }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { @@ -172,7 +176,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: DartGenerator.defaultOptions }); expect(constrainedValue).toEqual(''); expect(jestCallback).toHaveBeenCalled(); diff --git a/test/generators/go/constrainer/EnumConstrainer.spec.ts b/test/generators/go/constrainer/EnumConstrainer.spec.ts index 332856cf13..c4b49bec3f 100644 --- a/test/generators/go/constrainer/EnumConstrainer.spec.ts +++ b/test/generators/go/constrainer/EnumConstrainer.spec.ts @@ -2,7 +2,8 @@ import { GoDefaultConstraints } from '../../../../src/generators/go/GoConstraine import { EnumModel } from '../../../../src/models/MetaModel'; import { ConstrainedEnumModel, - ConstrainedEnumValueModel + ConstrainedEnumValueModel, + GoGenerator } from '../../../../src'; import { defaultEnumKeyConstraints, @@ -24,7 +25,8 @@ describe('EnumConstrainer', () => { const constrainedKey = GoDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '%' + enumKey: '%', + options: GoGenerator.defaultOptions }); expect(constrainedKey).toEqual('TestPercent'); }); @@ -32,7 +34,8 @@ describe('EnumConstrainer', () => { const constrainedKey = GoDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '1' + enumKey: '1', + options: GoGenerator.defaultOptions }); expect(constrainedKey).toEqual('TestNumber_1'); }); @@ -52,7 +55,8 @@ describe('EnumConstrainer', () => { const constrainedKey = GoDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: GoGenerator.defaultOptions }); expect(constrainedKey).toEqual('TestReservedEmpty'); }); @@ -60,7 +64,8 @@ describe('EnumConstrainer', () => { const constrainedKey = GoDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: GoGenerator.defaultOptions }); expect(constrainedKey).toEqual('TestEmpty'); }); @@ -68,7 +73,8 @@ describe('EnumConstrainer', () => { const constrainedKey = GoDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: 'some weird_value!"#2' + enumKey: 'some weird_value!"#2', + options: GoGenerator.defaultOptions }); expect(constrainedKey).toEqual( 'TestSomeSpaceWeirdValueExclamationQuotationHash_2' @@ -78,7 +84,8 @@ describe('EnumConstrainer', () => { const constrainedKey = GoDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: 'return' + enumKey: 'return', + options: GoGenerator.defaultOptions }); expect(constrainedKey).toEqual('TestReservedReturn'); }); @@ -88,7 +95,8 @@ describe('EnumConstrainer', () => { const constrainedValue = GoDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: 'string value' + enumValue: 'string value', + options: GoGenerator.defaultOptions }); expect(constrainedValue).toEqual('"string value"'); }); @@ -96,7 +104,8 @@ describe('EnumConstrainer', () => { const constrainedValue = GoDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: true + enumValue: true, + options: GoGenerator.defaultOptions }); expect(constrainedValue).toEqual('true'); }); @@ -104,7 +113,8 @@ describe('EnumConstrainer', () => { const constrainedValue = GoDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: 123 + enumValue: 123, + options: GoGenerator.defaultOptions }); expect(constrainedValue).toEqual(123); }); @@ -112,7 +122,8 @@ describe('EnumConstrainer', () => { const constrainedValue = GoDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: { test: 'test' } + enumValue: { test: 'test' }, + options: GoGenerator.defaultOptions }); expect(constrainedValue).toEqual('{"test":"test"}'); }); @@ -120,7 +131,8 @@ describe('EnumConstrainer', () => { const constrainedValue = GoDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: undefined + enumValue: undefined, + options: GoGenerator.defaultOptions }); expect(constrainedValue).toEqual(undefined); }); @@ -131,7 +143,8 @@ describe('EnumConstrainer', () => { const value = constrainFunction({ enumModel, constrainedEnumModel, - enumKey: 'TEST' + enumKey: 'TEST', + options: GoGenerator.defaultOptions }); expect(value).toEqual('TestTest'); }); @@ -146,7 +159,12 @@ describe('EnumConstrainer', () => { const constrainFunction = defaultEnumKeyConstraints( mockedConstraintCallbacks ); - constrainFunction({ enumModel, constrainedEnumModel, enumKey: '' }); + constrainFunction({ + enumModel, + constrainedEnumModel, + enumKey: '', + options: GoGenerator.defaultOptions + }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { expect(jestMockCallback).toHaveBeenCalled(); @@ -168,7 +186,8 @@ describe('EnumConstrainer', () => { const constrainedValue = constrainFunction({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: GoGenerator.defaultOptions }); expect(constrainedValue).toEqual(''); for (const jestMockCallback of spies) { diff --git a/test/generators/go/constrainer/ModelNameConstrainer.spec.ts b/test/generators/go/constrainer/ModelNameConstrainer.spec.ts index 0be52ccbfe..b4f7610a19 100644 --- a/test/generators/go/constrainer/ModelNameConstrainer.spec.ts +++ b/test/generators/go/constrainer/ModelNameConstrainer.spec.ts @@ -1,3 +1,4 @@ +import { GoGenerator } from '../../../../src'; import { GoDefaultConstraints } from '../../../../src/generators/go/GoConstrainer'; import { DefaultModelNameConstraints, @@ -6,26 +7,37 @@ import { } from '../../../../src/generators/go/constrainer/ModelNameConstrainer'; describe('ModelNameConstrainer', () => { test('should never render special chars', () => { - const constrainedKey = GoDefaultConstraints.modelName({ modelName: '%' }); + const constrainedKey = GoDefaultConstraints.modelName({ + modelName: '%', + options: GoGenerator.defaultOptions + }); expect(constrainedKey).toEqual('Percent'); }); test('should never render number as start char', () => { - const constrainedKey = GoDefaultConstraints.modelName({ modelName: '1' }); + const constrainedKey = GoDefaultConstraints.modelName({ + modelName: '1', + options: GoGenerator.defaultOptions + }); expect(constrainedKey).toEqual('Number_1'); }); test('should never contain empty name', () => { - const constrainedKey = GoDefaultConstraints.modelName({ modelName: '' }); + const constrainedKey = GoDefaultConstraints.modelName({ + modelName: '', + options: GoGenerator.defaultOptions + }); expect(constrainedKey).toEqual('Empty'); }); test('should use constant naming format', () => { const constrainedKey = GoDefaultConstraints.modelName({ - modelName: 'some weird_value!"#2' + modelName: 'some weird_value!"#2', + options: GoGenerator.defaultOptions }); expect(constrainedKey).toEqual('SomeWeirdValueExclamationQuotationHash_2'); }); test('should never render reserved keywords', () => { const constrainedKey = GoDefaultConstraints.modelName({ - modelName: 'return' + modelName: 'return', + options: GoGenerator.defaultOptions }); expect(constrainedKey).toEqual('ReservedReturn'); }); @@ -41,7 +53,10 @@ describe('ModelNameConstrainer', () => { const constrainFunction = defaultModelNameConstraints( mockedConstraintCallbacks ); - constrainFunction({ modelName: '' }); + constrainFunction({ + modelName: '', + options: GoGenerator.defaultOptions + }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { expect(jestMockCallback).toHaveBeenCalled(); @@ -59,7 +74,10 @@ describe('ModelNameConstrainer', () => { const constrainFunction = defaultModelNameConstraints({ NAMING_FORMATTER: jestCallback }); - const constrainedValue = constrainFunction({ modelName: '' }); + const constrainedValue = constrainFunction({ + modelName: '', + options: GoGenerator.defaultOptions + }); expect(constrainedValue).toEqual(''); for (const jestMockCallback of spies) { expect(jestMockCallback).toHaveBeenCalled(); diff --git a/test/generators/go/constrainer/PropertyKeyConstrainer.spec.ts b/test/generators/go/constrainer/PropertyKeyConstrainer.spec.ts index 195587071c..84183e8e3d 100644 --- a/test/generators/go/constrainer/PropertyKeyConstrainer.spec.ts +++ b/test/generators/go/constrainer/PropertyKeyConstrainer.spec.ts @@ -2,6 +2,7 @@ import { GoDefaultConstraints } from '../../../../src/generators/go/GoConstraine import { ConstrainedObjectModel, ConstrainedObjectPropertyModel, + GoGenerator, ObjectModel, ObjectPropertyModel } from '../../../../src'; @@ -36,7 +37,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: GoGenerator.defaultOptions }); }; @@ -95,7 +97,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel: objectPropertyModel2, - constrainedObjectPropertyModel: constrainedObjectPropertyModel2 + constrainedObjectPropertyModel: constrainedObjectPropertyModel2, + options: GoGenerator.defaultOptions }); expect(constrainedKey).toEqual('ReservedReservedReturn'); }); @@ -130,7 +133,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: GoGenerator.defaultOptions }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { @@ -169,7 +173,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: GoGenerator.defaultOptions }); expect(constrainedValue).toEqual(''); expect(jestCallback).toHaveBeenCalled(); diff --git a/test/generators/java/JavaRenderer.spec.ts b/test/generators/java/JavaRenderer.spec.ts index edbf22c03e..cbefc431e0 100644 --- a/test/generators/java/JavaRenderer.spec.ts +++ b/test/generators/java/JavaRenderer.spec.ts @@ -1,11 +1,7 @@ import { JavaGenerator } from '../../../src/generators'; import { JavaDependencyManager } from '../../../src/generators/java/JavaDependencyManager'; import { JavaRenderer } from '../../../src/generators/java/JavaRenderer'; -import { - CommonModel, - ConstrainedObjectModel, - InputMetaModel -} from '../../../src/models'; +import { ConstrainedObjectModel, InputMetaModel } from '../../../src/models'; import { MockJavaRenderer } from '../../TestUtils/TestRenderers'; describe('JavaRenderer', () => { diff --git a/test/generators/java/constrainer/ConstantConstrainer.spec.ts b/test/generators/java/constrainer/ConstantConstrainer.spec.ts index c66822deba..302321c51c 100644 --- a/test/generators/java/constrainer/ConstantConstrainer.spec.ts +++ b/test/generators/java/constrainer/ConstantConstrainer.spec.ts @@ -2,7 +2,8 @@ import { ConstrainedEnumModel, ConstrainedEnumValueModel, ConstrainedReferenceModel, - ConstrainedStringModel + ConstrainedStringModel, + JavaGenerator } from '../../../../src'; import { defaultConstantConstraints } from '../../../../src/generators/java/constrainer/ConstantConstrainer'; @@ -14,7 +15,8 @@ describe('ConstantConstrainer', () => { undefined, {}, 'String' - ) + ), + options: JavaGenerator.defaultOptions }); expect(constrainedConstant).toBeUndefined(); }); @@ -38,7 +40,8 @@ describe('ConstantConstrainer', () => { 'TestEnumType', [new ConstrainedEnumValueModel('testKey', 'testValue', 'testValue')] ) - ) + ), + options: JavaGenerator.defaultOptions }); expect(constrainedConstant).toEqual('TestRefType.testKey'); }); @@ -53,7 +56,8 @@ describe('ConstantConstrainer', () => { { const: { originalInput: 'testValue' } }, 'TestEnumType', [new ConstrainedEnumValueModel('testKey', 'testValue', 'testValue')] - ) + ), + options: JavaGenerator.defaultOptions }); expect(constrainedConstant).toEqual('TestEnumType.testKey'); }); @@ -67,7 +71,8 @@ describe('ConstantConstrainer', () => { undefined, { const: { originalInput: 'testValue' } }, 'String' - ) + ), + options: JavaGenerator.defaultOptions }); expect(constrainedConstant).toEqual('"testValue"'); }); diff --git a/test/generators/java/constrainer/EnumConstrainer.spec.ts b/test/generators/java/constrainer/EnumConstrainer.spec.ts index 0741014e53..fc0155cde1 100644 --- a/test/generators/java/constrainer/EnumConstrainer.spec.ts +++ b/test/generators/java/constrainer/EnumConstrainer.spec.ts @@ -2,7 +2,8 @@ import { JavaDefaultConstraints } from '../../../../src/generators/java/JavaCons import { EnumModel } from '../../../../src/models/MetaModel'; import { ConstrainedEnumModel, - ConstrainedEnumValueModel + ConstrainedEnumValueModel, + JavaGenerator } from '../../../../src'; import { defaultEnumKeyConstraints, @@ -24,7 +25,8 @@ describe('EnumConstrainer', () => { const constrainedKey = JavaDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '%' + enumKey: '%', + options: JavaGenerator.defaultOptions }); expect(constrainedKey).toEqual('PERCENT'); }); @@ -32,7 +34,8 @@ describe('EnumConstrainer', () => { const constrainedKey = JavaDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '1' + enumKey: '1', + options: JavaGenerator.defaultOptions }); expect(constrainedKey).toEqual('NUMBER_1'); }); @@ -52,7 +55,8 @@ describe('EnumConstrainer', () => { const constrainedKey = JavaDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: JavaGenerator.defaultOptions }); expect(constrainedKey).toEqual('RESERVED_EMPTY'); }); @@ -60,7 +64,8 @@ describe('EnumConstrainer', () => { const constrainedKey = JavaDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: JavaGenerator.defaultOptions }); expect(constrainedKey).toEqual('EMPTY'); }); @@ -68,7 +73,8 @@ describe('EnumConstrainer', () => { const constrainedKey = JavaDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: 'some weird_value!"#2' + enumKey: 'some weird_value!"#2', + options: JavaGenerator.defaultOptions }); expect(constrainedKey).toEqual( 'SOME_WEIRD_VALUE_EXCLAMATION_QUOTATION_HASH_2' @@ -78,7 +84,8 @@ describe('EnumConstrainer', () => { const constrainedKey = JavaDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: 'return' + enumKey: 'return', + options: JavaGenerator.defaultOptions }); expect(constrainedKey).toEqual('RESERVED_RETURN'); }); @@ -88,7 +95,8 @@ describe('EnumConstrainer', () => { const constrainedValue = JavaDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: 'string value' + enumValue: 'string value', + options: JavaGenerator.defaultOptions }); expect(constrainedValue).toEqual('"string value"'); }); @@ -96,7 +104,8 @@ describe('EnumConstrainer', () => { const constrainedValue = JavaDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: true + enumValue: true, + options: JavaGenerator.defaultOptions }); expect(constrainedValue).toEqual('"true"'); }); @@ -104,7 +113,8 @@ describe('EnumConstrainer', () => { const constrainedValue = JavaDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: 123 + enumValue: 123, + options: JavaGenerator.defaultOptions }); expect(constrainedValue).toEqual(123); }); @@ -112,7 +122,8 @@ describe('EnumConstrainer', () => { const constrainedValue = JavaDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: { test: 'test' } + enumValue: { test: 'test' }, + options: JavaGenerator.defaultOptions }); expect(constrainedValue).toEqual('"{\\"test\\":\\"test\\"}"'); }); @@ -120,7 +131,8 @@ describe('EnumConstrainer', () => { const constrainedValue = JavaDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: undefined + enumValue: undefined, + options: JavaGenerator.defaultOptions }); expect(constrainedValue).toEqual('"undefined"'); }); @@ -137,7 +149,12 @@ describe('EnumConstrainer', () => { const constrainFunction = defaultEnumKeyConstraints( mockedConstraintCallbacks ); - constrainFunction({ enumModel, constrainedEnumModel, enumKey: '' }); + constrainFunction({ + enumModel, + constrainedEnumModel, + enumKey: '', + options: JavaGenerator.defaultOptions + }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { expect(jestMockCallback).toHaveBeenCalled(); @@ -159,7 +176,8 @@ describe('EnumConstrainer', () => { const constrainedValue = constrainFunction({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: JavaGenerator.defaultOptions }); expect(constrainedValue).toEqual(''); for (const jestMockCallback of spies) { diff --git a/test/generators/java/constrainer/ModelNameConstrainer.spec.ts b/test/generators/java/constrainer/ModelNameConstrainer.spec.ts index 11f7eaa8f5..c483754a64 100644 --- a/test/generators/java/constrainer/ModelNameConstrainer.spec.ts +++ b/test/generators/java/constrainer/ModelNameConstrainer.spec.ts @@ -1,3 +1,4 @@ +import { JavaGenerator } from '../../../../src'; import { JavaDefaultConstraints } from '../../../../src/generators/java/JavaConstrainer'; import { DefaultModelNameConstraints, @@ -6,26 +7,37 @@ import { } from '../../../../src/generators/java/constrainer/ModelNameConstrainer'; describe('ModelNameConstrainer', () => { test('should never render special chars', () => { - const constrainedKey = JavaDefaultConstraints.modelName({ modelName: '%' }); + const constrainedKey = JavaDefaultConstraints.modelName({ + modelName: '%', + options: JavaGenerator.defaultOptions + }); expect(constrainedKey).toEqual('Percent'); }); test('should never render number as start char', () => { - const constrainedKey = JavaDefaultConstraints.modelName({ modelName: '1' }); + const constrainedKey = JavaDefaultConstraints.modelName({ + modelName: '1', + options: JavaGenerator.defaultOptions + }); expect(constrainedKey).toEqual('Number_1'); }); test('should never contain empty name', () => { - const constrainedKey = JavaDefaultConstraints.modelName({ modelName: '' }); + const constrainedKey = JavaDefaultConstraints.modelName({ + modelName: '', + options: JavaGenerator.defaultOptions + }); expect(constrainedKey).toEqual('Empty'); }); test('should use constant naming format', () => { const constrainedKey = JavaDefaultConstraints.modelName({ - modelName: 'some weird_value!"#2' + modelName: 'some weird_value!"#2', + options: JavaGenerator.defaultOptions }); expect(constrainedKey).toEqual('SomeWeirdValueExclamationQuotationHash_2'); }); test('should never render reserved keywords', () => { const constrainedKey = JavaDefaultConstraints.modelName({ - modelName: 'return' + modelName: 'return', + options: JavaGenerator.defaultOptions }); expect(constrainedKey).toEqual('ReservedReturn'); }); @@ -41,7 +53,10 @@ describe('ModelNameConstrainer', () => { const constrainFunction = defaultModelNameConstraints( mockedConstraintCallbacks ); - constrainFunction({ modelName: '' }); + constrainFunction({ + modelName: '', + options: JavaGenerator.defaultOptions + }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { expect(jestMockCallback).toHaveBeenCalled(); @@ -59,7 +74,10 @@ describe('ModelNameConstrainer', () => { const constrainFunction = defaultModelNameConstraints({ NAMING_FORMATTER: jestCallback }); - const constrainedValue = constrainFunction({ modelName: '' }); + const constrainedValue = constrainFunction({ + modelName: '', + options: JavaGenerator.defaultOptions + }); expect(constrainedValue).toEqual(''); for (const jestMockCallback of spies) { expect(jestMockCallback).toHaveBeenCalled(); diff --git a/test/generators/java/constrainer/PropertyKeyConstrainer.spec.ts b/test/generators/java/constrainer/PropertyKeyConstrainer.spec.ts index 3338834422..21e10256e1 100644 --- a/test/generators/java/constrainer/PropertyKeyConstrainer.spec.ts +++ b/test/generators/java/constrainer/PropertyKeyConstrainer.spec.ts @@ -2,6 +2,7 @@ import { JavaDefaultConstraints } from '../../../../src/generators/java/JavaCons import { ConstrainedObjectModel, ConstrainedObjectPropertyModel, + JavaGenerator, ObjectModel, ObjectPropertyModel } from '../../../../src'; @@ -36,7 +37,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: JavaGenerator.defaultOptions }); }; afterEach(() => { @@ -98,7 +100,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel: objectPropertyModel2, - constrainedObjectPropertyModel: constrainedObjectPropertyModel2 + constrainedObjectPropertyModel: constrainedObjectPropertyModel2, + options: JavaGenerator.defaultOptions }); expect(constrainedKey).toEqual('reservedReservedReturn'); }); @@ -133,7 +136,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: JavaGenerator.defaultOptions }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { @@ -172,7 +176,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: JavaGenerator.defaultOptions }); expect(constrainedValue).toEqual(''); expect(jestCallback).toHaveBeenCalled(); diff --git a/test/generators/javascript/constrainer/EnumConstrainer.spec.ts b/test/generators/javascript/constrainer/EnumConstrainer.spec.ts index 53e11edcec..829db1c6bb 100644 --- a/test/generators/javascript/constrainer/EnumConstrainer.spec.ts +++ b/test/generators/javascript/constrainer/EnumConstrainer.spec.ts @@ -2,7 +2,8 @@ import { JavaScriptDefaultConstraints } from '../../../../src/generators/javascr import { EnumModel } from '../../../../src/models/MetaModel'; import { ConstrainedEnumModel, - ConstrainedEnumValueModel + ConstrainedEnumValueModel, + JavaScriptGenerator } from '../../../../src'; describe('EnumConstrainer', () => { const enumModel = new EnumModel('test', undefined, {}, []); @@ -19,7 +20,8 @@ describe('EnumConstrainer', () => { const constrainedKey = JavaScriptDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '%' + enumKey: '%', + options: JavaScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('%'); }); @@ -27,7 +29,8 @@ describe('EnumConstrainer', () => { const constrainedKey = JavaScriptDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '1' + enumKey: '1', + options: JavaScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('1'); }); @@ -47,7 +50,8 @@ describe('EnumConstrainer', () => { const constrainedKey = JavaScriptDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: JavaScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual(''); }); @@ -55,7 +59,8 @@ describe('EnumConstrainer', () => { const constrainedKey = JavaScriptDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: JavaScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual(''); }); @@ -63,7 +68,8 @@ describe('EnumConstrainer', () => { const constrainedKey = JavaScriptDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: 'some weird_value!"#2' + enumKey: 'some weird_value!"#2', + options: JavaScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('some weird_value!"#2'); }); @@ -71,7 +77,8 @@ describe('EnumConstrainer', () => { const constrainedKey = JavaScriptDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: 'return' + enumKey: 'return', + options: JavaScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('return'); }); @@ -81,7 +88,8 @@ describe('EnumConstrainer', () => { const constrainedValue = JavaScriptDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: 'string value' + enumValue: 'string value', + options: JavaScriptGenerator.defaultOptions }); expect(constrainedValue).toEqual('string value'); }); @@ -89,7 +97,8 @@ describe('EnumConstrainer', () => { const constrainedValue = JavaScriptDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: true + enumValue: true, + options: JavaScriptGenerator.defaultOptions }); expect(constrainedValue).toEqual(true); }); @@ -97,7 +106,8 @@ describe('EnumConstrainer', () => { const constrainedValue = JavaScriptDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: 123 + enumValue: 123, + options: JavaScriptGenerator.defaultOptions }); expect(constrainedValue).toEqual(123); }); @@ -105,7 +115,8 @@ describe('EnumConstrainer', () => { const constrainedValue = JavaScriptDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: { test: 'test' } + enumValue: { test: 'test' }, + options: JavaScriptGenerator.defaultOptions }); expect(constrainedValue).toEqual({ test: 'test' }); }); @@ -113,7 +124,8 @@ describe('EnumConstrainer', () => { const constrainedValue = JavaScriptDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: undefined + enumValue: undefined, + options: JavaScriptGenerator.defaultOptions }); expect(constrainedValue).toEqual(undefined); }); diff --git a/test/generators/javascript/constrainer/ModelNameConstrainer.spec.ts b/test/generators/javascript/constrainer/ModelNameConstrainer.spec.ts index 5cae1a39f8..c11dd2de0b 100644 --- a/test/generators/javascript/constrainer/ModelNameConstrainer.spec.ts +++ b/test/generators/javascript/constrainer/ModelNameConstrainer.spec.ts @@ -1,3 +1,4 @@ +import { JavaScriptGenerator } from '../../../../src'; import { JavaScriptDefaultConstraints } from '../../../../src/generators/javascript/JavaScriptConstrainer'; import { DefaultModelNameConstraints, @@ -7,31 +8,36 @@ import { describe('ModelNameConstrainer', () => { test('should never render special chars', () => { const constrainedKey = JavaScriptDefaultConstraints.modelName({ - modelName: '%' + modelName: '%', + options: JavaScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('Percent'); }); test('should never render number as start char', () => { const constrainedKey = JavaScriptDefaultConstraints.modelName({ - modelName: '1' + modelName: '1', + options: JavaScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('Number_1'); }); test('should never contain empty name', () => { const constrainedKey = JavaScriptDefaultConstraints.modelName({ - modelName: '' + modelName: '', + options: JavaScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('Empty'); }); test('should use constant naming format', () => { const constrainedKey = JavaScriptDefaultConstraints.modelName({ - modelName: 'some weird_value!"#2' + modelName: 'some weird_value!"#2', + options: JavaScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('SomeWeirdValueExclamationQuotationHash_2'); }); test('should never render reserved keywords', () => { const constrainedKey = JavaScriptDefaultConstraints.modelName({ - modelName: 'return' + modelName: 'return', + options: JavaScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('ReservedReturn'); }); @@ -47,7 +53,10 @@ describe('ModelNameConstrainer', () => { const constrainFunction = defaultModelNameConstraints( mockedConstraintCallbacks ); - constrainFunction({ modelName: '' }); + constrainFunction({ + modelName: '', + options: JavaScriptGenerator.defaultOptions + }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { expect(jestMockCallback).toHaveBeenCalled(); @@ -65,7 +74,10 @@ describe('ModelNameConstrainer', () => { const constrainFunction = defaultModelNameConstraints({ NAMING_FORMATTER: jestCallback }); - const constrainedValue = constrainFunction({ modelName: '' }); + const constrainedValue = constrainFunction({ + modelName: '', + options: JavaScriptGenerator.defaultOptions + }); expect(constrainedValue).toEqual(''); for (const jestMockCallback of spies) { expect(jestMockCallback).toHaveBeenCalled(); diff --git a/test/generators/javascript/constrainer/PropertyKeyConstrainer.spec.ts b/test/generators/javascript/constrainer/PropertyKeyConstrainer.spec.ts index 330e8c36a6..b89881baf6 100644 --- a/test/generators/javascript/constrainer/PropertyKeyConstrainer.spec.ts +++ b/test/generators/javascript/constrainer/PropertyKeyConstrainer.spec.ts @@ -2,6 +2,7 @@ import { JavaScriptDefaultConstraints } from '../../../../src/generators/javascr import { ConstrainedObjectModel, ConstrainedObjectPropertyModel, + JavaScriptGenerator, ObjectModel, ObjectPropertyModel } from '../../../../src'; @@ -36,7 +37,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: JavaScriptGenerator.defaultOptions }); }; @@ -95,7 +97,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel: objectPropertyModel2, - constrainedObjectPropertyModel: constrainedObjectPropertyModel2 + constrainedObjectPropertyModel: constrainedObjectPropertyModel2, + options: JavaScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('reservedReservedReturn'); }); @@ -130,7 +133,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: JavaScriptGenerator.defaultOptions }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { @@ -169,7 +173,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: JavaScriptGenerator.defaultOptions }); expect(constrainedValue).toEqual(''); expect(jestCallback).toHaveBeenCalled(); diff --git a/test/generators/javascript/preset/utils/ExampleFunctions.spec.ts b/test/generators/javascript/preset/utils/ExampleFunctions.spec.ts index ee3a16cf79..a433dbc8f6 100644 --- a/test/generators/javascript/preset/utils/ExampleFunctions.spec.ts +++ b/test/generators/javascript/preset/utils/ExampleFunctions.spec.ts @@ -1,6 +1,5 @@ import { renderValueFromModel } from '../../../../../src/generators/javascript/presets/utils/ExampleFunction'; import { - CommonModel, ConstrainedAnyModel, ConstrainedArrayModel, ConstrainedBooleanModel, diff --git a/test/generators/kotlin/KotlinRenderer.spec.ts b/test/generators/kotlin/KotlinRenderer.spec.ts index b71827f6cb..7eb33d2cd1 100644 --- a/test/generators/kotlin/KotlinRenderer.spec.ts +++ b/test/generators/kotlin/KotlinRenderer.spec.ts @@ -2,7 +2,6 @@ import { KotlinGenerator } from '../../../src/generators/kotlin'; import { KotlinRenderer } from '../../../src/generators/kotlin/KotlinRenderer'; import { ConstrainedObjectModel, InputMetaModel } from '../../../src/models'; import { MockKotlinRenderer } from '../../TestUtils/TestRenderers'; -import { prefix } from 'concurrently/dist/src/defaults'; describe('KotlinRenderer', () => { let renderer: KotlinRenderer; diff --git a/test/generators/rust/RustConstrainer.spec.ts b/test/generators/rust/RustConstrainer.spec.ts index 9273e10c2c..2fd738756f 100644 --- a/test/generators/rust/RustConstrainer.spec.ts +++ b/test/generators/rust/RustConstrainer.spec.ts @@ -20,9 +20,7 @@ import { ConstrainedTupleModel, ConstrainedUnionModel, RustGenerator, - RustOptions, - ConstrainedObjectPropertyModel, - ConstrainedMetaModel + ConstrainedObjectPropertyModel } from '../../../src'; import { RustDependencyManager } from '../../../src/generators/rust/RustDependencyManager'; describe('RustConstrainer', () => { diff --git a/test/generators/rust/RustRenderer.spec.ts b/test/generators/rust/RustRenderer.spec.ts index 88cd4ef2e1..434713beb3 100644 --- a/test/generators/rust/RustRenderer.spec.ts +++ b/test/generators/rust/RustRenderer.spec.ts @@ -1,7 +1,6 @@ import { RustGenerator } from '../../../src/generators'; import { RustRenderer } from '../../../src/generators/rust/RustRenderer'; import { - CommonModel, ConstrainedObjectModel, ConstrainedEnumModel, ConstrainedStringModel, diff --git a/test/generators/rust/constrainer/EnumConstrainer.spec.ts b/test/generators/rust/constrainer/EnumConstrainer.spec.ts index 7c70f115ad..ec8f433a57 100644 --- a/test/generators/rust/constrainer/EnumConstrainer.spec.ts +++ b/test/generators/rust/constrainer/EnumConstrainer.spec.ts @@ -3,9 +3,9 @@ import { EnumModel } from '../../../../src/models/MetaModel'; import { ConstrainedEnumModel, ConstrainedEnumValueModel, - EnumKeyConstraint + RustEnumKeyConstraint, + RustGenerator } from '../../../../src'; -import { RESERVED_RUST_KEYWORDS } from '../../../../src/generators/rust/Constants'; import { defaultEnumKeyConstraints } from '../../../../src/generators/rust/constrainer/EnumConstrainer'; describe('EnumConstrainer', () => { const enumModel = new EnumModel('test', undefined, {}, []); @@ -22,7 +22,8 @@ describe('EnumConstrainer', () => { const constrainedKey = RustDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '%' + enumKey: '%', + options: RustGenerator.defaultOptions }); expect(constrainedKey).toEqual('Percent'); }); @@ -30,7 +31,8 @@ describe('EnumConstrainer', () => { const constrainedKey = RustDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '1' + enumKey: '1', + options: RustGenerator.defaultOptions }); expect(constrainedKey).toEqual('Number_1'); }); @@ -50,7 +52,8 @@ describe('EnumConstrainer', () => { const constrainedKey = RustDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: RustGenerator.defaultOptions }); expect(constrainedKey).toEqual('Empty'); }); @@ -58,7 +61,8 @@ describe('EnumConstrainer', () => { const constrainedKey = RustDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: RustGenerator.defaultOptions }); expect(constrainedKey).toEqual('Empty'); }); @@ -66,7 +70,8 @@ describe('EnumConstrainer', () => { const constrainedKey = RustDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: 'some weird_value!"#2' + enumKey: 'some weird_value!"#2', + options: RustGenerator.defaultOptions }); expect(constrainedKey).toEqual( 'SomeWeirdValueExclamationQuotationHash_2' @@ -76,21 +81,23 @@ describe('EnumConstrainer', () => { const constrainedKey = RustDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: 'return' + enumKey: 'return', + options: RustGenerator.defaultOptions }); expect(constrainedKey).toEqual('Return'); }); describe('custom constraints', () => { test('should make sure reserved keywords cannot be rendered', () => { - const customNamingFormat: Partial = { + const customNamingFormat: Partial = { NAMING_FORMATTER: (value) => value }; const constrainFunction = defaultEnumKeyConstraints(customNamingFormat); const constrainedKey = constrainFunction({ enumModel, constrainedEnumModel, - enumKey: 'return' + enumKey: 'return', + options: RustGenerator.defaultOptions }); expect(constrainedKey).toEqual('reserved_return'); }); @@ -101,7 +108,8 @@ describe('EnumConstrainer', () => { const constrainedValue = RustDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: 'string value' + enumValue: 'string value', + options: RustGenerator.defaultOptions }); expect(constrainedValue).toEqual('string value'); }); @@ -109,7 +117,8 @@ describe('EnumConstrainer', () => { const constrainedValue = RustDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: true + enumValue: true, + options: RustGenerator.defaultOptions }); expect(constrainedValue).toEqual(true); }); @@ -117,7 +126,8 @@ describe('EnumConstrainer', () => { const constrainedValue = RustDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: 123 + enumValue: 123, + options: RustGenerator.defaultOptions }); expect(constrainedValue).toEqual(123); }); @@ -125,7 +135,8 @@ describe('EnumConstrainer', () => { const constrainedValue = RustDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: { test: 'test' } + enumValue: { test: 'test' }, + options: RustGenerator.defaultOptions }); expect(constrainedValue).toEqual({ test: 'test' }); }); @@ -133,7 +144,8 @@ describe('EnumConstrainer', () => { const constrainedValue = RustDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: undefined + enumValue: undefined, + options: RustGenerator.defaultOptions }); expect(constrainedValue).toEqual(undefined); }); diff --git a/test/generators/rust/constrainer/ModelNameConstrainer.spec.ts b/test/generators/rust/constrainer/ModelNameConstrainer.spec.ts index e196b5024b..33894480b4 100644 --- a/test/generators/rust/constrainer/ModelNameConstrainer.spec.ts +++ b/test/generators/rust/constrainer/ModelNameConstrainer.spec.ts @@ -1,3 +1,4 @@ +import { RustGenerator } from '../../../../src'; import { RustDefaultConstraints } from '../../../../src/generators/rust/RustConstrainer'; import { defaultModelNameConstraints, @@ -5,26 +6,37 @@ import { } from '../../../../src/generators/rust/constrainer/ModelNameConstrainer'; describe('ModelNameConstrainer', () => { test('should never render special chars', () => { - const constrainedKey = RustDefaultConstraints.modelName({ modelName: '%' }); + const constrainedKey = RustDefaultConstraints.modelName({ + modelName: '%', + options: RustGenerator.defaultOptions + }); expect(constrainedKey).toEqual('Percent'); }); test('should never render number as start char', () => { - const constrainedKey = RustDefaultConstraints.modelName({ modelName: '1' }); + const constrainedKey = RustDefaultConstraints.modelName({ + modelName: '1', + options: RustGenerator.defaultOptions + }); expect(constrainedKey).toEqual('Number1'); }); test('should never contain empty name', () => { - const constrainedKey = RustDefaultConstraints.modelName({ modelName: '' }); + const constrainedKey = RustDefaultConstraints.modelName({ + modelName: '', + options: RustGenerator.defaultOptions + }); expect(constrainedKey).toEqual('Empty'); }); test('should use constant naming format', () => { const constrainedKey = RustDefaultConstraints.modelName({ - modelName: 'some weird_value!"#2' + modelName: 'some weird_value!"#2', + options: RustGenerator.defaultOptions }); expect(constrainedKey).toEqual('SomeWeirdValueExclamationQuotationHash2'); }); test('Reserved keywords should not take effect when naming formatter changes its format', () => { const constrainedKey = RustDefaultConstraints.modelName({ - modelName: 'return' + modelName: 'return', + options: RustGenerator.defaultOptions }); expect(constrainedKey).toEqual('Return'); }); @@ -34,7 +46,10 @@ describe('ModelNameConstrainer', () => { NAMING_FORMATTER: (value) => value }; const constrainFunction = defaultModelNameConstraints(customNamingFormat); - const constrainedKey = constrainFunction({ modelName: 'return' }); + const constrainedKey = constrainFunction({ + modelName: 'return', + options: RustGenerator.defaultOptions + }); expect(constrainedKey).toEqual('reserved_return'); }); }); diff --git a/test/generators/rust/constrainer/PropertyKeyConstrainer.spec.ts b/test/generators/rust/constrainer/PropertyKeyConstrainer.spec.ts index 81ffc61575..b4a6add402 100644 --- a/test/generators/rust/constrainer/PropertyKeyConstrainer.spec.ts +++ b/test/generators/rust/constrainer/PropertyKeyConstrainer.spec.ts @@ -3,7 +3,8 @@ import { ConstrainedObjectModel, ConstrainedObjectPropertyModel, ObjectModel, - ObjectPropertyModel + ObjectPropertyModel, + RustGenerator } from '../../../../src'; describe('PropertyKeyConstrainer', () => { const objectModel = new ObjectModel('test', undefined, {}, {}); @@ -31,7 +32,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: RustGenerator.defaultOptions }); }; @@ -92,7 +94,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel: objectPropertyModel2, - constrainedObjectPropertyModel: constrainedObjectPropertyModel2 + constrainedObjectPropertyModel: constrainedObjectPropertyModel2, + options: RustGenerator.defaultOptions }); expect(constrainedKey).toEqual('reserved_reserved_return'); }); diff --git a/test/generators/typescript/constrainer/ConstantConstrainer.spec.ts b/test/generators/typescript/constrainer/ConstantConstrainer.spec.ts index dcce0beb88..3139b2d0a4 100644 --- a/test/generators/typescript/constrainer/ConstantConstrainer.spec.ts +++ b/test/generators/typescript/constrainer/ConstantConstrainer.spec.ts @@ -2,7 +2,8 @@ import { ConstrainedEnumModel, ConstrainedEnumValueModel, ConstrainedReferenceModel, - ConstrainedStringModel + ConstrainedStringModel, + TypeScriptGenerator } from '../../../../src'; import { defaultConstantConstraints } from '../../../../src/generators/typescript/constrainer/ConstantConstrainer'; @@ -14,7 +15,8 @@ describe('ConstantConstrainer', () => { undefined, {}, 'String' - ) + ), + options: TypeScriptGenerator.defaultOptions }); expect(constrainedConstant).toBeUndefined(); }); @@ -38,7 +40,8 @@ describe('ConstantConstrainer', () => { 'TestEnumType', [new ConstrainedEnumValueModel('testKey', 'testValue', 'testValue')] ) - ) + ), + options: TypeScriptGenerator.defaultOptions }); expect(constrainedConstant).toEqual('TestRefType.testKey'); }); @@ -53,7 +56,8 @@ describe('ConstantConstrainer', () => { { const: { originalInput: 'testValue' } }, 'TestEnumType', [new ConstrainedEnumValueModel('testKey', 'testValue', 'testValue')] - ) + ), + options: TypeScriptGenerator.defaultOptions }); expect(constrainedConstant).toEqual('TestEnumType.testKey'); }); @@ -67,7 +71,8 @@ describe('ConstantConstrainer', () => { undefined, { const: { originalInput: 'testValue' } }, 'String' - ) + ), + options: TypeScriptGenerator.defaultOptions }); expect(constrainedConstant).toEqual("'testValue'"); }); diff --git a/test/generators/typescript/constrainer/EnumConstrainer.spec.ts b/test/generators/typescript/constrainer/EnumConstrainer.spec.ts index 561436cfda..56314455bb 100644 --- a/test/generators/typescript/constrainer/EnumConstrainer.spec.ts +++ b/test/generators/typescript/constrainer/EnumConstrainer.spec.ts @@ -2,7 +2,8 @@ import { TypeScriptDefaultConstraints } from '../../../../src/generators/typescr import { EnumModel } from '../../../../src/models/MetaModel'; import { ConstrainedEnumModel, - ConstrainedEnumValueModel + ConstrainedEnumValueModel, + TypeScriptGenerator } from '../../../../src'; import { defaultEnumKeyConstraints, @@ -24,7 +25,8 @@ describe('EnumConstrainer', () => { const constrainedKey = TypeScriptDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '%' + enumKey: '%', + options: TypeScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('PERCENT'); }); @@ -32,7 +34,8 @@ describe('EnumConstrainer', () => { const constrainedKey = TypeScriptDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '1' + enumKey: '1', + options: TypeScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('NUMBER_1'); }); @@ -52,7 +55,8 @@ describe('EnumConstrainer', () => { const constrainedKey = TypeScriptDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: TypeScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('RESERVED_EMPTY'); }); @@ -60,7 +64,8 @@ describe('EnumConstrainer', () => { const constrainedKey = TypeScriptDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: TypeScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('EMPTY'); }); @@ -68,7 +73,8 @@ describe('EnumConstrainer', () => { const constrainedKey = TypeScriptDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: 'some weird_value!"#2' + enumKey: 'some weird_value!"#2', + options: TypeScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual( 'SOME_SPACE_WEIRD_VALUE_EXCLAMATION_QUOTATION_HASH_2' @@ -78,7 +84,8 @@ describe('EnumConstrainer', () => { const constrainedKey = TypeScriptDefaultConstraints.enumKey({ enumModel, constrainedEnumModel, - enumKey: 'return' + enumKey: 'return', + options: TypeScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('RESERVED_RETURN'); }); @@ -88,7 +95,8 @@ describe('EnumConstrainer', () => { const constrainedValue = TypeScriptDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: 'string value' + enumValue: 'string value', + options: TypeScriptGenerator.defaultOptions }); expect(constrainedValue).toEqual('"string value"'); }); @@ -96,7 +104,8 @@ describe('EnumConstrainer', () => { const constrainedValue = TypeScriptDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: true + enumValue: true, + options: TypeScriptGenerator.defaultOptions }); expect(constrainedValue).toEqual('"true"'); }); @@ -104,7 +113,8 @@ describe('EnumConstrainer', () => { const constrainedValue = TypeScriptDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: 123 + enumValue: 123, + options: TypeScriptGenerator.defaultOptions }); expect(constrainedValue).toEqual('123'); }); @@ -112,7 +122,8 @@ describe('EnumConstrainer', () => { const constrainedValue = TypeScriptDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: { test: 'test' } + enumValue: { test: 'test' }, + options: TypeScriptGenerator.defaultOptions }); expect(constrainedValue).toEqual('\'{"test":"test"}\''); }); @@ -120,7 +131,8 @@ describe('EnumConstrainer', () => { const constrainedValue = TypeScriptDefaultConstraints.enumValue({ enumModel, constrainedEnumModel, - enumValue: undefined + enumValue: undefined, + options: TypeScriptGenerator.defaultOptions }); expect(constrainedValue).toEqual('undefined'); }); @@ -137,7 +149,12 @@ describe('EnumConstrainer', () => { const constrainFunction = defaultEnumKeyConstraints( mockedConstraintCallbacks ); - constrainFunction({ enumModel, constrainedEnumModel, enumKey: '' }); + constrainFunction({ + enumModel, + constrainedEnumModel, + enumKey: '', + options: TypeScriptGenerator.defaultOptions + }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { expect(jestMockCallback).toHaveBeenCalled(); @@ -159,7 +176,8 @@ describe('EnumConstrainer', () => { const constrainedValue = constrainFunction({ enumModel, constrainedEnumModel, - enumKey: '' + enumKey: '', + options: TypeScriptGenerator.defaultOptions }); expect(constrainedValue).toEqual(''); for (const jestMockCallback of spies) { diff --git a/test/generators/typescript/constrainer/ModelNameConstrainer.spec.ts b/test/generators/typescript/constrainer/ModelNameConstrainer.spec.ts index 11bcd88ba5..063ca8336f 100644 --- a/test/generators/typescript/constrainer/ModelNameConstrainer.spec.ts +++ b/test/generators/typescript/constrainer/ModelNameConstrainer.spec.ts @@ -1,3 +1,4 @@ +import { TypeScriptGenerator } from '../../../../src'; import { TypeScriptDefaultConstraints } from '../../../../src/generators/typescript/TypeScriptConstrainer'; import { DefaultModelNameConstraints, @@ -7,31 +8,36 @@ import { describe('ModelNameConstrainer', () => { test('should never render special chars', () => { const constrainedKey = TypeScriptDefaultConstraints.modelName({ - modelName: '%' + modelName: '%', + options: TypeScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('Percent'); }); test('should never render number as start char', () => { const constrainedKey = TypeScriptDefaultConstraints.modelName({ - modelName: '1' + modelName: '1', + options: TypeScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('Number_1'); }); test('should never contain empty name', () => { const constrainedKey = TypeScriptDefaultConstraints.modelName({ - modelName: '' + modelName: '', + options: TypeScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('Empty'); }); test('should use constant naming format', () => { const constrainedKey = TypeScriptDefaultConstraints.modelName({ - modelName: 'some weird_value!"#2' + modelName: 'some weird_value!"#2', + options: TypeScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('SomeWeirdValueExclamationQuotationHash_2'); }); test('should never render reserved keywords', () => { const constrainedKey = TypeScriptDefaultConstraints.modelName({ - modelName: 'return' + modelName: 'return', + options: TypeScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('ReservedReturn'); }); @@ -47,7 +53,10 @@ describe('ModelNameConstrainer', () => { const constrainFunction = defaultModelNameConstraints( mockedConstraintCallbacks ); - constrainFunction({ modelName: '' }); + constrainFunction({ + modelName: '', + options: TypeScriptGenerator.defaultOptions + }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { expect(jestMockCallback).toHaveBeenCalled(); @@ -65,7 +74,10 @@ describe('ModelNameConstrainer', () => { const constrainFunction = defaultModelNameConstraints({ NAMING_FORMATTER: jestCallback }); - const constrainedValue = constrainFunction({ modelName: '' }); + const constrainedValue = constrainFunction({ + modelName: '', + options: TypeScriptGenerator.defaultOptions + }); expect(constrainedValue).toEqual(''); for (const jestMockCallback of spies) { expect(jestMockCallback).toHaveBeenCalled(); diff --git a/test/generators/typescript/constrainer/PropertyKeyConstrainer.spec.ts b/test/generators/typescript/constrainer/PropertyKeyConstrainer.spec.ts index ef9198919b..e893e40a86 100644 --- a/test/generators/typescript/constrainer/PropertyKeyConstrainer.spec.ts +++ b/test/generators/typescript/constrainer/PropertyKeyConstrainer.spec.ts @@ -3,7 +3,8 @@ import { ConstrainedObjectModel, ConstrainedObjectPropertyModel, ObjectModel, - ObjectPropertyModel + ObjectPropertyModel, + TypeScriptGenerator } from '../../../../src'; import { DefaultPropertyKeyConstraints, @@ -36,7 +37,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: TypeScriptGenerator.defaultOptions }); }; @@ -95,7 +97,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel: objectPropertyModel2, - constrainedObjectPropertyModel: constrainedObjectPropertyModel2 + constrainedObjectPropertyModel: constrainedObjectPropertyModel2, + options: TypeScriptGenerator.defaultOptions }); expect(constrainedKey).toEqual('reservedReservedReturn'); }); @@ -130,7 +133,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: TypeScriptGenerator.defaultOptions }); //Expect all callbacks to be called for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) { @@ -169,7 +173,8 @@ describe('PropertyKeyConstrainer', () => { constrainedObjectModel, objectModel, objectPropertyModel, - constrainedObjectPropertyModel + constrainedObjectPropertyModel, + options: TypeScriptGenerator.defaultOptions }); expect(constrainedValue).toEqual(''); expect(jestCallback).toHaveBeenCalled(); diff --git a/test/generators/typescript/preset/utils/ExampleFunctions.spec.ts b/test/generators/typescript/preset/utils/ExampleFunctions.spec.ts index 9f681fbd21..1859280b2e 100644 --- a/test/generators/typescript/preset/utils/ExampleFunctions.spec.ts +++ b/test/generators/typescript/preset/utils/ExampleFunctions.spec.ts @@ -1,6 +1,5 @@ import { renderValueFromModel } from '../../../../../src/generators/typescript/presets/utils/ExampleFunction'; import { - CommonModel, ConstrainedAnyModel, ConstrainedArrayModel, ConstrainedBooleanModel, diff --git a/test/helpers/TypeHelpers.spec.ts b/test/helpers/TypeHelpers.spec.ts index 13df93ac86..c57d89efa6 100644 --- a/test/helpers/TypeHelpers.spec.ts +++ b/test/helpers/TypeHelpers.spec.ts @@ -1,6 +1,5 @@ import { getTypeFromMapping, TypeMapping } from '../../src/helpers'; import { - CommonModel, ConstrainedAnyModel, ConstrainedArrayModel, ConstrainedBooleanModel, @@ -10,7 +9,6 @@ import { ConstrainedIntegerModel, ConstrainedMetaModel, ConstrainedObjectModel, - ConstrainedObjectPropertyModel, ConstrainedReferenceModel, ConstrainedStringModel, ConstrainedTupleModel, diff --git a/test/models/OutputModel.spec.ts b/test/models/OutputModel.spec.ts index c4a65b2c9f..5a427df586 100644 --- a/test/models/OutputModel.spec.ts +++ b/test/models/OutputModel.spec.ts @@ -1,6 +1,5 @@ import { InputMetaModel, - CommonModel, ToOutputModelArg, OutputModel, ConstrainedAnyModel diff --git a/test/processors/InputProcessor.spec.ts b/test/processors/InputProcessor.spec.ts index 1e9e61bb59..f09b22eeb2 100644 --- a/test/processors/InputProcessor.spec.ts +++ b/test/processors/InputProcessor.spec.ts @@ -6,8 +6,7 @@ import { AsyncAPIInputProcessor, JsonSchemaInputProcessor, InputProcessor, - SwaggerInputProcessor, - TypeScriptInputProcessor + SwaggerInputProcessor } from '../../src/processors'; import { OpenAPIInputProcessor } from '../../src/processors/OpenAPIInputProcessor'; diff --git a/test/processors/JsonSchemaInputProcessor.spec.ts b/test/processors/JsonSchemaInputProcessor.spec.ts index 769ad658f6..73737ae515 100644 --- a/test/processors/JsonSchemaInputProcessor.spec.ts +++ b/test/processors/JsonSchemaInputProcessor.spec.ts @@ -1,7 +1,7 @@ import * as fs from 'fs'; import * as path from 'path'; import { JsonSchemaInputProcessor } from '../../src/processors/JsonSchemaInputProcessor'; -import { AnyModel, CommonModel, StringModel } from '../../src/models'; +import { AnyModel, CommonModel } from '../../src/models'; jest.mock('../../src/utils/LoggingInterface'); jest.spyOn(JsonSchemaInputProcessor, 'convertSchemaToCommonModel'); let mockedReturnModels = [new CommonModel()];