swaggie 1.5.1 → 1.5.3-beta.1

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
@@ -301,7 +301,7 @@ function error(e) {
301
301
  | Content types: `JSON`, `text`, `multipart/form-data` | Multiple request types (only one will be used) |
302
302
  | Content types: `application/x-www-form-urlencoded`, `application/octet-stream` | References to other spec files |
303
303
  | Different types of enum definitions (+ OpenAPI 3.1 support for enums) | OpenAPI callbacks |
304
- | Paths inheritance, comments (descriptions) | OpenAPI webhooks |
304
+ | Paths inheritance, comments (descriptions), nullable | OpenAPI webhooks |
305
305
  | Getting documents from remote locations or as path reference (local file) | |
306
306
  | Grouping endpoints by tags + handle gracefully duplicate operation ids | |
307
307
 
@@ -48,25 +48,40 @@ var _utils = require('../utils');
48
48
  return getSafeIdentifier(refName) || unknownType;
49
49
  }
50
50
 
51
+ if (schema.type === 'null') {
52
+ return 'null';
53
+ }
54
+
55
+ const isNullableSuffix = 'nullable' in schema && schema.nullable === true ? ' | null' : '';
56
+ const type = getTypeFromSchemaInternal(schema, options);
57
+
58
+ if (isNullableSuffix && type.endsWith('| null')) {
59
+ return type;
60
+ }
61
+ return type + isNullableSuffix;
62
+ } exports.getTypeFromSchema = getTypeFromSchema;
63
+
64
+ function getTypeFromSchemaInternal(
65
+ schema,
66
+ options
67
+ ) {
68
+ const unknownType = options.preferAny ? 'any' : 'unknown';
69
+
51
70
  if ('allOf' in schema || 'oneOf' in schema || 'anyOf' in schema) {
52
71
  return getTypeFromComposites(schema , options);
53
72
  }
54
73
 
55
74
  if (schema.type === 'array') {
56
75
  if (schema.items) {
57
- return `${getTypeFromSchema(schema.items, options)}[]`;
76
+ return `${getNestedTypeFromSchema(schema.items, options)}[]`;
58
77
  }
59
78
  return `${unknownType}[]`;
60
79
  }
61
80
  if (schema.type === 'object') {
62
81
  return getTypeFromObject(schema, options);
63
82
  }
64
- if (schema.type === 'null') {
65
- return 'null';
66
- }
67
-
68
83
  if ('enum' in schema) {
69
- return `(${schema.enum.map((v) => JSON.stringify(v)).join(' | ')})`;
84
+ return `${schema.enum.map((v) => JSON.stringify(v)).join(' | ')}`;
70
85
  }
71
86
  if (schema.type === 'integer' || schema.type === 'number') {
72
87
  return 'number';
@@ -81,7 +96,17 @@ var _utils = require('../utils');
81
96
  return 'boolean';
82
97
  }
83
98
  return unknownType;
84
- } exports.getTypeFromSchema = getTypeFromSchema;
99
+ }
100
+
101
+ function getNestedTypeFromSchema(
102
+ schema,
103
+ options
104
+ ) {
105
+ if (('nullable' in schema && schema.nullable === true) || ('enum' in schema && schema.enum)) {
106
+ return `(${getTypeFromSchema(schema, options)})`;
107
+ }
108
+ return getTypeFromSchema(schema, options);
109
+ }
85
110
 
86
111
  /**
87
112
  * Knowing that the schema is an object, this function returns a TypeScript type definition
@@ -1,5 +1,5 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _nodefs = require('node:fs'); var _nodefs2 = _interopRequireDefault(_nodefs);
2
- var _jsyaml = require('js-yaml'); var _jsyaml2 = _interopRequireDefault(_jsyaml);
2
+ var _yaml = require('yaml');
3
3
 
4
4
 
5
5
  /**
@@ -41,7 +41,7 @@ function readLocalFile(filePath) {
41
41
  function parseFileContents(contents, path) {
42
42
  // If the path ends with .yaml or .yml, parse as YAML
43
43
  if (/.ya?ml$/i.test(path)) {
44
- return _jsyaml2.default.load(contents) ;
44
+ return _yaml.parse.call(void 0, contents);
45
45
  }
46
46
  // If the path ends with .json, parse as JSON
47
47
  if (/.json$/i.test(path)) {
@@ -54,5 +54,5 @@ function parseFileContents(contents, path) {
54
54
  return JSON.parse(contents);
55
55
  }
56
56
 
57
- return _jsyaml2.default.load(contents) ;
57
+ return _yaml.parse.call(void 0, contents);
58
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swaggie",
3
- "version": "1.5.1",
3
+ "version": "1.5.3-beta.1",
4
4
  "description": "Generate TypeScript REST client code from an OpenAPI spec",
5
5
  "author": {
6
6
  "name": "Piotr Dabrowski",
@@ -10,7 +10,7 @@
10
10
  "homepage": "https://github.com/yhnavein/swaggie",
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "https://github.com/yhnavein/swaggie.git"
13
+ "url": "git+https://github.com/yhnavein/swaggie.git"
14
14
  },
15
15
  "bugs": {
16
16
  "url": "https://github.com/yhnavein/swaggie/issues"
@@ -52,11 +52,10 @@
52
52
  "case": "^1.6.3",
53
53
  "commander": "^14.0.3",
54
54
  "eta": "^4.5.1",
55
- "js-yaml": "^4.1.0",
55
+ "yaml": "^2.8.2",
56
56
  "nanocolors": "^0.2.0"
57
57
  },
58
58
  "devDependencies": {
59
- "@types/js-yaml": "4.0.9",
60
59
  "bun-types": "1.3.9",
61
60
  "openapi-types": "^12.1.3",
62
61
  "sucrase": "3.35.1",