Skip to content

Commit

Permalink
feat: Adding support for response headers (#35)
Browse files Browse the repository at this point in the history
* WIP

* fixing liquid templates

* updating major version

* review comments

* fix interface name

* fix failing checks

* fix failing checks

* version finalization

* changing default fetcher liquid file

* cleanup

* cleanup - remove space
  • Loading branch information
vardanbansal-harness authored Oct 23, 2024
1 parent d43130f commit fa804fc
Show file tree
Hide file tree
Showing 54 changed files with 3,805 additions and 3,422 deletions.
14 changes: 12 additions & 2 deletions examples/output/github/hooks/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ export interface FetcherOptions<TQueryParams = never, TBody = never, THeaderPara

const JSON_HEADERS = ['application/json'];

interface ResponseContainer<TResponse, TResponseHeaders> {
content: TResponse;
headers: TResponseHeaders;
}

export async function fetcher<
TResponse = unknown,
TQueryParams = never,
TBody = never,
THeaderParams = HeadersInit,
>(options: FetcherOptions<TQueryParams, TBody, THeaderParams>): Promise<TResponse> {
>(
options: FetcherOptions<TQueryParams, TBody, THeaderParams>,
): Promise<ResponseContainer<TResponse, Record<string, any>>> {
const { body, url, queryParams, headers, ...rest } = options;

const response = await fetch(url, {
Expand All @@ -31,7 +38,10 @@ export async function fetcher<
const data = await (asJson ? response.json() : response.text());

if (response.ok) {
return data;
return {
content: data,
headers: {},
};
}

throw data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@ export interface ReposListForAuthenticatedUserProps
queryParams: ReposListForAuthenticatedUserQueryQueryParams;
}

export interface ReposListForAuthenticatedUserResponseContainer {
content: ReposListForAuthenticatedUserOkResponse;
headers: Record<string, any>;
}

export function reposListForAuthenticatedUser(
props: ReposListForAuthenticatedUserProps,
): Promise<ReposListForAuthenticatedUserOkResponse> {
): Promise<ReposListForAuthenticatedUserResponseContainer> {
return fetcher<
ReposListForAuthenticatedUserOkResponse,
ReposListForAuthenticatedUserQueryQueryParams,
Expand All @@ -82,14 +87,14 @@ export function useReposListForAuthenticatedUserQuery(
props: ReposListForAuthenticatedUserProps,
options?: Omit<
UseQueryOptions<
ReposListForAuthenticatedUserOkResponse,
ReposListForAuthenticatedUserResponseContainer,
ReposListForAuthenticatedUserErrorResponse
>,
'queryKey' | 'queryFn'
>,
) {
return useQuery<
ReposListForAuthenticatedUserOkResponse,
ReposListForAuthenticatedUserResponseContainer,
ReposListForAuthenticatedUserErrorResponse
>(
['repos/list-for-authenticated-user', props.queryParams],
Expand Down
1 change: 0 additions & 1 deletion examples/output/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export type { RequiresAuthenticationResponse } from './responses/RequiresAuthent
export type { ValidationFailedResponse } from './responses/ValidationFailedResponse';
export type { BasicError } from './schemas/BasicError';
export type { NullableLicenseSimple } from './schemas/NullableLicenseSimple';
export type { NullableSimpleUser } from './schemas/NullableSimpleUser';
export type { Repository } from './schemas/Repository';
export type { SimpleUser } from './schemas/SimpleUser';
export type { ValidationError } from './schemas/ValidationError';
93 changes: 0 additions & 93 deletions examples/output/github/schemas/NullableSimpleUser.ts

This file was deleted.

150 changes: 4 additions & 146 deletions examples/output/github/schemas/Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is autogenerated using @harnessio/oats-cli.
// Please do not modify this code directly.
import type { NullableLicenseSimple } from '../schemas/NullableLicenseSimple';
import type { NullableSimpleUser } from '../schemas/NullableSimpleUser';
import type { SimpleUser } from '../schemas/SimpleUser';

/**
Expand Down Expand Up @@ -170,6 +169,7 @@ export interface Repository {
* Whether downloads are enabled.
* @default true
* @example true
* @deprecated
*/
has_downloads: boolean;
/**
Expand Down Expand Up @@ -208,6 +208,7 @@ export interface Repository {
html_url: string;
/**
* Unique identifier of the repository
* @format int64
* @example 42
*/
id: number;
Expand Down Expand Up @@ -278,7 +279,6 @@ export interface Repository {
* @example "Team Environment"
*/
name: string;
network_count?: number;
/**
* @example "MDEwOlJlcG9zaXRvcnkxMjk2MjY5"
*/
Expand All @@ -292,7 +292,6 @@ export interface Repository {
* @example 0
*/
open_issues_count: number;
organization?: NullableSimpleUser;
owner: SimpleUser;
permissions?: {
admin: boolean;
Expand All @@ -319,7 +318,7 @@ export interface Repository {
*/
releases_url: string;
/**
* The size of the repository. Size is calculated hourly. When a repository is initially created, the size is 0.
* The size of the repository, in kilobytes. Size is calculated hourly. When a repository is initially created, the size is 0.
* @example 108
*/
size: number;
Expand Down Expand Up @@ -359,7 +358,6 @@ export interface Repository {
* @example "http://api.github.com/repos/octocat/Hello-World/statuses/{sha}"
*/
statuses_url: string;
subscribers_count?: number;
/**
* @format uri
* @example "http://api.github.com/repos/octocat/Hello-World/subscribers"
Expand All @@ -386,146 +384,6 @@ export interface Repository {
*/
teams_url: string;
temp_clone_token?: string;
template_repository?: {
allow_auto_merge?: boolean;
allow_merge_commit?: boolean;
allow_rebase_merge?: boolean;
allow_squash_merge?: boolean;
allow_update_branch?: boolean;
archive_url?: string;
archived?: boolean;
assignees_url?: string;
blobs_url?: string;
branches_url?: string;
clone_url?: string;
collaborators_url?: string;
comments_url?: string;
commits_url?: string;
compare_url?: string;
contents_url?: string;
contributors_url?: string;
created_at?: string;
default_branch?: string;
delete_branch_on_merge?: boolean;
deployments_url?: string;
description?: string;
disabled?: boolean;
downloads_url?: string;
events_url?: string;
fork?: boolean;
forks_count?: number;
forks_url?: string;
full_name?: string;
git_commits_url?: string;
git_refs_url?: string;
git_tags_url?: string;
git_url?: string;
has_downloads?: boolean;
has_issues?: boolean;
has_pages?: boolean;
has_projects?: boolean;
has_wiki?: boolean;
homepage?: string;
hooks_url?: string;
html_url?: string;
id?: number;
is_template?: boolean;
issue_comment_url?: string;
issue_events_url?: string;
issues_url?: string;
keys_url?: string;
labels_url?: string;
language?: string;
languages_url?: string;
/**
* The default value for a merge commit message.
*
* - `PR_TITLE` - default to the pull request's title.
* - `PR_BODY` - default to the pull request's body.
* - `BLANK` - default to a blank commit message.
*/
merge_commit_message?: 'BLANK' | 'PR_BODY' | 'PR_TITLE';
/**
* The default value for a merge commit title.
*
* - `PR_TITLE` - default to the pull request's title.
* - `MERGE_MESSAGE` - default to the classic title for a merge message (e.g., Merge pull request #123 from branch-name).
*/
merge_commit_title?: 'MERGE_MESSAGE' | 'PR_TITLE';
merges_url?: string;
milestones_url?: string;
mirror_url?: string;
name?: string;
network_count?: number;
node_id?: string;
notifications_url?: string;
open_issues_count?: number;
owner?: {
avatar_url?: string;
events_url?: string;
followers_url?: string;
following_url?: string;
gists_url?: string;
gravatar_id?: string;
html_url?: string;
id?: number;
login?: string;
node_id?: string;
organizations_url?: string;
received_events_url?: string;
repos_url?: string;
site_admin?: boolean;
starred_url?: string;
subscriptions_url?: string;
type?: string;
url?: string;
};
permissions?: {
admin?: boolean;
maintain?: boolean;
pull?: boolean;
push?: boolean;
triage?: boolean;
};
private?: boolean;
pulls_url?: string;
pushed_at?: string;
releases_url?: string;
size?: number;
/**
* The default value for a squash merge commit message:
*
* - `PR_BODY` - default to the pull request's body.
* - `COMMIT_MESSAGES` - default to the branch's commit messages.
* - `BLANK` - default to a blank commit message.
*/
squash_merge_commit_message?: 'BLANK' | 'COMMIT_MESSAGES' | 'PR_BODY';
/**
* The default value for a squash merge commit title:
*
* - `PR_TITLE` - default to the pull request's title.
* - `COMMIT_OR_PR_TITLE` - default to the commit's title (if only one commit) or the pull request's title (when more than one commit).
*/
squash_merge_commit_title?: 'COMMIT_OR_PR_TITLE' | 'PR_TITLE';
ssh_url?: string;
stargazers_count?: number;
stargazers_url?: string;
statuses_url?: string;
subscribers_count?: number;
subscribers_url?: string;
subscription_url?: string;
svn_url?: string;
tags_url?: string;
teams_url?: string;
temp_clone_token?: string;
topics?: string[];
trees_url?: string;
updated_at?: string;
url?: string;
use_squash_pr_title_as_default?: boolean;
visibility?: string;
watchers_count?: number;
} | null;
topics?: string[];
/**
* @example "http://api.github.com/repos/octocat/Hello-World/git/trees{/sha}"
Expand All @@ -542,7 +400,7 @@ export interface Repository {
*/
url: string;
/**
* Whether a squash merge commit can use the pull request title as default. **This property has been deprecated. Please use `squash_merge_commit_title` instead.
* Whether a squash merge commit can use the pull request title as default. **This property is closing down. Please use `squash_merge_commit_title` instead.
* @deprecated
*/
use_squash_pr_title_as_default?: boolean;
Expand Down
5 changes: 5 additions & 0 deletions examples/output/github/schemas/SimpleUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface SimpleUser {
*/
html_url: string;
/**
* @format int64
* @example 1
*/
id: number;
Expand Down Expand Up @@ -90,4 +91,8 @@ export interface SimpleUser {
* @example "https://api.github.com/users/octocat"
*/
url: string;
/**
* @example "public"
*/
user_view_type?: string;
}
Loading

0 comments on commit fa804fc

Please sign in to comment.