OpenAPI: Improve example request URL generation

This commit is contained in:
fuma-nama
2024-06-24 21:49:25 +08:00
parent 77a35ca91f
commit 464e44c7ed
8 changed files with 39 additions and 31 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-openapi': patch
---
Improve example request URL generation
+4 -1
View File
@@ -75,8 +75,11 @@ export function createEndpoint(
);
}
if (queryParams.size > 0)
pathWithParameters = `${pathWithParameters}?${queryParams.toString()}`;
return {
url: new URL(pathWithParameters, baseUrl).toString(),
url: new URL(`${baseUrl}${pathWithParameters}`).toString(),
body: bodySchema ? generateInput(method.method, bodySchema) : undefined,
responses,
method: method.method,
+10 -10
View File
@@ -83,7 +83,7 @@ The number of days per page.
<Request value={"cURL"}>
```bash
curl -X GET "https://api.fake-museum-example.com/special-events"
curl -X GET "https://api.fake-museum-example.com/v1/special-events?startDate=2023-02-23&endDate=2023-04-18&page=2&limit=15"
```
</Request>
@@ -91,7 +91,7 @@ curl -X GET "https://api.fake-museum-example.com/special-events"
<Request value={"JavaScript"}>
```js
fetch("https://api.fake-museum-example.com/special-events", {
fetch("https://api.fake-museum-example.com/v1/special-events?startDate=2023-02-23&endDate=2023-04-18&page=2&limit=15", {
method: "GET"
});
```
@@ -246,7 +246,7 @@ Price of a ticket for the special event
<Request value={"cURL"}>
```bash
curl -X POST "https://api.fake-museum-example.com/special-events" \
curl -X POST "https://api.fake-museum-example.com/v1/special-events" \
-d '{
"name": "Pirate Coding Workshop",
"location": "Computer Room",
@@ -263,7 +263,7 @@ curl -X POST "https://api.fake-museum-example.com/special-events" \
<Request value={"JavaScript"}>
```js
fetch("https://api.fake-museum-example.com/special-events", {
fetch("https://api.fake-museum-example.com/v1/special-events", {
method: "POST"
});
```
@@ -386,7 +386,7 @@ An identifier for a special event.
<Request value={"cURL"}>
```bash
curl -X GET "https://api.fake-museum-example.com/special-events/dad4bce8-f5cb-4078-a211-995864315e39"
curl -X GET "https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5cb-4078-a211-995864315e39"
```
</Request>
@@ -394,7 +394,7 @@ curl -X GET "https://api.fake-museum-example.com/special-events/dad4bce8-f5cb-40
<Request value={"JavaScript"}>
```js
fetch("https://api.fake-museum-example.com/special-events/dad4bce8-f5cb-4078-a211-995864315e39", {
fetch("https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5cb-4078-a211-995864315e39", {
method: "GET"
});
```
@@ -559,7 +559,7 @@ An identifier for a special event.
<Request value={"cURL"}>
```bash
curl -X PATCH "https://api.fake-museum-example.com/special-events/dad4bce8-f5cb-4078-a211-995864315e39" \
curl -X PATCH "https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5cb-4078-a211-995864315e39" \
-d '{
"name": "Pirate Coding Workshop",
"location": "Computer Room",
@@ -576,7 +576,7 @@ curl -X PATCH "https://api.fake-museum-example.com/special-events/dad4bce8-f5cb-
<Request value={"JavaScript"}>
```js
fetch("https://api.fake-museum-example.com/special-events/dad4bce8-f5cb-4078-a211-995864315e39", {
fetch("https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5cb-4078-a211-995864315e39", {
method: "PATCH"
});
```
@@ -700,7 +700,7 @@ An identifier for a special event.
<Request value={"cURL"}>
```bash
curl -X DELETE "https://api.fake-museum-example.com/special-events/dad4bce8-f5cb-4078-a211-995864315e39"
curl -X DELETE "https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5cb-4078-a211-995864315e39"
```
</Request>
@@ -708,7 +708,7 @@ curl -X DELETE "https://api.fake-museum-example.com/special-events/dad4bce8-f5cb
<Request value={"JavaScript"}>
```js
fetch("https://api.fake-museum-example.com/special-events/dad4bce8-f5cb-4078-a211-995864315e39", {
fetch("https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5cb-4078-a211-995864315e39", {
method: "DELETE"
});
```
@@ -73,7 +73,7 @@ The number of days per page.
<Request value={"cURL"}>
```bash
curl -X GET "https://api.fake-museum-example.com/museum-hours"
curl -X GET "https://api.fake-museum-example.com/v1/museum-hours?startDate=2023-02-23&page=2&limit=15"
```
</Request>
@@ -81,7 +81,7 @@ curl -X GET "https://api.fake-museum-example.com/museum-hours"
<Request value={"JavaScript"}>
```js
fetch("https://api.fake-museum-example.com/museum-hours", {
fetch("https://api.fake-museum-example.com/v1/museum-hours?startDate=2023-02-23&page=2&limit=15", {
method: "GET"
});
```
+4 -4
View File
@@ -89,7 +89,7 @@ Phone number for the ticket purchaser (optional).
<Request value={"cURL"}>
```bash
curl -X POST "https://api.fake-museum-example.com/tickets" \
curl -X POST "https://api.fake-museum-example.com/v1/tickets" \
-d '{
"ticketType": "event",
"eventId": "3be6453c-03eb-4357-ae5a-984a0e574a54",
@@ -104,7 +104,7 @@ curl -X POST "https://api.fake-museum-example.com/tickets" \
<Request value={"JavaScript"}>
```js
fetch("https://api.fake-museum-example.com/tickets", {
fetch("https://api.fake-museum-example.com/v1/tickets", {
method: "POST"
});
```
@@ -225,7 +225,7 @@ An identifier for a ticket to a museum event. Used to generate ticket image.
<Request value={"cURL"}>
```bash
curl -X GET "https://api.fake-museum-example.com/tickets/a54a57ca-36f8-421b-a6b4-2e8f26858a4c/qr"
curl -X GET "https://api.fake-museum-example.com/v1/tickets/a54a57ca-36f8-421b-a6b4-2e8f26858a4c/qr"
```
</Request>
@@ -233,7 +233,7 @@ curl -X GET "https://api.fake-museum-example.com/tickets/a54a57ca-36f8-421b-a6b4
<Request value={"JavaScript"}>
```js
fetch("https://api.fake-museum-example.com/tickets/a54a57ca-36f8-421b-a6b4-2e8f26858a4c/qr", {
fetch("https://api.fake-museum-example.com/v1/tickets/a54a57ca-36f8-421b-a6b4-2e8f26858a4c/qr", {
method: "GET"
});
```
+6 -6
View File
@@ -39,7 +39,7 @@ How many items to return at one time (max 100)
<Request value={"cURL"}>
```bash
curl -X GET "http://petstore.swagger.io/pets"
curl -X GET "http://petstore.swagger.io/v1/pets?limit=100"
```
</Request>
@@ -47,7 +47,7 @@ curl -X GET "http://petstore.swagger.io/pets"
<Request value={"JavaScript"}>
```js
fetch("http://petstore.swagger.io/pets", {
fetch("http://petstore.swagger.io/v1/pets?limit=100", {
method: "GET"
});
```
@@ -167,7 +167,7 @@ export interface Response {
<Request value={"cURL"}>
```bash
curl -X POST "http://petstore.swagger.io/pets" \
curl -X POST "http://petstore.swagger.io/v1/pets" \
-d '{
"id": 0,
"name": "string",
@@ -180,7 +180,7 @@ curl -X POST "http://petstore.swagger.io/pets" \
<Request value={"JavaScript"}>
```js
fetch("http://petstore.swagger.io/pets", {
fetch("http://petstore.swagger.io/v1/pets", {
method: "POST"
});
```
@@ -255,7 +255,7 @@ The id of the pet to retrieve
<Request value={"cURL"}>
```bash
curl -X GET "http://petstore.swagger.io/pets/string"
curl -X GET "http://petstore.swagger.io/v1/pets/string"
```
</Request>
@@ -263,7 +263,7 @@ curl -X GET "http://petstore.swagger.io/pets/string"
<Request value={"JavaScript"}>
```js
fetch("http://petstore.swagger.io/pets/string", {
fetch("http://petstore.swagger.io/v1/pets/string", {
method: "GET"
});
```
+4 -4
View File
@@ -53,7 +53,7 @@ The id of the api to fetch
<Request value={"cURL"}>
```bash
curl -X GET "https://api.unkey.dev/v1/apis.getApi"
curl -X GET "https://api.unkey.dev/v1/apis.getApi?apiId=api_1234"
```
</Request>
@@ -61,7 +61,7 @@ curl -X GET "https://api.unkey.dev/v1/apis.getApi"
<Request value={"JavaScript"}>
```js
fetch("https://api.unkey.dev/v1/apis.getApi", {
fetch("https://api.unkey.dev/v1/apis.getApi?apiId=api_1234", {
method: "GET"
});
```
@@ -549,7 +549,7 @@ Decrypt and display the raw key. Only possible if the key was encrypted when gen
<Request value={"cURL"}>
```bash
curl -X GET "https://api.unkey.dev/v1/apis.listKeys"
curl -X GET "https://api.unkey.dev/v1/apis.listKeys?apiId=api_1234&limit=100&cursor=string&ownerId=string&decrypt=true"
```
</Request>
@@ -557,7 +557,7 @@ curl -X GET "https://api.unkey.dev/v1/apis.listKeys"
<Request value={"JavaScript"}>
```js
fetch("https://api.unkey.dev/v1/apis.listKeys", {
fetch("https://api.unkey.dev/v1/apis.listKeys?apiId=api_1234&limit=100&cursor=string&ownerId=string&decrypt=true", {
method: "GET"
});
```
+4 -4
View File
@@ -59,7 +59,7 @@ Decrypt and display the raw key. Only possible if the key was encrypted when gen
<Request value={"cURL"}>
```bash
curl -X GET "https://api.unkey.dev/v1/keys.getKey"
curl -X GET "https://api.unkey.dev/v1/keys.getKey?keyId=key_1234&decrypt=true"
```
</Request>
@@ -67,7 +67,7 @@ curl -X GET "https://api.unkey.dev/v1/keys.getKey"
<Request value={"JavaScript"}>
```js
fetch("https://api.unkey.dev/v1/keys.getKey", {
fetch("https://api.unkey.dev/v1/keys.getKey?keyId=key_1234&decrypt=true", {
method: "GET"
});
```
@@ -3515,7 +3515,7 @@ The granularity of the usage data to fetch, currently only `day` is supported
<Request value={"cURL"}>
```bash
curl -X GET "https://api.unkey.dev/v1/keys.getVerifications"
curl -X GET "https://api.unkey.dev/v1/keys.getVerifications?keyId=key_1234&ownerId=chronark&start=1620000000000&end=1620000000000&granularity=day"
```
</Request>
@@ -3523,7 +3523,7 @@ curl -X GET "https://api.unkey.dev/v1/keys.getVerifications"
<Request value={"JavaScript"}>
```js
fetch("https://api.unkey.dev/v1/keys.getVerifications", {
fetch("https://api.unkey.dev/v1/keys.getVerifications?keyId=key_1234&ownerId=chronark&start=1620000000000&end=1620000000000&granularity=day", {
method: "GET"
});
```