Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Apr 18, 2024
1 parent 968a55f commit c6a8d72
Show file tree
Hide file tree
Showing 32 changed files with 1,566 additions and 734 deletions.
7 changes: 7 additions & 0 deletions docs/migrations/version-3-to-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

This document contain all the breaking changes and migrations guidelines for adapting your code to the new version.

## Rewrite of how types are determined

In v3 and below, there was a edge case where a type could not be determined IF it was a cyclic model that was NOT split out into separate models. This change affects all generators to various degrees.

For example


## Deprecation of `processor.interpreter`

Since the early days we had the option to set `processorOptions.interpreter` options to change how JSON Schema is interpreted to Meta models. However, these options are more accurately part of the `processorOptions.jsonSchema` options.
Expand Down
24 changes: 23 additions & 1 deletion src/generators/cplusplus/CplusplusGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import {
defaultGeneratorOptions
} from '../AbstractGenerator';
import {
ConstrainedAnyModel,
ConstrainedBooleanModel,
ConstrainedEnumModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedMetaModel,
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedStringModel,
InputMetaModel,
MetaModel,
RenderOutput
Expand Down Expand Up @@ -52,6 +58,21 @@ export type CplusplusPropertyKeyConstraint =

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface CplusplusRenderCompleteModelOptions {}

/**
* All the constrained models that do not depend on others to determine the type
*/
const SAFE_MODEL_TYPES: any[] = [
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedAnyModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedStringModel,
ConstrainedBooleanModel,
ConstrainedEnumModel
];

export class CplusplusGenerator extends AbstractGenerator<
CplusplusOptions,
CplusplusRenderCompleteModelOptions
Expand Down Expand Up @@ -126,7 +147,8 @@ export class CplusplusGenerator extends AbstractGenerator<
dependencyManager: dependencyManagerToUse,
options: this.options,
constrainedName: '' //This is just a placeholder, it will be constrained within the function
}
},
SAFE_MODEL_TYPES
);
}

Expand Down
25 changes: 24 additions & 1 deletion src/generators/csharp/CSharpGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ import {
defaultGeneratorOptions
} from '../AbstractGenerator';
import {
ConstrainedAnyModel,
ConstrainedBooleanModel,
ConstrainedEnumModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedMetaModel,
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedStringModel,
ConstrainedUnionModel,
InputMetaModel,
MetaModel,
RenderOutput
Expand Down Expand Up @@ -61,6 +68,21 @@ export interface CSharpRenderCompleteModelOptions {
namespace: string;
}

/**
* All the constrained models that do not depend on others to determine the type
*/
const SAFE_MODEL_TYPES: any[] = [
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedAnyModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedStringModel,
ConstrainedBooleanModel,
ConstrainedEnumModel,
ConstrainedUnionModel
];

/**
* Generator for CSharp
*/
Expand Down Expand Up @@ -144,7 +166,8 @@ export class CSharpGenerator extends AbstractGenerator<
dependencyManager: dependencyManagerToUse,
options: this.options,
constrainedName: '' //This is just a placeholder, it will be constrained within the function,
}
},
SAFE_MODEL_TYPES
);
}

Expand Down
29 changes: 27 additions & 2 deletions src/generators/dart/DartGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ import {
MetaModel,
ConstrainedObjectModel,
ConstrainedEnumModel,
InputMetaModel
InputMetaModel,
ConstrainedAnyModel,
ConstrainedBooleanModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedReferenceModel,
ConstrainedStringModel,
ConstrainedTupleModel,
ConstrainedUnionModel
} from '../../models';
import {
ConstantConstraint,
Expand Down Expand Up @@ -52,6 +60,22 @@ export interface DartRenderCompleteModelOptions {
packageName: string;
}

/**
* All the constrained models that do not depend on others to determine the type
*/
const SAFE_MODEL_TYPES: any[] = [
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedAnyModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedStringModel,
ConstrainedBooleanModel,
ConstrainedTupleModel,
ConstrainedEnumModel,
ConstrainedUnionModel
];

export class DartGenerator extends AbstractGenerator<
DartOptions,
DartRenderCompleteModelOptions
Expand Down Expand Up @@ -123,7 +147,8 @@ export class DartGenerator extends AbstractGenerator<
dependencyManager: dependencyManagerToUse,
options: this.options,
constrainedName: '' //This is just a placeholder, it will be constrained within the function
}
},
SAFE_MODEL_TYPES
);
}
/**
Expand Down
27 changes: 25 additions & 2 deletions src/generators/go/GoGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ import {
ConstrainedObjectModel,
ConstrainedEnumModel,
ConstrainedMetaModel,
MetaModel
MetaModel,
ConstrainedAnyModel,
ConstrainedBooleanModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedReferenceModel,
ConstrainedStringModel,
ConstrainedTupleModel
} from '../../models';
import {
ConstantConstraint,
Expand Down Expand Up @@ -48,6 +55,21 @@ export interface GoRenderCompleteModelOptions {
packageName: string;
}

/**
* All the constrained models that do not depend on others to determine the type
*/
const SAFE_MODEL_TYPES: any[] = [
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedAnyModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedStringModel,
ConstrainedBooleanModel,
ConstrainedTupleModel,
ConstrainedEnumModel
];

