Skip to content

Commit c9ec36a

Browse files
committed
fix: update the realworld entrypoint
1 parent 4afa0f4 commit c9ec36a

File tree

10 files changed

+505
-349
lines changed

10 files changed

+505
-349
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
BASE_URL=/
2-
VITE_API_HOST=https://api.realworld.io
2+
VITE_API_HOST=https://api.realworld.show

FRONTEND_INSTRUCTIONS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
### Using the hosted API
44

5-
Simply point your [API requests](https://github.com/gothinkster/realworld/tree/master/api) to `https://api.realworld.io/api` and you're good to go!
5+
Simply point your [API requests](https://github.com/gothinkster/realworld/tree/master/api) to `https://api.realworld.show/api` and you're good to go!
66

77
### Routing Guidelines
88

cypress/fixtures/article-comments.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"author": {
99
"username": "Gerome",
1010
"bio": null,
11-
"image": "https://api.realworld.io/images/demo-avatar.png",
11+
"image": "https://api.realworld.show/images/demo-avatar.png",
1212
"following": false
1313
}
1414
},
@@ -20,7 +20,7 @@
2020
"author": {
2121
"username": "Gerome",
2222
"bio": null,
23-
"image": "https://api.realworld.io/images/demo-avatar.png",
23+
"image": "https://api.realworld.show/images/demo-avatar.png",
2424
"following": false
2525
}
2626
}

