Skip to content

Commit e30f825

Browse files
committed
Mark & treat built-in APIs differently to other public APIs
1 parent ded7823 commit e30f825

File tree

7 files changed

+37
-14
lines changed

7 files changed

+37
-14
lines changed

extra-apis/ethereum.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"name": "CC0-1.0",
88
"url": "https://creativecommons.org/publicdomain/zero/1.0/legalcode"
99
},
10-
"version": "0.0.0"
10+
"version": "0.0.0",
11+
"x-httptoolkit-builtin-api": true
1112
},
1213
"servers": [
1314
{ "url": "http://localhost:8545" },

extra-apis/ipfs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"x-providerName": "IPFS",
88
"x-logo": {
99
"url": "https://raw.githubusercontent.com/ipfs/ipfs-docs/55fe8bc6a53ba3b9023951fb4b432efbbc81fba5/docs/.vuepress/public/images/ipfs-logo.svg"
10-
}
10+
},
11+
"x-httptoolkit-builtin-api": true
1112
},
1213
"servers": [
1314
{

src/components/view/http/http-details-pane.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ export class HttpDetailsPane extends React.Component<{
100100
} = uiStore!;
101101
const { requestBreakpoint, responseBreakpoint } = exchange;
102102

103-
// The full API details - only available for paid usage, so we drop this
104-
// for non-paid users at this stage.
105-
const apiExchange = isPaidUser ? exchange.api : undefined;
103+
// The full API details - for paid APIs, and non-paid users, we don't show
104+
// the detailed API data in any of the cards, we just show the name (below)
105+
// in a collapsed API card.
106+
const apiExchange = (isPaidUser || exchange.api?.isBuiltInApi)
107+
? exchange.api
108+
: undefined;
106109

107110
// We do still want the API name though, if there is one - we use this to
108111
// show non-paid users when API data might be available, iff this request
@@ -190,16 +193,16 @@ export class HttpDetailsPane extends React.Component<{
190193
) {
191194
if (!apiName) return null;
192195

193-
if (!this.props.accountStore!.isPaidUser) {
194-
// If you're not paid, but we do recognize this as a specific API
195-
// operation, we show a placeholder:
196+
if (!apiExchange) {
197+
// If you're not a paid user, and it's a paid API, then we only have
198+
// the basic API name here but no details, so we just show a placeholder:
196199
return <HttpApiPlaceholderCard
197200
{...this.cardProps.api}
198201
apiName={apiName}
199202
/>;
200203
}
201204

202-
// If paid & we have a name, we must have full API details, show them:
205+
// If paid/built-in API & we have a name, we must have full API details, show them:
203206
return <HttpApiCard
204207
{...this.cardProps.api}
205208
apiName={apiName}

src/model/api/api-interfaces.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ export type ApiSpec =
2020
| OpenRpcDocument;
2121

2222
export interface ApiExchange {
23+
24+
/**
25+
* Built-in API specs are special: they're shown for free users too, and they're
26+
* shown differently in the list (highlighting the operation, not the normal
27+
* lower-level HTTP details).
28+
*/
29+
readonly isBuiltInApi: boolean;
30+
2331
readonly service: ApiService;
2432
readonly operation: ApiOperation;
2533
readonly request: ApiRequest;

src/model/api/jsonrpc.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ interface MatchedOperation {
7171
export class JsonRpcApiExchange implements ApiExchange {
7272

7373
constructor(
74-
private _api: OpenRpcMetadata,
75-
private _exchange: HttpExchange,
74+
_api: OpenRpcMetadata,
75+
_exchange: HttpExchange,
7676
private _rpcMethod: MatchedOperation | ErrorLike
7777
) {
78+
this.isBuiltInApi = _api.spec.info['x-httptoolkit-builtin-api'] === true;
79+
7880
this.service = new JsonRpcApiService(_api);
7981

8082
if (isErrorLike(_rpcMethod)) {
@@ -92,6 +94,8 @@ export class JsonRpcApiExchange implements ApiExchange {
9294
}
9395
}
9496

97+
readonly isBuiltInApi: boolean;
98+
9599
readonly service: ApiService;
96100
readonly operation: ApiOperation;
97101
readonly request: ApiRequest;

src/model/api/openapi-schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export const openApiSchema = {
105105
"type": "string"
106106
}
107107
}
108+
},
109+
"x-httptoolkit-builtin-api": {
110+
"type": "boolean",
111+
"default": false
108112
}
109113
},
110114
"additionalProperties": false

src/model/api/openapi.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ import {
2121
} from "../../types";
2222
import { firstMatch, empty, lastHeader } from '../../util';
2323
import { formatAjvError } from '../../util/json-schema';
24-
import { reportError } from '../../errors';
2524

2625
import {
2726
ApiExchange,
2827
ApiService,
2928
ApiOperation,
3029
ApiRequest,
3130
ApiResponse,
32-
ApiParameter,
33-
ApiMetadata
31+
ApiParameter
3432
} from './api-interfaces';
3533
import { OpenApiMetadata } from './build-api-metadata';
3634
import { fromMarkdown } from '../markdown';
@@ -278,6 +276,8 @@ function stripTags(input: string | undefined): string | undefined {
278276

279277
export class OpenApiExchange implements ApiExchange {
280278
constructor(api: OpenApiMetadata, exchange: HttpExchange) {
279+
this.isBuiltInApi = api.spec.info['x-httptoolkit-builtin-api'] === true;
280+
281281
const { request } = exchange;
282282
this.service = new OpenApiService(api.spec);
283283

@@ -295,6 +295,8 @@ export class OpenApiExchange implements ApiExchange {
295295
private _spec: OpenAPIObject;
296296
private _opSpec: MatchedOperation;
297297

298+
public readonly isBuiltInApi: boolean;
299+
298300
public readonly service: ApiService;
299301
public readonly operation: ApiOperation;
300302
public readonly request: ApiRequest;

0 commit comments

Comments
 (0)