/**
* Generator for Go
*/
Expand Down Expand Up @@ -121,7 +143,8 @@ export class GoGenerator extends AbstractGenerator<
dependencyManager: dependencyManagerToUse,
options: this.options,
constrainedName: '' //This is just a placeholder, it will be constrained within the function
}
},
SAFE_MODEL_TYPES
);
}

Expand Down
27 changes: 26 additions & 1 deletion src/generators/java/JavaGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ import {
defaultGeneratorOptions
} from '../AbstractGenerator';
import {
ConstrainedAnyModel,
ConstrainedBooleanModel,
ConstrainedEnumModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedMetaModel,
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedStringModel,
ConstrainedTupleModel,
ConstrainedUnionModel,
InputMetaModel,
MetaModel,
Expand Down Expand Up @@ -54,6 +61,23 @@ export type JavaTypeMapping = TypeMapping<JavaOptions, JavaDependencyManager>;
export interface JavaRenderCompleteModelOptions {
packageName: string;
}

/**
* All the constrained models that do not depend on others to determine the type
*/
const SAFE_MODEL_TYPES: any[] = [
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedAnyModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedStringModel,
ConstrainedBooleanModel,
ConstrainedTupleModel,
ConstrainedEnumModel,
ConstrainedUnionModel
];

export class JavaGenerator extends AbstractGenerator<
JavaOptions,
JavaRenderCompleteModelOptions
Expand Down Expand Up @@ -126,7 +150,8 @@ export class JavaGenerator extends AbstractGenerator<
dependencyManager: dependencyManagerToUse,
options: this.options,
constrainedName: '' //This is just a placeholder, it will be constrained within the function
}
},
SAFE_MODEL_TYPES
);
}

Expand Down
32 changes: 31 additions & 1 deletion src/generators/javascript/JavaScriptGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@ import {
defaultGeneratorOptions
} from '../AbstractGenerator';
import {
ConstrainedAnyModel,
ConstrainedArrayModel,
ConstrainedBooleanModel,
ConstrainedDictionaryModel,
ConstrainedEnumModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedMetaModel,
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedStringModel,
ConstrainedTupleModel,
ConstrainedUnionModel,
InputMetaModel,
MetaModel,
RenderOutput
Expand Down Expand Up @@ -55,6 +66,24 @@ export type JavaScriptTypeMapping = TypeMapping<
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface JavaScriptRenderCompleteModelOptions {}

/**
* All the constrained models that do not depend on others to determine the type
*/
const SAFE_MODEL_TYPES: any[] = [
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedAnyModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedStringModel,
ConstrainedBooleanModel,
ConstrainedTupleModel,
ConstrainedArrayModel,
ConstrainedEnumModel,
ConstrainedUnionModel,
ConstrainedDictionaryModel
];

/**
* Generator for JavaScript
*/
Expand Down Expand Up @@ -210,7 +239,8 @@ ${modelCode}`;
dependencyManager: dependencyManagerToUse,
options: this.options,
constrainedName: '' //This is just a placeholder, it will be constrained within the function
}
},
SAFE_MODEL_TYPES
);
}

Expand Down
32 changes: 31 additions & 1 deletion src/generators/kotlin/KotlinGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ import {
defaultGeneratorOptions
} from '../AbstractGenerator';
import {
ConstrainedAnyModel,
ConstrainedArrayModel,
ConstrainedBooleanModel,
ConstrainedDictionaryModel,
ConstrainedEnumModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedMetaModel,
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedStringModel,
ConstrainedTupleModel,
ConstrainedUnionModel,
InputMetaModel,
MetaModel,
RenderOutput
Expand Down Expand Up @@ -52,6 +62,25 @@ export type KotlinTypeMapping = TypeMapping<
export interface KotlinRenderCompleteModelOptions {
packageName: string;
}

/**
* All the constrained models that do not depend on others to determine the type
*/
const SAFE_MODEL_TYPES: any[] = [
ConstrainedObjectModel,
ConstrainedReferenceModel,
ConstrainedAnyModel,
ConstrainedFloatModel,
ConstrainedIntegerModel,
ConstrainedStringModel,
ConstrainedBooleanModel,
ConstrainedTupleModel,
ConstrainedArrayModel,
ConstrainedEnumModel,
ConstrainedUnionModel,
ConstrainedDictionaryModel
];

export class KotlinGenerator extends AbstractGenerator<
KotlinOptions,
KotlinRenderCompleteModelOptions
Expand Down Expand Up @@ -127,7 +156,8 @@ export class KotlinGenerator extends AbstractGenerator<
dependencyManager: dependencyManagerToUse,
options: optionsToUse,
constrainedName: '' //This is just a placeholder, it will be constrained within the function
}
},
SAFE_MODEL_TYPES
);
}

Expand Down
Loading

0 comments on commit c6a8d72

Please sign in to comment.