Skip to content

Commit 122eaf9

Browse files
authored
Merge pull request #1822 from hey-api/fix/bump-json-schema-ref
2 parents cc28590 + c73b0d4 commit 122eaf9

File tree

6 files changed

+364
-81
lines changed

6 files changed

+364
-81
lines changed

.changeset/big-boats-grin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
fix: bump json-schema-ref-parser package

packages/openapi-ts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"node": "^18.18.0 || ^20.9.0 || >=22.10.0"
8080
},
8181
"dependencies": {
82-
"@hey-api/json-schema-ref-parser": "1.0.2",
82+
"@hey-api/json-schema-ref-parser": "1.0.3",
8383
"c12": "2.0.1",
8484
"commander": "13.0.0",
8585
"handlebars": "4.7.8"

packages/openapi-ts/src/getSpec.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,7 @@ export const getSpec = async ({
3030
watch: WatchValues;
3131
}): Promise<SpecResponse | SpecError> => {
3232
const refParser = new $RefParser();
33-
// TODO: patch @hey-api/json-schema-ref-parser to correctly handle raw spec
34-
const resolvedInput =
35-
typeof inputPath === 'string'
36-
? getResolvedInput({ pathOrUrlOrSchema: inputPath })
37-
: ({
38-
path: '',
39-
schema: inputPath,
40-
type: 'json',
41-
} as const);
33+
const resolvedInput = getResolvedInput({ pathOrUrlOrSchema: inputPath });
4234

4335
let arrayBuffer: ArrayBuffer | undefined;
4436
// boolean signals whether the file has **definitely** changed
@@ -48,23 +40,30 @@ export const getSpec = async ({
4840
if (resolvedInput.type === 'url') {
4941
// do NOT send HEAD request on first run or if unsupported
5042
if (watch.lastValue && watch.isHeadMethodSupported !== false) {
51-
let request;
5243
try {
53-
request = await sendRequest({
44+
const request = await sendRequest({
5445
init: {
5546
headers: watch.headers,
5647
method: 'HEAD',
5748
},
5849
timeout,
5950
url: resolvedInput.path,
6051
});
61-
} catch (ex) {
52+
53+
if (request.response.status >= 300) {
54+
return {
55+
error: 'not-ok',
56+
response: request.response,
57+
};
58+
}
59+
60+
response = request.response;
61+
} catch (error) {
6262
return {
6363
error: 'not-ok',
64-
response: new Response(ex.message),
64+
response: new Response(error.message),
6565
};
6666
}
67-
response = request.response;
6867

6968
if (!response.ok && watch.isHeadMethodSupported) {
7069
// assume the server is no longer running
@@ -118,18 +117,26 @@ export const getSpec = async ({
118117
}
119118

120119
try {
121-
const fileRequest = await sendRequest({
120+
const request = await sendRequest({
122121
init: {
123122
method: 'GET',
124123
},
125124
timeout,
126125
url: resolvedInput.path,
127126
});
128-
response = fileRequest.response;
129-
} catch (ex) {
127+
128+
if (request.response.status >= 300) {
129+
return {
130+
error: 'not-ok',
131+
response: request.response,
132+
};
133+
}
134+
135+
response = request.response;
136+
} catch (error) {
130137
return {
131138
error: 'not-ok',
132-
response: new Response(ex.message),
139+
response: new Response(error.message),
133140
};
134141
}
135142

packages/openapi-ts/test/custom/request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const request = <T>(
3030
onCancel(() => {
3131
clearTimeout(timeout);
3232
});
33-
} catch (e) {
34-
reject(e);
33+
} catch (error) {
34+
reject(error);
3535
}
3636
});

packages/openapi-ts/test/openapi-ts.config.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,29 @@ import { defineConfig } from '../src';
55
export default defineConfig({
66
// experimentalParser: false,
77
input: {
8-
// branch: 'main',
8+
branch: 'main',
99
// exclude: '^#/components/schemas/ModelWithCircularReference$',
1010
// include:
1111
// '^(#/components/schemas/import|#/paths/api/v{api-version}/simple/options)$',
12-
// organization: 'hey-api',
13-
path: {
14-
components: {},
15-
info: {
16-
version: '1.0.0',
17-
},
18-
openapi: '3.1.0',
19-
paths: {},
20-
},
12+
organization: 'hey-api',
13+
// path: {
14+
// components: {},
15+
// info: {
16+
// version: '1.0.0',
17+
// },
18+
// openapi: '3.1.0',
19+
// paths: {},
20+
// },
2121
// path: path.resolve(__dirname, 'spec', '3.1.x', 'full.json'),
22-
// path: 'https://get.heyapi.dev/',
22+
// path: 'http://localhost:4000/',
23+
path: 'https://get.heyapi.dev/',
2324
// path: 'https://get.heyapi.dev/hey-api/backend?branch=main&version=1.0.0',
2425
// path: 'http://localhost:8000/openapi.json',
2526
// path: './test/spec/v3-transforms.json',
2627
// path: 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/2caffd88277a4e27c95dcefc7e3b6a63a3b03297-v2-2023-11-15.json',
2728
// path: 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml',
2829
// project: 'backend',
30+
project: 'upload-openapi-spec',
2931
// version: '1.0.0',
3032
},
3133
logs: {

0 commit comments

Comments
 (0)