api 4.5.0 → 4.5.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/cache.js +15 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api",
3
- "version": "4.5.0",
3
+ "version": "4.5.1",
4
4
  "description": "Generate an SDK from an OpenAPI definition",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -52,5 +52,5 @@
52
52
  ".api-test/"
53
53
  ]
54
54
  },
55
- "gitHead": "2cbe023cb5d2c1ff1f8b46a4c90d49bb7af0c5f1"
55
+ "gitHead": "5c3490291498c1ac7f2f9dfe2ad99afff9010689"
56
56
  }
package/src/cache.js CHANGED
@@ -92,7 +92,18 @@ class Cache {
92
92
  }
93
93
 
94
94
  const cache = this.getCache();
95
- return JSON.parse(fs.readFileSync(cache[this.uriHash].path, 'utf8'));
95
+
96
+ // Prior to v4.5.0 we were putting a fully resolved path to the API definition in the cache
97
+ // store but if you had specified a custom caching directory and would generate the cache on
98
+ // your system, that filepath would obviously not be the same in other environments. For this
99
+ // reason the `path` was removed from the cache store in favor of storing the `hash` instead.
100
+ //
101
+ // If we still have `path` in the config cache for backwards compatibility we should use it.
102
+ if ('path' in cache[this.uriHash]) {
103
+ return JSON.parse(fs.readFileSync(cache[this.uriHash].path, 'utf8'));
104
+ }
105
+
106
+ return JSON.parse(fs.readFileSync(path.join(this.specsCache, `${cache[this.uriHash].hash}.json`)));
96
107
  }
97
108
 
98
109
  async load() {
@@ -159,16 +170,16 @@ class Cache {
159
170
  const cache = self.getCache();
160
171
  if (!(self.uriHash in cache)) {
161
172
  const saved = JSON.stringify(spec, null, 2);
162
- const jsonHash = crypto.createHash('md5').update(saved).digest('hex');
173
+ const fileHash = crypto.createHash('md5').update(saved).digest('hex');
163
174
 
164
175
  cache[self.uriHash] = {
165
- path: path.join(self.specsCache, `${jsonHash}.json`),
176
+ hash: fileHash,
166
177
  original: self.uri,
167
178
  title: 'title' in spec.info ? spec.info.title : undefined,
168
179
  version: 'version' in spec.info ? spec.info.version : undefined,
169
180
  };
170
181
 
171
- fs.writeFileSync(cache[self.uriHash].path, saved);
182
+ fs.writeFileSync(path.join(self.specsCache, `${fileHash}.json`), saved);
172
183
  fs.writeFileSync(self.cacheStore, JSON.stringify(cache, null, 2));
173
184
 
174
185
  self.cache = cache;