cypress/fixtures/article.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"author": {
1111
"username": "plumrx",
1212
"bio": null,
13-
"image": "https://api.realworld.io/images/demo-avatar.png",
13+
"image": "https://api.realworld.show/images/demo-avatar.png",
1414
"following": false
1515
},
1616
"favorited": true,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"test:e2e:local": "cypress open --e2e -c baseUrl=http://localhost:5173",
1717
"test:e2e:prod": "cypress run --e2e -c baseUrl=https://vue3-realworld-example-app-mutoe.vercel.app",
1818
"test:unit": "vitest run",
19-
"generate:api": "curl -sL https://raw.githubusercontent.com/gothinkster/realworld/main/api/openapi.yml -o ./src/services/openapi.yml && sta -p ./src/services/openapi.yml -o ./src/services -n api.ts"
19+
"generate:api": "curl -sL https://raw.githubusercontent.com/gothinkster/realworld/refs/heads/main/api/openapi.yml -o ./src/services/openapi.yml && sta generate -p ./src/services/openapi.yml -o ./src/services -n api.ts"
2020
},
2121
"dependencies": {
2222
"insane": "^2.6.2",
@@ -42,7 +42,7 @@
4242
"msw": "^2.11.3",
4343
"rollup-plugin-analyzer": "^4.0.0",
4444
"simple-git-hooks": "^2.13.1",
45-
"swagger-typescript-api": "^13.0.16",
45+
"swagger-typescript-api": "^13.2.13",
4646
"typescript": "~5.9.2",
4747
"vite": "^7.1.7",
4848
"vitest": "^3.2.4",

pnpm-lock.yaml

Lines changed: 339 additions & 292 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/services/api.ts

Lines changed: 106 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable */
22
/* tslint:disable */
3+
// @ts-nocheck
34
/*
45
* ---------------------------------------------------------------
56
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
@@ -115,16 +116,22 @@ export interface FullRequestParams extends Omit<RequestInit, "body"> {
115116
cancelToken?: CancelToken;
116117
}
117118

118-
export type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
119+
export type RequestParams = Omit<
120+
FullRequestParams,
121+
"body" | "method" | "query" | "path"
122+
>;
119123

120124
export interface ApiConfig<SecurityDataType = unknown> {
121125
baseUrl?: string;
122126
baseApiParams?: Omit<RequestParams, "baseUrl" | "cancelToken" | "signal">;
123-
securityWorker?: (securityData: SecurityDataType | null) => Promise<RequestParams | void> | RequestParams | void;
127+
securityWorker?: (
128+
securityData: SecurityDataType | null,
129+
) => Promise<RequestParams | void> | RequestParams | void;
124130
customFetch?: typeof fetch;
125131
}
126132

127-
export interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response {
133+
export interface HttpResponse<D extends unknown, E extends unknown = unknown>
134+
extends Response {
128135
data: D;
129136
error: E;
130137
}
@@ -133,17 +140,19 @@ type CancelToken = Symbol | string | number;
133140

134141
export enum ContentType {
135142
Json = "application/json",
143+
JsonApi = "application/vnd.api+json",
136144
FormData = "multipart/form-data",
137145
UrlEncoded = "application/x-www-form-urlencoded",
138146
Text = "text/plain",
139147
}
140148

141149
export class HttpClient<SecurityDataType = unknown> {
142-
public baseUrl: string = "https://api.realworld.io/api";
150+
public baseUrl: string = "https://api.realworld.show/api";
143151
private securityData: SecurityDataType | null = null;
144152
private securityWorker?: ApiConfig<SecurityDataType>["securityWorker"];
145153
private abortControllers = new Map<CancelToken, AbortController>();
146-
private customFetch = (...fetchParams: Parameters<typeof fetch>) => fetch(...fetchParams);
154+
private customFetch = (...fetchParams: Parameters<typeof fetch>) =>
155+
fetch(...fetchParams);
147156

148157
private baseApiParams: RequestParams = {
149158
credentials: "same-origin",
@@ -176,9 +185,15 @@ export class HttpClient<SecurityDataType = unknown> {
176185

177186
protected toQueryString(rawQuery?: QueryParamsType): string {
178187
const query = rawQuery || {};
179-
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
188+
const keys = Object.keys(query).filter(
189+
(key) => "undefined" !== typeof query[key],
190+
);
180191
return keys
181-
.map((key) => (Array.isArray(query[key]) ? this.addArrayQueryParam(query, key) : this.addQueryParam(query, key)))
192+
.map((key) =>
193+
Array.isArray(query[key])
194+
? this.addArrayQueryParam(query, key)
195+
: this.addQueryParam(query, key),
196+
)
182197
.join("&");
183198
}
184199

@@ -189,10 +204,23 @@ export class HttpClient<SecurityDataType = unknown> {
189204

190205
private contentFormatters: Record<ContentType, (input: any) => any> = {
191206
[ContentType.Json]: (input: any) =>
192-
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
193-
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
194-
[ContentType.FormData]: (input: any) =>
195-
Object.keys(input || {}).reduce((formData, key) => {
207+
input !== null && (typeof input === "object" || typeof input === "string")
208+
? JSON.stringify(input)
209+
: input,
210+
[ContentType.JsonApi]: (input: any) =>
211+
input !== null && (typeof input === "object" || typeof input === "string")
212+
? JSON.stringify(input)
213+
: input,
214+
[ContentType.Text]: (input: any) =>
215+
input !== null && typeof input !== "string"
216+
? JSON.stringify(input)
217+
: input,
218+
[ContentType.FormData]: (input: any) => {
219+
if (input instanceof FormData) {
220+
return input;
221+
}
222+
223+
return Object.keys(input || {}).reduce((formData, key) => {
196224
const property = input[key];
197225
formData.append(
198226
key,
@@ -203,11 +231,15 @@ export class HttpClient<SecurityDataType = unknown> {
203231
: `${property}`,
204232
);
205233
return formData;
206-
}, new FormData()),
234+
}, new FormData());
235+
},
207236
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
208237
};
209238

210-
protected mergeRequestParams(params1: RequestParams, params2?: RequestParams): RequestParams {
239+
protected mergeRequestParams(
240+
params1: RequestParams,
241+
params2?: RequestParams,
242+
): RequestParams {
211243
return {
212244
...this.baseApiParams,
213245
...params1,
@@ -220,7 +252,9 @@ export class HttpClient<SecurityDataType = unknown> {
220252
};
221253
}
222254

223-
protected createAbortSignal = (cancelToken: CancelToken): AbortSignal | undefined => {
255+
protected createAbortSignal = (
256+
cancelToken: CancelToken,
257+
): AbortSignal | undefined => {
224258
if (this.abortControllers.has(cancelToken)) {
225259
const abortController = this.abortControllers.get(cancelToken);
226260
if (abortController) {
@@ -264,22 +298,34 @@ export class HttpClient<SecurityDataType = unknown> {
264298
const payloadFormatter = this.contentFormatters[type || ContentType.Json];
265299
const responseFormat = format || requestParams.format;
266300

267-
return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, {
268-
...requestParams,
269-
headers: {
270-
...(requestParams.headers || {}),
271-
...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}),
301+
return this.customFetch(
302+
`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`,
303+
{
304+
...requestParams,
305+
headers: {
306+
...(requestParams.headers || {}),
307+
...(type && type !== ContentType.FormData
308+
? { "Content-Type": type }
309+
: {}),
310+
},
311+
signal:
312+
(cancelToken
313+
? this.createAbortSignal(cancelToken)
314+
: requestParams.signal) || null,
315+
body:
316+
typeof body === "undefined" || body === null
317+
? null
318+
: payloadFormatter(body),
272319
},
273-
signal: (cancelToken ? this.createAbortSignal(cancelToken) : requestParams.signal) || null,
274-
body: typeof body === "undefined" || body === null ? null : payloadFormatter(body),
275-
}).then(async (response) => {
276-
const r = response.clone() as HttpResponse<T, E>;
320+
).then(async (response) => {
321+
const r = response as HttpResponse<T, E>;
277322
r.data = null as unknown as T;
278323
r.error = null as unknown as E;
279324

325+
const responseToParse = responseFormat ? response.clone() : response;
280326
const data = !responseFormat
281327
? r
282-
: await response[responseFormat]()
328+
: await responseToParse[responseFormat]()
283329
.then((data) => {
284330
if (r.ok) {
285331
r.data = data;
@@ -307,12 +353,14 @@ export class HttpClient<SecurityDataType = unknown> {
307353
* @title RealWorld Conduit API
308354
* @version 1.0.0
309355
* @license MIT License (https://opensource.org/licenses/MIT)
310-
* @baseUrl https://api.realworld.io/api
311-
* @contact RealWorld (https://www.realworld.how)
356+
* @baseUrl https://api.realworld.show/api
357+
* @contact RealWorld (https://realworld-docs.netlify.app/)
312358
*
313359
* Conduit API documentation
314360
*/
315-
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
361+
export class Api<
362+
SecurityDataType extends unknown,
363+
> extends HttpClient<SecurityDataType> {
316364
users = {
317365
/**
318366
* @description Login for existing user
@@ -509,7 +557,19 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
509557
) =>
510558
this.request<
511559
{
512-
articles: Article[];
560+
articles: {
561+
slug: string;
562+
title: string;
563+
description: string;
564+
tagList: string[];
565+
/** @format date-time */
566+
createdAt: string;
567+
/** @format date-time */
568+
updatedAt: string;
569+
favorited: boolean;
570+
favoritesCount: number;
571+
author: Profile;
572+
}[];
513573
articlesCount: number;
514574
},
515575
GenericErrorModel
@@ -553,7 +613,19 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
553613
) =>
554614
this.request<
555615
{
556-
articles: Article[];
616+
articles: {
617+
slug: string;
618+
title: string;
619+
description: string;
620+
tagList: string[];
621+
/** @format date-time */
622+
createdAt: string;
623+
/** @format date-time */
624+
updatedAt: string;
625+
favorited: boolean;
626+
favoritesCount: number;
627+
author: Profile;
628+
}[];
557629
articlesCount: number;
558630
},
559631
GenericErrorModel
@@ -716,7 +788,11 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
716788
* @request DELETE:/articles/{slug}/comments/{id}
717789
* @secure
718790
*/
719-
deleteArticleComment: (slug: string, id: number, params: RequestParams = {}) =>
791+
deleteArticleComment: (
792+
slug: string,
793+
id: number,
794+
params: RequestParams = {},
795+
) =>
720796
this.request<any, GenericErrorModel>({
721797
path: `/articles/${slug}/comments/${id}`,
722798
method: "DELETE",

0 commit comments

Comments
 (0)