Skip to content

Commit 25b2de2

Browse files
author
Stefan Cooper
committed
fix: updates to fix broken tests
Signed-off-by: Stefan Cooper <[email protected]>
1 parent 356d8ab commit 25b2de2

File tree

3 files changed

+81
-34
lines changed

3 files changed

+81
-34
lines changed

src/schema-routes/schema-routes.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,16 @@ export class SchemaRoutes {
331331

332332
/* content: { "multipart/form-data": { schema: {...} }, "application/json": { schema: {...} } } */
333333

334+
const contentTypes = Object.keys(content);
335+
336+
// if there's only one content type, return it
337+
if (contentTypes.length === 1 && content[contentTypes[0]]?.schema) {
338+
return {
339+
...content[contentTypes[0]].schema,
340+
dataType: contentTypes[0],
341+
};
342+
}
343+
334344
// Check if there are multiple media types with schemas
335345
const schemasWithDataTypes = [];
336346
for (const dataType in content) {
@@ -347,8 +357,23 @@ export class SchemaRoutes {
347357
return schemasWithDataTypes[0];
348358
}
349359

350-
// If there are multiple schemas, create a oneOf schema to generate a union type
360+
// If there are multiple schemas with different structures, create a oneOf schema to generate a union type
351361
if (schemasWithDataTypes.length > 1) {
362+
// Check if all schemas are structurally the same
363+
// If they are, just return the first one
364+
const firstSchema = schemasWithDataTypes[0];
365+
const allSchemasAreSame = schemasWithDataTypes.every((schema) =>
366+
lodash.isEqual(
367+
lodash.omit(schema, "dataType"),
368+
lodash.omit(firstSchema, "dataType"),
369+
),
370+
);
371+
372+
if (allSchemasAreSame) {
373+
return firstSchema;
374+
}
375+
376+
// Otherwise, create a union type
352377
return {
353378
oneOf: schemasWithDataTypes,
354379
dataType: schemasWithDataTypes[0].dataType, // Use the first dataType for compatibility

tests/__snapshots__/extended.test.ts.snap

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export interface BlockFeed {
217217
id?: string;
218218
}
219219

220-
export interface ChartDataData {
220+
export type ChartDataData = {
221221
/** The names of the columns returned as data. */
222222
columns?: string[];
223223
/** The actual chart data. */
@@ -228,7 +228,7 @@ export interface ChartDataData {
228228
name?: string;
229229
};
230230
parameters?: object;
231-
}
231+
};
232232

233233
export interface ChartDataParams {
234234
/**
@@ -678,12 +678,12 @@ export interface GetBlockParams {
678678
username: string;
679679
}
680680

681-
export interface GetCurrentUserThrottleData {
681+
export type GetCurrentUserThrottleData = {
682682
/** Actions taken inside the time window. */
683683
active_data_rate?: number;
684684
/** Max possible actions inside the time window (usually 1 minute). */
685685
data_rate_limit?: number;
686-
}
686+
};
687687

688688
export interface GetCurrentUserThrottleParams {
689689
/** a valid username string */
@@ -8732,13 +8732,12 @@ export interface SignRequestParams {
87328732
test?: number;
87338733
}
87348734

8735-
/** JWT */
8736-
export interface SignRetrieveData {
8735+
export type SignRetrieveData = {
87378736
exp?: number;
87388737
field?: string;
87398738
/** base64safe encoded public signing key */
87408739
sub?: string;
8741-
}
8740+
};
87428741

87438742
export type SignRetrieveError = Error;
87448743

@@ -13323,7 +13322,9 @@ export interface ActivityListRepoNotificationsForAuthenticatedUserParams {
1332313322
since?: string;
1332413323
}
1332513324

13326-
export type ActivityListReposStarredByAuthenticatedUserData = Repository[];
13325+
export type ActivityListReposStarredByAuthenticatedUserData =
13326+
| Repository[]
13327+
| StarredRepository[];
1332713328

1332813329
export interface ActivityListReposStarredByAuthenticatedUserParams {
1332913330
/**
@@ -13366,7 +13367,9 @@ export enum ActivityListReposStarredByAuthenticatedUserParams1SortEnum {
1336613367
Updated = "updated",
1336713368
}
1336813369

13369-
export type ActivityListReposStarredByUserData = Repository[];
13370+
export type ActivityListReposStarredByUserData =
13371+
| Repository[]
13372+
| StarredRepository[];
1337013373

1337113374
export interface ActivityListReposStarredByUserParams {
1337213375
/**
@@ -13426,7 +13429,7 @@ export interface ActivityListReposWatchedByUserParams {
1342613429
username: string;
1342713430
}
1342813431

13429-
export type ActivityListStargazersForRepoData = SimpleUser[];
13432+
export type ActivityListStargazersForRepoData = SimpleUser[] | Stargazer[];
1343013433

1343113434
export interface ActivityListStargazersForRepoParams {
1343213435
owner: string;
@@ -28162,7 +28165,9 @@ export interface ReposGetCommunityProfileMetricsParams {
2816228165
repo: string;
2816328166
}
2816428167

28165-
export type ReposGetContentData = ContentTree;
28168+
export type ReposGetContentData =
28169+
| ContentTree
28170+
| (ContentDirectory | ContentFile | ContentSymlink | ContentSubmodule);
2816628171

2816728172
export interface ReposGetContentParams {
2816828173
owner: string;
@@ -60092,7 +60097,10 @@ export class Api<
6009260097
data: ReposCreateForkPayload,
6009360098
params: RequestParams = {},
6009460099
) =>
60095-
this.request<ReposCreateForkData, BasicError | ValidationError>({
60100+
this.request<
60101+
ReposCreateForkData,
60102+
(BasicError | ScimError) | BasicError | ValidationError
60103+
>({
6009660104
path: \`/repos/\${owner}/\${repo}/forks\`,
6009760105
method: "POST",
6009860106
body: data,
@@ -61604,13 +61612,15 @@ export class Api<
6160461612
{ owner, repo, ...query }: ReposListCommitsParams,
6160561613
params: RequestParams = {},
6160661614
) =>
61607-
this.request<ReposListCommitsData, BasicError>({
61608-
path: \`/repos/\${owner}/\${repo}/commits\`,
61609-
method: "GET",
61610-
query: query,
61611-
format: "json",
61612-
...params,
61613-
}),
61615+
this.request<ReposListCommitsData, (BasicError | ScimError) | BasicError>(
61616+
{
61617+
path: \`/repos/\${owner}/\${repo}/commits\`,
61618+
method: "GET",
61619+
query: query,
61620+
format: "json",
61621+
...params,
61622+
},
61623+
),
6161461624

6161561625
/**
6161661626
* @description Users with pull access in a repository can view commit statuses for a given ref. The ref can be a SHA, a branch name, or a tag name. Statuses are returned in reverse chronological order. The first status in the list will be the latest one. This resource is also available via a legacy route: \`GET /repos/:owner/:repo/statuses/:ref\`.
@@ -61729,7 +61739,7 @@ export class Api<
6172961739
{ owner, repo, ...query }: ReposListForksParams,
6173061740
params: RequestParams = {},
6173161741
) =>
61732-
this.request<ReposListForksData, BasicError>({
61742+
this.request<ReposListForksData, BasicError | ScimError>({
6173361743
path: \`/repos/\${owner}/\${repo}/forks\`,
6173461744
method: "GET",
6173561745
query: query,
@@ -62414,7 +62424,7 @@ export class Api<
6241462424
) =>
6241562425
this.request<
6241662426
ReposUpdateInformationAboutPagesSiteData,
62417-
BasicError | ValidationError
62427+
(BasicError | ScimError) | ValidationError
6241862428
>({
6241962429
path: \`/repos/\${owner}/\${repo}/pages\`,
6242062430
method: "PUT",
@@ -64787,7 +64797,7 @@ export class Api<
6478764797
) =>
6478864798
this.request<
6478964799
ReposCreateForAuthenticatedUserData,
64790-
BasicError | ValidationError
64800+
(BasicError | ScimError) | BasicError | ValidationError
6479164801
>({
6479264802
path: \`/user/repos\`,
6479364803
method: "POST",

tests/__snapshots__/simple.test.ts.snap

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20642,7 +20642,8 @@ export class Api<
2064220642
documentation_url: string;
2064320643
message: string;
2064420644
}
20645-
| (ValidationError | ValidationErrorSimple)
20645+
| ValidationError
20646+
| ValidationErrorSimple
2064620647
>({
2064720648
path: \`/orgs/\${org}\`,
2064820649
method: "PATCH",
@@ -24462,7 +24463,8 @@ export class Api<
2446224463
this.request<
2446324464
ProjectCard,
2446424465
| BasicError
24465-
| (ValidationError | ValidationErrorSimple)
24466+
| ValidationError
24467+
| ValidationErrorSimple
2446624468
| {
2446724469
code?: string;
2446824470
documentation_url?: string;
@@ -27970,7 +27972,7 @@ export class Api<
2797027972
},
2797127973
params: RequestParams = {},
2797227974
) =>
27973-
this.request<Commit[], BasicError>({
27975+
this.request<Commit[], (BasicError | ScimError) | BasicError>({
2797427976
path: \`/repos/\${owner}/\${repo}/commits\`,
2797527977
method: "GET",
2797627978
query: query,
@@ -28365,7 +28367,11 @@ export class Api<
2836528367
},
2836628368
params: RequestParams = {},
2836728369
) =>
28368-
this.request<ContentTree, BasicError>({
28370+
this.request<
28371+
| ContentTree
28372+
| (ContentDirectory | ContentFile | ContentSymlink | ContentSubmodule),
28373+
BasicError
28374+
>({
2836928375
path: \`/repos/\${owner}/\${repo}/contents/\${path}\`,
2837028376
method: "GET",
2837128377
query: query,
@@ -28895,7 +28901,7 @@ export class Api<
2889528901
},
2889628902
params: RequestParams = {},
2889728903
) =>
28898-
this.request<MinimalRepository[], BasicError>({
28904+
this.request<MinimalRepository[], BasicError | ScimError>({
2889928905
path: \`/repos/\${owner}/\${repo}/forks\`,
2890028906
method: "GET",
2890128907
query: query,
@@ -28920,7 +28926,10 @@ export class Api<
2892028926
},
2892128927
params: RequestParams = {},
2892228928
) =>
28923-
this.request<Repository, BasicError | ValidationError>({
28929+
this.request<
28930+
Repository,
28931+
(BasicError | ScimError) | BasicError | ValidationError
28932+
>({
2892428933
path: \`/repos/\${owner}/\${repo}/forks\`,
2892528934
method: "POST",
2892628935
body: data,
@@ -31601,7 +31610,7 @@ export class Api<
3160131610
},
3160231611
params: RequestParams = {},
3160331612
) =>
31604-
this.request<void, BasicError | ValidationError>({
31613+
this.request<void, (BasicError | ScimError) | ValidationError>({
3160531614
path: \`/repos/\${owner}/\${repo}/pages\`,
3160631615
method: "PUT",
3160731616
body: data,
@@ -33275,7 +33284,7 @@ export class Api<
3327533284
},
3327633285
params: RequestParams = {},
3327733286
) =>
33278-
this.request<SimpleUser[], ValidationError>({
33287+
this.request<SimpleUser[] | Stargazer[], ValidationError>({
3327933288
path: \`/repos/\${owner}/\${repo}/stargazers\`,
3328033289
method: "GET",
3328133290
query: query,
@@ -37318,7 +37327,10 @@ export class Api<
3731837327
},
3731937328
params: RequestParams = {},
3732037329
) =>
37321-
this.request<Repository, BasicError | ValidationError>({
37330+
this.request<
37331+
Repository,
37332+
(BasicError | ScimError) | BasicError | ValidationError
37333+
>({
3732237334
path: \`/user/repos\`,
3732337335
method: "POST",
3732437336
body: data,
@@ -37424,7 +37436,7 @@ export class Api<
3742437436
},
3742537437
params: RequestParams = {},
3742637438
) =>
37427-
this.request<Repository[], BasicError>({
37439+
this.request<Repository[] | StarredRepository[], BasicError>({
3742837440
path: \`/user/starred\`,
3742937441
method: "GET",
3743037442
query: query,
@@ -38191,7 +38203,7 @@ export class Api<
3819138203
},
3819238204
params: RequestParams = {},
3819338205
) =>
38194-
this.request<Repository[], any>({
38206+
this.request<Repository[] | StarredRepository[], any>({
3819538207
path: \`/users/\${username}/starred\`,
3819638208
method: "GET",
3819738209
query: query,

0 commit comments

Comments
 (0)