ts-class-to-openapi 1.4.2 → 1.4.4

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # 🔄 ts-class-to-openapi
2
2
 
3
+ [![npm version](https://badge.fury.io/js/ts-class-to-openapi.svg)](https://www.npmjs.com/package/ts-class-to-openapi) [![npm downloads](https://img.shields.io/npm/dm/ts-class-to-openapi.svg)](https://www.npmjs.com/package/ts-class-to-openapi)
4
+
3
5
  ✨ **Transform TypeScript classes into OpenAPI 3.1.0 schemas**
4
6
 
5
7
  A robust and efficient library that automatically transforms TypeScript classes into OpenAPI-compatible schemas. Compatible with **pure TypeScript classes** and **class-validator decorated classes**.
@@ -28,7 +30,7 @@ class User {
28
30
 
29
31
  const schema = transform(User)
30
32
 
31
- console.log(JSON.stringify(shema), null, 2)
33
+ console.log(JSON.stringify(schema), null, 2)
32
34
  ```
33
35
 
34
36
  **Generated output:**
package/dist/index.cjs CHANGED
@@ -258,14 +258,19 @@ var SchemaTransformer = class SchemaTransformer {
258
258
  else {
259
259
  const heritageClause = classNode.heritageClauses[0];
260
260
  if (heritageClause && heritageClause.token === typescript.default.SyntaxKind.ExtendsKeyword) {
261
- var _symbol$declarations;
262
261
  const type = heritageClause.types[0];
263
262
  let properties = [];
264
263
  let baseProperties = [];
265
264
  if (!type) return [];
266
265
  const symbol = this.checker.getSymbolAtLocation(type.expression);
267
266
  if (!symbol) return [];
268
- const declaration = (_symbol$declarations = symbol.declarations) === null || _symbol$declarations === void 0 ? void 0 : _symbol$declarations[0];
267
+ const realSymbol = symbol && symbol.flags & typescript.default.SymbolFlags.Alias ? this.checker.getAliasedSymbol(symbol) : symbol;
268
+ let declaration;
269
+ if (realSymbol && realSymbol.links && realSymbol.links.type && realSymbol.links.type.symbol && realSymbol.links.type.symbol.declarations) declaration = realSymbol.links.type.symbol.declarations[0];
270
+ else {
271
+ var _realSymbol$declarati;
272
+ declaration = realSymbol === null || realSymbol === void 0 || (_realSymbol$declarati = realSymbol.declarations) === null || _realSymbol$declarati === void 0 ? void 0 : _realSymbol$declarati.find(typescript.default.isClassDeclaration);
273
+ }
269
274
  if (declaration && typescript.default.isClassDeclaration(declaration)) {
270
275
  const newGenericTypeMap = /* @__PURE__ */ new Map();
271
276
  if (declaration.typeParameters && type.typeArguments) declaration.typeParameters.forEach((param, index) => {
package/dist/index.mjs CHANGED
@@ -233,14 +233,19 @@ var SchemaTransformer = class SchemaTransformer {
233
233
  else {
234
234
  const heritageClause = classNode.heritageClauses[0];
235
235
  if (heritageClause && heritageClause.token === ts.SyntaxKind.ExtendsKeyword) {
236
- var _symbol$declarations;
237
236
  const type = heritageClause.types[0];
238
237
  let properties = [];
239
238
  let baseProperties = [];
240
239
  if (!type) return [];
241
240
  const symbol = this.checker.getSymbolAtLocation(type.expression);
242
241
  if (!symbol) return [];
243
- const declaration = (_symbol$declarations = symbol.declarations) === null || _symbol$declarations === void 0 ? void 0 : _symbol$declarations[0];
242
+ const realSymbol = symbol && symbol.flags & ts.SymbolFlags.Alias ? this.checker.getAliasedSymbol(symbol) : symbol;
243
+ let declaration;
244
+ if (realSymbol && realSymbol.links && realSymbol.links.type && realSymbol.links.type.symbol && realSymbol.links.type.symbol.declarations) declaration = realSymbol.links.type.symbol.declarations[0];
245
+ else {
246
+ var _realSymbol$declarati;
247
+ declaration = realSymbol === null || realSymbol === void 0 || (_realSymbol$declarati = realSymbol.declarations) === null || _realSymbol$declarati === void 0 ? void 0 : _realSymbol$declarati.find(ts.isClassDeclaration);
248
+ }
244
249
  if (declaration && ts.isClassDeclaration(declaration)) {
245
250
  const newGenericTypeMap = /* @__PURE__ */ new Map();
246
251
  if (declaration.typeParameters && type.typeArguments) declaration.typeParameters.forEach((param, index) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-class-to-openapi",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "Transform TypeScript classes into OpenAPI 3.1.0 schema objects, which support class-validator decorators",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",