ts-class-to-openapi 1.0.5 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +368 -882
  2. package/dist/__test__/entities/additional-test-classes.d.ts +12 -0
  3. package/dist/__test__/entities/circular-reference-classes.d.ts +110 -0
  4. package/dist/__test__/entities/complex-circular-dependencies.d.ts +71 -0
  5. package/dist/__test__/entities/decorated-classes.d.ts +54 -0
  6. package/dist/__test__/entities/generic-circular-classes.d.ts +57 -0
  7. package/dist/__test__/entities/nested-classes.d.ts +70 -0
  8. package/dist/__test__/entities/pure-classes.d.ts +37 -0
  9. package/dist/__test__/entities/schema-validation-classes.d.ts +35 -0
  10. package/dist/__test__/index.d.ts +3 -9
  11. package/dist/__test__/testCases/schema-validation.test.d.ts +1 -0
  12. package/dist/index.d.ts +2 -2
  13. package/dist/index.esm.js +546 -1319
  14. package/dist/index.js +545 -1319
  15. package/dist/run.d.ts +1 -1
  16. package/dist/run.js +1131 -1343
  17. package/dist/transformer.d.ts +1 -575
  18. package/dist/transformer.fixtures.d.ts +21 -0
  19. package/dist/types.d.ts +40 -3
  20. package/package.json +16 -15
  21. package/dist/__test__/entities/address.entity.d.ts +0 -5
  22. package/dist/__test__/entities/array.entity.d.ts +0 -7
  23. package/dist/__test__/entities/broken.entity.d.ts +0 -7
  24. package/dist/__test__/entities/circular.entity.d.ts +0 -59
  25. package/dist/__test__/entities/complete.entity.d.ts +0 -16
  26. package/dist/__test__/entities/complex-generics.entity.d.ts +0 -33
  27. package/dist/__test__/entities/comprehensive-enum.entity.d.ts +0 -23
  28. package/dist/__test__/entities/enum.entity.d.ts +0 -29
  29. package/dist/__test__/entities/generic.entity.d.ts +0 -11
  30. package/dist/__test__/entities/optional-properties.entity.d.ts +0 -11
  31. package/dist/__test__/entities/plain.entity.d.ts +0 -19
  32. package/dist/__test__/entities/simple.entity.d.ts +0 -5
  33. package/dist/__test__/entities/upload.entity.d.ts +0 -8
  34. package/dist/__test__/entities/user-role-generic.entity.d.ts +0 -13
  35. package/dist/__test__/test-entities/duplicate-name.entity.d.ts +0 -5
  36. package/dist/__test__/test-entities/generic.entity.d.ts +0 -11
  37. /package/dist/__test__/{circular-reference.test.d.ts → entities/circular-reference-cases.d.ts} +0 -0
  38. /package/dist/__test__/{enum.test.d.ts → entities/deep-nested-classes.d.ts} +0 -0
  39. /package/dist/__test__/{generic-types.test.d.ts → test.d.ts} +0 -0
  40. /package/dist/__test__/{integration.test.d.ts → testCases/circular-references.test.d.ts} +0 -0
  41. /package/dist/__test__/{main.test.d.ts → testCases/debug.test.d.ts} +0 -0
  42. /package/dist/__test__/{optional-properties.test.d.ts → testCases/decorated-classes.test.d.ts} +0 -0
  43. /package/dist/__test__/{plain.test.d.ts → testCases/edge-cases.test.d.ts} +0 -0
  44. /package/dist/__test__/{ref-pattern.test.d.ts → testCases/nested-classes.test.d.ts} +0 -0
  45. /package/dist/__test__/{singleton-behavior.test.d.ts → testCases/pure-classes.test.d.ts} +0 -0
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Additional test classes for pure TypeScript classes tests
3
+ * These classes are used in the pure-classes.test.ts file
4
+ */
5
+ export declare class OptionalOnlyClass {
6
+ optionalProp?: string;
7
+ anotherOptional?: number;
8
+ }
9
+ export declare class UnionTypeClass {
10
+ stringOrNumber: string | number;
11
+ optionalUnion?: boolean | string;
12
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Test classes for circular reference scenarios
3
+ * These classes are designed to test the handling of recursive references
4
+ */
5
+ /**
6
+ * Self-referencing class through direct property
7
+ */
8
+ export declare class SelfReferenceDirectClass {
9
+ id: number;
10
+ name: string;
11
+ parent?: SelfReferenceDirectClass;
12
+ children: SelfReferenceDirectClass[];
13
+ }
14
+ /**
15
+ * Metadata class for nested circular references
16
+ */
17
+ export declare class NestedMetadata {
18
+ createdBy?: SelfReferenceNestedClass;
19
+ modifiedBy?: SelfReferenceNestedClass;
20
+ }
21
+ /**
22
+ * Self-referencing class through nested property
23
+ */
24
+ export declare class SelfReferenceNestedClass {
25
+ id: number;
26
+ metadata: NestedMetadata;
27
+ }
28
+ /**
29
+ * Second class in indirect circular reference
30
+ */
31
+ export declare class NodeDataClass {
32
+ description: string;
33
+ parentNode: NodeClass;
34
+ }
35
+ /**
36
+ * First class in indirect circular reference
37
+ */
38
+ export declare class NodeClass {
39
+ id: number;
40
+ name: string;
41
+ nodeData: NodeDataClass;
42
+ }
43
+ /**
44
+ * Third class in deep circular chain
45
+ */
46
+ export declare class ClassC {
47
+ id: number;
48
+ value: number;
49
+ nextRef: ClassA;
50
+ }
51
+ /**
52
+ * Second class in deep circular chain
53
+ */
54
+ export declare class ClassB {
55
+ id: number;
56
+ description: string;
57
+ nextRef: ClassC;
58
+ }
59
+ /**
60
+ * First class in deep circular chain
61
+ */
62
+ export declare class ClassA {
63
+ id: number;
64
+ name: string;
65
+ nextRef: ClassB;
66
+ }
67
+ /**
68
+ * Multiple circular paths in the same class
69
+ */
70
+ export declare class MultiPathCircularClass {
71
+ id: number;
72
+ selfRef1?: MultiPathCircularClass;
73
+ selfRef2?: MultiPathCircularClass;
74
+ manyRefs: MultiPathCircularClass[];
75
+ }
76
+ /**
77
+ * Base generic class that can create circular references
78
+ */
79
+ export declare class GenericContainer {
80
+ value: any;
81
+ metadata: Record<string, any>;
82
+ related?: GenericContainer;
83
+ }
84
+ /**
85
+ * Concrete implementation with self-reference
86
+ */
87
+ export declare class SelfReferencingGenericClass extends GenericContainer {
88
+ id: number;
89
+ name: string;
90
+ children: SelfReferencingGenericClass;
91
+ }
92
+ /**
93
+ * Classes for deeply nested circular references
94
+ */
95
+ export declare class Level3 {
96
+ data: boolean;
97
+ refToRoot?: DeepNestedProperClasses;
98
+ }
99
+ export declare class Level2 {
100
+ data: number;
101
+ level3: Level3;
102
+ }
103
+ export declare class Level1 {
104
+ data: string;
105
+ level2: Level2;
106
+ }
107
+ export declare class DeepNestedProperClasses {
108
+ id: number;
109
+ level1: Level1;
110
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Complex inter-dependent classes with multiple circular references
3
+ */
4
+ /**
5
+ * Core entity with relationships to other classes
6
+ */
7
+ export declare class User {
8
+ id: number;
9
+ name: string;
10
+ email: string;
11
+ posts: Post[];
12
+ comments: Comment[];
13
+ profile: Profile;
14
+ primaryGroup?: Group;
15
+ manager?: User;
16
+ directReports: User[];
17
+ }
18
+ /**
19
+ * Entity with back-reference to User
20
+ */
21
+ export declare class Post {
22
+ id: number;
23
+ title: string;
24
+ content: string;
25
+ author: User;
26
+ comments: Comment[];
27
+ categories: Category[];
28
+ relatedPosts: Post[];
29
+ }
30
+ /**
31
+ * Entity with multiple back-references creating complex circular dependencies
32
+ */
33
+ export declare class Comment {
34
+ id: number;
35
+ content: string;
36
+ author: User;
37
+ post: Post;
38
+ parentComment?: Comment;
39
+ replies: Comment[];
40
+ }
41
+ /**
42
+ * Entity with 1:1 relationship with User
43
+ */
44
+ export declare class Profile {
45
+ id: number;
46
+ bio: string;
47
+ avatar: string;
48
+ user: User;
49
+ }
50
+ /**
51
+ * Entity with many-to-many relationship with User
52
+ */
53
+ export declare class Group {
54
+ id: number;
55
+ name: string;
56
+ description: string;
57
+ members: User[];
58
+ admin: User;
59
+ parentGroup?: Group;
60
+ subGroups: Group[];
61
+ }
62
+ /**
63
+ * Entity with many-to-many relationship with Post
64
+ */
65
+ export declare class Category {
66
+ id: number;
67
+ name: string;
68
+ posts: Post[];
69
+ parentCategory?: Category;
70
+ subcategories: Category[];
71
+ }
@@ -0,0 +1,54 @@
1
+ export declare enum UserStatus {
2
+ ACTIVE = "active",
3
+ INACTIVE = "inactive",
4
+ PENDING = "pending",
5
+ SUSPENDED = "suspended"
6
+ }
7
+ export declare enum Priority {
8
+ LOW = 1,
9
+ MEDIUM = 2,
10
+ HIGH = 3,
11
+ CRITICAL = 4
12
+ }
13
+ export declare class DecoratedAddress {
14
+ street: string;
15
+ city: string;
16
+ state: string;
17
+ zipCode: string;
18
+ country: string;
19
+ }
20
+ export declare class DecoratedUser {
21
+ id: number;
22
+ name: string;
23
+ email: string;
24
+ age: number;
25
+ status: UserStatus;
26
+ isActive?: boolean;
27
+ tags: string[];
28
+ address: DecoratedAddress;
29
+ createdAt: Date;
30
+ updatedAt?: Date;
31
+ }
32
+ export declare class DecoratedProduct {
33
+ id: number;
34
+ name: string;
35
+ description: string;
36
+ price: number;
37
+ currency: string;
38
+ categories: string[];
39
+ inStock: boolean;
40
+ quantity?: number;
41
+ images?: string[];
42
+ }
43
+ export declare class DecoratedTask {
44
+ id: number;
45
+ title: string;
46
+ description: string;
47
+ priority: Priority;
48
+ completed: boolean;
49
+ dueDate: Date;
50
+ assignedTo?: DecoratedUser;
51
+ tags?: string[];
52
+ createdAt: Date;
53
+ completedAt?: Date;
54
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Interfaces and classes for handling generic circular references
3
+ */
4
+ /**
5
+ * Interface defining the contract for metadata properties
6
+ */
7
+ export interface IMetadata {
8
+ createdAt?: Date;
9
+ updatedAt?: Date;
10
+ version?: number;
11
+ [key: string]: any;
12
+ }
13
+ /**
14
+ * Interface defining the contract for entities with circular references
15
+ */
16
+ export interface ICircularReference<T> {
17
+ getReference(): T | undefined;
18
+ setReference(ref: T): void;
19
+ }
20
+ /**
21
+ * Interface for entities that can contain related items
22
+ */
23
+ export interface IRelatable<T> {
24
+ related?: T;
25
+ }
26
+ /**
27
+ * Base class for containers that hold generic values with metadata
28
+ */
29
+ export declare abstract class BaseContainer<T> implements IRelatable<BaseContainer<T>> {
30
+ abstract value: T;
31
+ metadata: IMetadata;
32
+ related?: BaseContainer<T>;
33
+ constructor();
34
+ protected abstract validateValue(value: T): boolean;
35
+ }
36
+ /**
37
+ * Generic container implementation with basic value validation
38
+ */
39
+ export declare class GenericContainer<T> extends BaseContainer<T> {
40
+ value: T;
41
+ metadata: IMetadata & {
42
+ additionalInfo?: string;
43
+ };
44
+ constructor(value: T);
45
+ protected validateValue(value: T): boolean;
46
+ }
47
+ /**
48
+ * Self-referencing class that extends GenericContainer
49
+ */
50
+ export declare class SelfReferencingGenericClass extends GenericContainer<SelfReferencingGenericClass> implements ICircularReference<SelfReferencingGenericClass> {
51
+ id: number;
52
+ name: string;
53
+ constructor(id: number, name: string);
54
+ getReference(): SelfReferencingGenericClass | undefined;
55
+ setReference(ref: SelfReferencingGenericClass): void;
56
+ protected validateValue(value: SelfReferencingGenericClass): boolean;
57
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Nested TypeScript classes to test object relationships
3
+ */
4
+ export declare class Address {
5
+ street: string;
6
+ city: string;
7
+ state: string;
8
+ zipCode: string;
9
+ country: string;
10
+ }
11
+ export declare class Role {
12
+ id: number;
13
+ name: string;
14
+ permissions: string[];
15
+ level: number;
16
+ }
17
+ export declare class Company {
18
+ name: string;
19
+ industry: string;
20
+ foundedYear: number;
21
+ employees: number;
22
+ }
23
+ export declare class EmergencyContact {
24
+ name: string;
25
+ phone: string;
26
+ relationship: string;
27
+ }
28
+ export declare class NestedUser {
29
+ id: number;
30
+ name: string;
31
+ email: string;
32
+ address: Address;
33
+ roles: Role[];
34
+ company: Company;
35
+ alternativeAddresses: Address[];
36
+ emergencyContact?: EmergencyContact;
37
+ }
38
+ /**
39
+ * Deep nesting example
40
+ */
41
+ export declare class Department {
42
+ id: number;
43
+ name: string;
44
+ budget: number;
45
+ }
46
+ export declare class Team {
47
+ id: number;
48
+ name: string;
49
+ department: Department;
50
+ members: TeamMember[];
51
+ }
52
+ export declare class TeamMember {
53
+ id: number;
54
+ name: string;
55
+ email: string;
56
+ role: string;
57
+ startDate: Date;
58
+ }
59
+ export declare class Subsidiary {
60
+ name: string;
61
+ location: Address;
62
+ established: Date;
63
+ }
64
+ export declare class Organization {
65
+ id: number;
66
+ name: string;
67
+ teams: Team[];
68
+ headquarters: Address;
69
+ subsidiaries: Subsidiary[];
70
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Pure TypeScript class without any decorators
3
+ * Used to test basic type inference and transformation
4
+ */
5
+ export declare class PureUser {
6
+ id: number;
7
+ name: string;
8
+ email: string;
9
+ age: number;
10
+ isActive: boolean;
11
+ tags: string[];
12
+ metadata: Record<string, any>;
13
+ createdAt: Date;
14
+ phone?: string;
15
+ bio?: string;
16
+ }
17
+ /**
18
+ * Pure TypeScript class with primitive types only
19
+ */
20
+ export declare class SimplePerson {
21
+ firstName: string;
22
+ lastName: string;
23
+ age: number;
24
+ isEmployed: boolean;
25
+ }
26
+ /**
27
+ * Pure TypeScript class with arrays
28
+ */
29
+ export declare class Product {
30
+ id: number;
31
+ name: string;
32
+ price: number;
33
+ categories: string[];
34
+ scores: number[];
35
+ isAvailable: boolean;
36
+ description?: string;
37
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Classes for testing schema validation
3
+ */
4
+ export declare class TypeMappingTest {
5
+ stringProp: string;
6
+ numberProp: number;
7
+ booleanProp: boolean;
8
+ arrayProp: string[];
9
+ objectProp: Record<string, any>;
10
+ dateProp: Date;
11
+ }
12
+ export declare class NestedSchema {
13
+ id: number;
14
+ name: string;
15
+ nested: {
16
+ prop1: string;
17
+ prop2: number;
18
+ };
19
+ }
20
+ export declare class CircularA {
21
+ id: number;
22
+ name: string;
23
+ refToB: CircularB;
24
+ }
25
+ export declare class CircularB {
26
+ id: number;
27
+ description: string;
28
+ refToA: CircularA;
29
+ }
30
+ export declare class RequiredFieldsTest {
31
+ required1: string;
32
+ required2: number;
33
+ optional1?: string;
34
+ optional2?: number;
35
+ }
@@ -1,9 +1,3 @@
1
- import './main.test';
2
- import './integration.test';
3
- import './plain.test';
4
- import './optional-properties.test';
5
- import './generic-types.test';
6
- import './enum.test';
7
- import './circular-reference.test';
8
- import './ref-pattern.test';
9
- import './singleton-behavior.test';
1
+ import './testCases/pure-classes.test';
2
+ import './testCases/decorated-classes.test';
3
+ import './testCases/nested-classes.test';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { transform, SchemaTransformer } from './transformer';
1
+ import { transform } from './transformer';
2
2
  import { SchemaType, TransformerOptions } from './types';
3
- export { transform, SchemaTransformer, type SchemaType, type TransformerOptions, };
3
+ export { transform, type SchemaType, type TransformerOptions };