Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/hey-api/openapi-ts into fea…
Browse files Browse the repository at this point in the history
…t/client-nuxt
  • Loading branch information
mrlubos committed Jan 10, 2025
2 parents 104fb2d + 836d8a9 commit 97e39bc
Show file tree
Hide file tree
Showing 5 changed files with 2,527 additions and 3,673 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Build library
run: pnpm build
- name: Build packages
run: pnpm --filter './packages/**' run build

- name: Build examples
if: matrix.node-version == '22.x' && matrix.os == 'ubuntu-latest'
run: pnpm --filter './examples/**' run build

- name: Run linter
run: pnpm lint
Expand Down
6 changes: 6 additions & 0 deletions packages/openapi-ts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @hey-api/openapi-ts

## 0.61.2

### Patch Changes

- [#1543](https://github.com/hey-api/openapi-ts/pull/1543) [`7a2d6dc`](https://github.com/hey-api/openapi-ts/commit/7a2d6dcd6e30411178ac5c78db3f1dbbcc8d6b27) Thanks [@mrlubos](https://github.com/mrlubos)! - fix: send GET request only on first spec fetch

## 0.61.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-ts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hey-api/openapi-ts",
"version": "0.61.1",
"version": "0.61.2",
"description": "🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more.",
"homepage": "https://heyapi.dev/",
"repository": {
Expand Down
104 changes: 53 additions & 51 deletions packages/openapi-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,17 @@ const getPlugins = (
});
};

interface WatchValues {
headers: Headers;
lastValue: string | undefined;
}

const getSpec = async ({
inputPath,
watch,
}: {
inputPath: Config['input']['path'];
watch: {
headers: Headers;
lastValue: string | undefined;
};
watch: WatchValues;
}): Promise<
| {
data: JSONSchema;
Expand All @@ -330,59 +332,62 @@ const getSpec = async ({

// no support for watching files and objects for now
if (resolvedInput.type === 'url') {
const request = await sendRequest({
init: {
headers: watch.headers,
method: 'HEAD',
},
url: resolvedInput.path,
});
response = request.response;

if (!response.ok) {
// assume the server is no longer running
// do nothing, it might be restarted later
return {
error: 'not-ok',
response,
};
}
// do not send HEAD request on first run
if (watch.lastValue) {
const request = await sendRequest({
init: {
headers: watch.headers,
method: 'HEAD',
},
url: resolvedInput.path,
});
response = request.response;

if (!response.ok) {
// assume the server is no longer running
// do nothing, it might be restarted later
return {
error: 'not-ok',
response,
};
}

if (response.status === 304) {
return {
error: 'not-modified',
response,
};
}
if (response.status === 304) {
return {
error: 'not-modified',
response,
};
}

if (hasChanged === undefined) {
const eTag = response.headers.get('ETag');
if (eTag) {
hasChanged = eTag !== watch.headers.get('If-None-Match');
if (hasChanged === undefined) {
const eTag = response.headers.get('ETag');
if (eTag) {
hasChanged = eTag !== watch.headers.get('If-None-Match');

if (hasChanged) {
watch.headers.set('If-None-Match', eTag);
if (hasChanged) {
watch.headers.set('If-None-Match', eTag);
}
}
}
}

if (hasChanged === undefined) {
const lastModified = response.headers.get('Last-Modified');
if (lastModified) {
hasChanged = lastModified !== watch.headers.get('If-Modified-Since');
if (hasChanged === undefined) {
const lastModified = response.headers.get('Last-Modified');
if (lastModified) {
hasChanged = lastModified !== watch.headers.get('If-Modified-Since');

if (hasChanged) {
watch.headers.set('If-Modified-Since', lastModified);
if (hasChanged) {
watch.headers.set('If-Modified-Since', lastModified);
}
}
}
}

// we definitely know the input has not changed
if (hasChanged === false) {
return {
error: 'not-modified',
response,
};
// we definitely know the input has not changed
if (hasChanged === false) {
return {
error: 'not-modified',
response,
};
}
}

const fileRequest = await sendRequest({
Expand Down Expand Up @@ -578,10 +583,7 @@ export async function createClient(
watch: _watch,
}: {
config: Config;
watch?: {
headers: Headers;
lastValue: string | undefined;
};
watch?: WatchValues;
}) => {
const inputPath = config.input.path;

Expand Down
Loading

0 comments on commit 97e39bc

Please sign in to comment.