ts-class-to-openapi 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -31
- package/dist/__test__/circular-reference.test.d.ts +1 -0
- package/dist/__test__/entities/circular.entity.d.ts +59 -0
- package/dist/__test__/index.d.ts +3 -0
- package/dist/__test__/ref-pattern.test.d.ts +1 -0
- package/dist/__test__/singleton-behavior.test.d.ts +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.esm.js +307 -57
- package/dist/index.js +307 -56
- package/dist/run.js +307 -56
- package/dist/transformer.d.ts +137 -33
- package/dist/types.d.ts +17 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,6 @@ A powerful library that automatically converts your TypeScript classes into Open
|
|
|
8
8
|
>
|
|
9
9
|
> - **Pure TypeScript classes** without requiring any decorators or external dependencies!
|
|
10
10
|
> - **Full enum support** with `@IsEnum` decorator for string, numeric, and object enums
|
|
11
|
-
> - Perfect for transforming existing codebases instantly.
|
|
12
11
|
|
|
13
12
|
## 🚀 Key Features
|
|
14
13
|
|
|
@@ -793,7 +792,16 @@ const schema = transform(User)
|
|
|
793
792
|
"format": "binary"
|
|
794
793
|
}
|
|
795
794
|
},
|
|
796
|
-
"required": [
|
|
795
|
+
"required": [
|
|
796
|
+
"id",
|
|
797
|
+
"name",
|
|
798
|
+
"email",
|
|
799
|
+
"tags",
|
|
800
|
+
"createdAt",
|
|
801
|
+
"role",
|
|
802
|
+
"files",
|
|
803
|
+
"avatar"
|
|
804
|
+
]
|
|
797
805
|
}
|
|
798
806
|
}
|
|
799
807
|
```
|
|
@@ -802,19 +810,19 @@ const schema = transform(User)
|
|
|
802
810
|
|
|
803
811
|
## 📊 Pure TypeScript vs Enhanced Mode Comparison
|
|
804
812
|
|
|
805
|
-
| Feature | Pure TypeScript
|
|
806
|
-
| ---------------------- |
|
|
807
|
-
| **Dependencies** | Zero
|
|
808
|
-
| **Configuration** | None
|
|
809
|
-
| **Type Detection** | Automatic
|
|
810
|
-
| **Validation Rules** | Basic types only
|
|
813
|
+
| Feature | Pure TypeScript | Enhanced (class-validator) |
|
|
814
|
+
| ---------------------- | ------------------------------------------- | ----------------------------------------- |
|
|
815
|
+
| **Dependencies** | Zero | Requires `class-validator` |
|
|
816
|
+
| **Configuration** | None | `experimentalDecorators: true` |
|
|
817
|
+
| **Type Detection** | Automatic | Automatic + Decorators |
|
|
818
|
+
| **Validation Rules** | Basic types only | Rich validation constraints |
|
|
811
819
|
| **Required Fields** | Based on TypeScript optional operator (`?`) | TypeScript optional operator + decorators |
|
|
812
|
-
| **String Constraints** | None
|
|
813
|
-
| **Number Constraints** | None
|
|
814
|
-
| **Array Constraints** | None
|
|
815
|
-
| **Email Validation** | None
|
|
816
|
-
| **Date Handling** | `date-time` format
|
|
817
|
-
| **Use Case** | Existing codebases, rapid prototyping
|
|
820
|
+
| **String Constraints** | None | Min/max length, patterns |
|
|
821
|
+
| **Number Constraints** | None | Min/max values, positive |
|
|
822
|
+
| **Array Constraints** | None | Min/max items, non-empty |
|
|
823
|
+
| **Email Validation** | None | Email format validation |
|
|
824
|
+
| **Date Handling** | `date-time` format | `date-time` format |
|
|
825
|
+
| **Use Case** | Existing codebases, rapid prototyping | APIs with validation, robust schemas |
|
|
818
826
|
|
|
819
827
|
### Example Comparison
|
|
820
828
|
|
|
@@ -822,9 +830,9 @@ const schema = transform(User)
|
|
|
822
830
|
|
|
823
831
|
```typescript
|
|
824
832
|
class User {
|
|
825
|
-
name: string
|
|
826
|
-
email: string
|
|
827
|
-
age: number
|
|
833
|
+
name: string // Required (no ? operator)
|
|
834
|
+
email: string // Required (no ? operator)
|
|
835
|
+
age: number // Required (no ? operator)
|
|
828
836
|
}
|
|
829
837
|
// Generates: All properties required (no ? operator), basic types
|
|
830
838
|
```
|
|
@@ -1139,10 +1147,10 @@ The presence or absence of the TypeScript optional operator (`?`) determines if
|
|
|
1139
1147
|
|
|
1140
1148
|
```typescript
|
|
1141
1149
|
class User {
|
|
1142
|
-
name: string
|
|
1143
|
-
email: string
|
|
1144
|
-
age?: number
|
|
1145
|
-
bio?: string
|
|
1150
|
+
name: string // ✅ REQUIRED (no ? operator)
|
|
1151
|
+
email: string // ✅ REQUIRED (no ? operator)
|
|
1152
|
+
age?: number // ❌ OPTIONAL (has ? operator)
|
|
1153
|
+
bio?: string // ❌ OPTIONAL (has ? operator)
|
|
1146
1154
|
}
|
|
1147
1155
|
|
|
1148
1156
|
// Generated schema:
|
|
@@ -1158,12 +1166,12 @@ import { IsNotEmpty, IsOptional } from 'class-validator'
|
|
|
1158
1166
|
|
|
1159
1167
|
class User {
|
|
1160
1168
|
@IsNotEmpty()
|
|
1161
|
-
requiredField?: string
|
|
1162
|
-
|
|
1169
|
+
requiredField?: string // ✅ REQUIRED (@IsNotEmpty overrides ?)
|
|
1170
|
+
|
|
1163
1171
|
@IsOptional()
|
|
1164
|
-
optionalField: string
|
|
1165
|
-
|
|
1166
|
-
normalField: string
|
|
1172
|
+
optionalField: string // ❌ OPTIONAL (@IsOptional overrides no ?)
|
|
1173
|
+
|
|
1174
|
+
normalField: string // ✅ REQUIRED (no ? operator)
|
|
1167
1175
|
normalOptional?: string // ❌ OPTIONAL (has ? operator)
|
|
1168
1176
|
}
|
|
1169
1177
|
|
|
@@ -1179,12 +1187,12 @@ Array properties follow the same rules, with additional decorators:
|
|
|
1179
1187
|
import { ArrayNotEmpty } from 'class-validator'
|
|
1180
1188
|
|
|
1181
1189
|
class User {
|
|
1182
|
-
tags: string[]
|
|
1183
|
-
|
|
1190
|
+
tags: string[] // ✅ REQUIRED (no ? operator)
|
|
1191
|
+
|
|
1184
1192
|
@ArrayNotEmpty()
|
|
1185
|
-
categories?: string[]
|
|
1186
|
-
|
|
1187
|
-
optionalTags?: string[]
|
|
1193
|
+
categories?: string[] // ✅ REQUIRED (@ArrayNotEmpty overrides ?)
|
|
1194
|
+
|
|
1195
|
+
optionalTags?: string[] // ❌ OPTIONAL (has ? operator)
|
|
1188
1196
|
}
|
|
1189
1197
|
|
|
1190
1198
|
// Generated schema:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example entity demonstrating circular reference issue
|
|
3
|
+
* User -> Role -> User (circular)
|
|
4
|
+
*/
|
|
5
|
+
export declare class CircularUser {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
role: CircularRole;
|
|
9
|
+
organization: CircularOrganization;
|
|
10
|
+
organizations: CircularOrganization[];
|
|
11
|
+
}
|
|
12
|
+
export declare class CircularRole {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
assignedBy: CircularUser;
|
|
16
|
+
organization: CircularOrganization;
|
|
17
|
+
usersWithRole: CircularUser[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Example entity demonstrating complex circular references
|
|
21
|
+
* Organization -> User, Role, Organization (multiple circular references)
|
|
22
|
+
*/
|
|
23
|
+
export declare class CircularOrganization {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
owner: CircularUser;
|
|
27
|
+
defaultRole: CircularRole;
|
|
28
|
+
members: CircularUser[];
|
|
29
|
+
availableRoles: CircularRole[];
|
|
30
|
+
parentOrganization?: CircularOrganization;
|
|
31
|
+
childOrganizations: CircularOrganization[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Example demonstrating deep circular reference chain
|
|
35
|
+
* A -> B -> C -> D -> A (complex chain)
|
|
36
|
+
*/
|
|
37
|
+
export declare class DeepCircularA {
|
|
38
|
+
id: string;
|
|
39
|
+
reference: DeepCircularB;
|
|
40
|
+
}
|
|
41
|
+
export declare class DeepCircularB {
|
|
42
|
+
id: string;
|
|
43
|
+
reference: DeepCircularC;
|
|
44
|
+
}
|
|
45
|
+
export declare class DeepCircularC {
|
|
46
|
+
id: string;
|
|
47
|
+
reference: DeepCircularD;
|
|
48
|
+
}
|
|
49
|
+
export declare class DeepCircularD {
|
|
50
|
+
id: string;
|
|
51
|
+
reference: DeepCircularA;
|
|
52
|
+
allReferences: {
|
|
53
|
+
a: DeepCircularA;
|
|
54
|
+
b: DeepCircularB;
|
|
55
|
+
c: DeepCircularC;
|
|
56
|
+
selfRef: DeepCircularD;
|
|
57
|
+
};
|
|
58
|
+
arrayReferences: (DeepCircularA | DeepCircularB | DeepCircularC | DeepCircularD)[];
|
|
59
|
+
}
|
package/dist/__test__/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { transform } from './transformer';
|
|
2
|
-
import { SchemaType } from './types';
|
|
3
|
-
export { transform, type SchemaType };
|
|
1
|
+
import { transform, SchemaTransformer } from './transformer';
|
|
2
|
+
import { SchemaType, TransformerOptions } from './types';
|
|
3
|
+
export { transform, SchemaTransformer, type SchemaType, type TransformerOptions, };
|