api 5.0.2 → 5.0.3

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.
@@ -78,6 +78,7 @@ var fs_1 = __importDefault(require("fs"));
78
78
  var path_1 = __importDefault(require("path"));
79
79
  var execa_1 = __importDefault(require("execa"));
80
80
  var lodash_setwith_1 = __importDefault(require("lodash.setwith"));
81
+ var semver_1 = __importDefault(require("semver"));
81
82
  var ts_morph_1 = require("ts-morph");
82
83
  var logger_1 = __importDefault(require("../../logger"));
83
84
  var language_1 = __importDefault(require("../language"));
@@ -127,13 +128,21 @@ var TSGenerator = /** @class */ (function (_super) {
127
128
  TSGenerator.prototype.installer = function (storage, opts) {
128
129
  if (opts === void 0) { opts = {}; }
129
130
  return __awaiter(this, void 0, void 0, function () {
130
- var installDir, pkg, npmInstall;
131
+ var installDir, info, pkgVersion, pkg, npmInstall;
131
132
  return __generator(this, function (_a) {
132
133
  switch (_a.label) {
133
134
  case 0:
134
135
  installDir = storage.getIdentifierStorageDir();
136
+ info = this.spec.getDefinition().info;
137
+ pkgVersion = semver_1["default"].coerce(info.version);
138
+ if (!pkgVersion) {
139
+ // If the version that's in `info.version` isn't compatible with semver NPM won't be able to
140
+ // handle it properly so we need to fallback to something it can.
141
+ pkgVersion = semver_1["default"].coerce('0.0.0');
142
+ }
135
143
  pkg = {
136
144
  name: "@api/".concat(storage.identifier),
145
+ version: pkgVersion.version,
137
146
  main: "./index.".concat(this.outputJS ? 'js' : 'ts'),
138
147
  types: './index.d.ts'
139
148
  };
@@ -1,2 +1,2 @@
1
1
  export declare const PACKAGE_NAME = "api";
2
- export declare const PACKAGE_VERSION = "5.0.2";
2
+ export declare const PACKAGE_VERSION = "5.0.3";
@@ -3,4 +3,4 @@ exports.__esModule = true;
3
3
  exports.PACKAGE_VERSION = exports.PACKAGE_NAME = void 0;
4
4
  // This file is automatically updated by the build script.
5
5
  exports.PACKAGE_NAME = 'api';
6
- exports.PACKAGE_VERSION = '5.0.2';
6
+ exports.PACKAGE_VERSION = '5.0.3';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api",
3
- "version": "5.0.2",
3
+ "version": "5.0.3",
4
4
  "description": "Magical SDK generation from an OpenAPI definition 🪄",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -63,9 +63,10 @@
63
63
  "node-abort-controller": "^3.0.1",
64
64
  "oas": "^20.0.0",
65
65
  "ora": "^5.4.1",
66
- "prettier": "^2.7.1",
66
+ "prettier": "^2.8.0",
67
67
  "prompts": "^2.4.2",
68
68
  "remove-undefined-objects": "^2.0.1",
69
+ "semver": "^7.3.8",
69
70
  "ssri": "^10.0.0",
70
71
  "ts-morph": "^16.0.0",
71
72
  "validate-npm-package-name": "^5.0.0"
@@ -84,6 +85,7 @@
84
85
  "@types/mocha": "^10.0.0",
85
86
  "@types/prettier": "^2.7.1",
86
87
  "@types/prompts": "^2.0.14",
88
+ "@types/semver": "^7.3.13",
87
89
  "@types/sinon-chai": "^3.2.8",
88
90
  "@types/ssri": "^7.1.1",
89
91
  "@types/validate-npm-package-name": "^4.0.0",
@@ -95,6 +97,7 @@
95
97
  "oas-normalize": "^7.1.0",
96
98
  "sinon": "^14.0.0",
97
99
  "sinon-chai": "^3.7.0",
100
+ "type-fest": "^3.2.0",
98
101
  "typescript": "^4.7.4",
99
102
  "unique-temp-dir": "^1.0.0"
100
103
  },
@@ -105,5 +108,5 @@
105
108
  "test/"
106
109
  ]
107
110
  },
108
- "gitHead": "f51774f2d2cc8da42fdf1c4d4980e32379cef7ed"
111
+ "gitHead": "7aba675afe57fccdd23144a7917bc71bc7d28ed7"
109
112
  }
@@ -4,12 +4,14 @@ import type Oas from 'oas';
4
4
  import type { Operation } from 'oas';
5
5
  import type { HttpMethods, SchemaObject } from 'oas/dist/rmoas.types';
6
6
  import type { ClassDeclaration, JSDocStructure, OptionalKind, ParameterDeclarationStructure } from 'ts-morph';
7
+ import type { PackageJson } from 'type-fest';
7
8
 
8
9
  import fs from 'fs';
9
10
  import path from 'path';
10
11
 
11
12
  import execa from 'execa';
12
13
  import setWith from 'lodash.setwith';
14
+ import semver from 'semver';
13
15
  import { IndentationText, Project, QuoteKind, ScriptTarget, VariableDeclarationKind } from 'ts-morph';
14
16
 
15
17
  import logger from '../../logger';
@@ -119,8 +121,17 @@ export default class TSGenerator extends CodeGeneratorLanguage {
119
121
  async installer(storage: Storage, opts: InstallerOptions = {}): Promise<void> {
120
122
  const installDir = storage.getIdentifierStorageDir();
121
123
 
122
- const pkg = {
124
+ const info = this.spec.getDefinition().info;
125
+ let pkgVersion = semver.coerce(info.version);
126
+ if (!pkgVersion) {
127
+ // If the version that's in `info.version` isn't compatible with semver NPM won't be able to
128
+ // handle it properly so we need to fallback to something it can.
129
+ pkgVersion = semver.coerce('0.0.0');
130
+ }
131
+
132
+ const pkg: PackageJson = {
123
133
  name: `@api/${storage.identifier}`,
134
+ version: pkgVersion.version,
124
135
  main: `./index.${this.outputJS ? 'js' : 'ts'}`,
125
136
  types: './index.d.ts', // Types are always present regardless if you're getting compiled JS.
126
137
  };
@@ -1,3 +1,3 @@
1
1
  // This file is automatically updated by the build script.
2
2
  export const PACKAGE_NAME = 'api';
3
- export const PACKAGE_VERSION = '5.0.2';
3
+ export const PACKAGE_VERSION = '5.0.3';