Skip to content

Commit 344681c

Browse files
authored
Merge pull request #738 from marle3003/develop
Develop
2 parents c88831d + b672523 commit 344681c

File tree

19 files changed

+285
-121
lines changed

19 files changed

+285
-121
lines changed

api/handler_http.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ type operation struct {
4747
}
4848

4949
type param struct {
50-
Name string `json:"name"`
51-
Type string `json:"type"`
52-
Description string `json:"description,omitempty"`
53-
Required bool `json:"required"`
54-
Deprecated bool `json:"deprecated"`
55-
Style string `json:"style,omitempty"`
56-
Exploded bool `json:"exploded"`
57-
Schema *schema.Schema `json:"schema"`
50+
Name string `json:"name"`
51+
Type string `json:"type"`
52+
Description string `json:"description,omitempty"`
53+
Required bool `json:"required"`
54+
Deprecated bool `json:"deprecated"`
55+
Style string `json:"style,omitempty"`
56+
Exploded bool `json:"exploded"`
57+
AllowReserved bool `json:"allowReserved"`
58+
Schema *schema.Schema `json:"schema"`
5859
}
5960

6061
type response struct {
@@ -295,14 +296,15 @@ func getParameters(params openapi.Parameters) (result []param) {
295296
}
296297

297298
pi := param{
298-
Name: p.Value.Name,
299-
Type: string(p.Value.Type),
300-
Description: p.Value.Description,
301-
Required: p.Value.Required,
302-
Deprecated: p.Value.Deprecated,
303-
Style: p.Value.Style,
304-
Exploded: p.Value.IsExplode(),
305-
Schema: p.Value.Schema,
299+
Name: p.Value.Name,
300+
Type: string(p.Value.Type),
301+
Description: p.Value.Description,
302+
Required: p.Value.Required,
303+
Deprecated: p.Value.Deprecated,
304+
Style: p.Value.Style,
305+
Exploded: p.Value.IsExplode(),
306+
AllowReserved: p.Value.AllowReserved,
307+
Schema: p.Value.Schema,
306308
}
307309
if len(p.Description) > 0 {
308310
pi.Description = p.Description

api/handler_http_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func TestHandler_Http(t *testing.T) {
119119
)
120120
},
121121
requestUrl: "http://foo.api/api/services/http/foo",
122-
responseBody: `{"name":"foo","servers":[{"url":"/","description":""}],"paths":[{"path":"/foo/{bar}","operations":[{"method":"get","deprecated":false,"parameters":[{"name":"bar","type":"path","required":true,"deprecated":false,"exploded":false,"schema":{"type":"string"}}]}]}]`,
122+
responseBody: `{"name":"foo","servers":[{"url":"/","description":""}],"paths":[{"path":"/foo/{bar}","operations":[{"method":"get","deprecated":false,"parameters":[{"name":"bar","type":"path","required":true,"deprecated":false,"exploded":false,"allowReserved":false,"schema":{"type":"string"}}]}]}]`,
123123
},
124124
{
125125
name: "get http service with requestBody",

docs/config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@
110110
"delete": "javascript-api/mokapi-http/delete.md",
111111
"options": "javascript-api/mokapi-http/options.md",
112112
"patch": "javascript-api/mokapi-http/patch.md",
113+
"fetch": "javascript-api/mokapi-http/fetch.md",
113114
"HttpResponse": "javascript-api/mokapi-http/httpresponse.md",
115+
"FetchOptions": "javascript-api/mokapi-http/fetchoptions.md",
114116
"Args": "javascript-api/mokapi-http/args.md"
115117
}
116118
},

docs/configuration/static/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ For some parameters the file name can be specified directly, for others a file U
7272
The parameter `--configfile` provides the ability to define all parameters in a file.
7373
7474
```bash
75-
mokapi --providers-file file:///tmp/file.json
75+
mokapi --providers-file file:/tmp/file.json
7676
mokapi --providers-git-rootCaCert=/path/to/caCert.pem
7777
mokapi --cli-input=/path/to/config.json
7878
```

docs/javascript-api/mokapi-http/args.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ description: The Args object is used by functions in the Mokapi HTTP module to a
77
Args is an object used by functions in the module mokapi/http
88
and contains request-specific arguments like HTTP headers.
99

10-
| Name | Type | Description |
11-
|---------------|--------|------------------------------------------------------------------------------------------------------|
12-
| headers | object | Key-value pair object |
13-
| maxRedirects | | The number of redirects to follow. Default value is 5. A value of 0 (zero) prevents all redirection. |
10+
| Name | Type | Description |
11+
|--------------|----------------|------------------------------------------------------------------------------------------------------|
12+
| headers | object | Key-value pair object |
13+
| maxRedirects | number | The number of redirects to follow. Default value is 5. A value of 0 (zero) prevents all redirection. |
14+
| timeout | number, string | Maximum time to wait for the request to complete. Default timeout is 60 seconds ("60s") |
1415

1516
## Example of Accept header
1617

@@ -36,4 +37,16 @@ export default function() {
3637
})
3738
console.log(res.headers['Location'][0])
3839
}
40+
```
41+
42+
## Example timeout
43+
44+
```javascript
45+
import { get } from 'mokapi/http'
46+
47+
export default function() {
48+
const res = get('https://foo.bar', {
49+
timeout: '10s'
50+
})
51+
}
3952
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Fetch – fetch( url, [opts] )
3+
description: Use Mokapi's JavaScript API to send HTTP requests. Customize methods, headers, timeouts, and request data for testing and development.
4+
---
5+
# fetch( url, [opts] )
6+
7+
The `fetch()` function provides a Promise-based interface for making HTTP requests in Mokapi’s JavaScript environment.
8+
It works similarly to the browser’s Fetch API.
9+
10+
| Parameter | Type | Description |
11+
|-----------------|--------|------------------------------------------------------------------------------------------------------------------|
12+
| url | string | Request URL e.g. https://foo.bar |
13+
| opts (optional) | object | [FetchOptions](/docs/javascript-api/mokapi-http/fetchoptions.md) object containing additional request parameters |
14+
15+
## Returns
16+
17+
| Type | Description |
18+
|-------------------|--------------------------------------------------------------------------------------------------|
19+
| Promise<Response> | A promise that resolves to a [Response](/docs/javascript-api/mokapi-http/httpresponse.md) object |
20+
21+
## Example
22+
23+
```javascript
24+
import { put } from 'mokapi/http'
25+
26+
export default async function() {
27+
const res = await fetch('https://foo.bar/foo', {
28+
method: 'PUT',
29+
body: { 'foo': 'bar' },
30+
headers: { 'Content-Type': 'application/json' }
31+
})
32+
console.log(res.json())
33+
}
34+
```
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: FetchOptions | Mokapi HTTP Module Function Parameters
3+
description: The FetchOptions object defines parameters for the fetch() function in Mokapi's HTTP module, including method, headers, body, timeout, and redirect settings.
4+
---
5+
# FetchOptions
6+
7+
The `FetchOptions` object defines additional parameters for the [`fetch()`](/docs/javascript-api/mokapi-http/fetch.md) function in the `mokapi/http` module.
8+
It allows you to customize request behavior such as HTTP method, headers, body, timeout, and redirect handling.
9+
10+
| Name | Type | Description |
11+
|--------------|----------------|--------------------------------------------------------------------------------------------------------------|
12+
| method | string | The HTTP method used for the request (e.g. `"GET"`, `"POST"`, `"PUT"`). Defaults to `"GET"`. | |
13+
| body | object | The request body to send. Automatically serialized to JSON when `Content-Type` is set to `application/json`. |
14+
| headers | object | Key-value pairs representing HTTP headers to include with the request. |
15+
| maxRedirects | number | The number of redirects to follow. Default value is 5. A value of 0 (zero) prevents all redirection. |
16+
| timeout | number, string | Maximum time to wait for the request to complete. Default timeout is 60 seconds ("60s") |
17+
18+
## Example of Accept header
19+
20+
```javascript
21+
import { fetch } from 'mokapi/http'
22+
23+
export default async function() {
24+
const res = await fetch('https://foo.bar', {
25+
headers: {Accept: 'application/json'}
26+
})
27+
console.log(res.json())
28+
}
29+
```
30+
31+
## Send a PUT request with a JSON body
32+
33+
```javascript
34+
import { get } from 'mokapi/http'
35+
36+
export default function() {
37+
const res = get('https://foo.bar', {
38+
method: 'PUT',
39+
body: { foo: 'bar' }
40+
})
41+
console.log(res.json())
42+
}
43+
```

docs/javascript-api/overview.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ Provides core functions for scheduling jobs, handling events, and accessing envi
3333

3434
Functions to send HTTP requests within Mokapi scripts.
3535

36-
| Functions | Description |
37-
|-----------------------------------------------------------------------------------|-------------------------------|
38-
| [get( url, \[args\] )](/docs/javascript-api/mokapi-http/get.md) | Sends an HTTP GET request. |
39-
| [post( url, \[body\], \[args\] )](/docs/javascript-api/mokapi-http/post.md) | Sends an HTTP POST request |
40-
| [put( url, \[body\], \[args\] )](/docs/javascript-api/mokapi-http/put.md) | Sends an HTTP PUT request |
41-
| [head( url, \[args\] )](/docs/javascript-api/mokapi-http/head.md) | Sends an HTTP HEAD request |
42-
| [patch( url, \[body\], \[args\] )](/docs/javascript-api/mokapi-http/patch.md) | Sends an HTTP PATCH request |
43-
| [delete( url, \[body\], \[args\] )](/docs/javascript-api/mokapi-http/delete.md) | Sends an HTTP DELETE request |
44-
| [options( url, \[body\], \[args\] )](/docs/javascript-api/mokapi-http/options.md) | Sends an HTTP OPTIONS request |
36+
| Functions | Description |
37+
|-----------------------------------------------------------------------------------|----------------------------------------|
38+
| [get( url, \[args\] )](/docs/javascript-api/mokapi-http/get.md) | Sends an HTTP GET request. |
39+
| [post( url, \[body\], \[args\] )](/docs/javascript-api/mokapi-http/post.md) | Sends an HTTP POST request |
40+
| [put( url, \[body\], \[args\] )](/docs/javascript-api/mokapi-http/put.md) | Sends an HTTP PUT request |
41+
| [head( url, \[args\] )](/docs/javascript-api/mokapi-http/head.md) | Sends an HTTP HEAD request |
42+
| [patch( url, \[body\], \[args\] )](/docs/javascript-api/mokapi-http/patch.md) | Sends an HTTP PATCH request |
43+
| [delete( url, \[body\], \[args\] )](/docs/javascript-api/mokapi-http/delete.md) | Sends an HTTP DELETE request |
44+
| [options( url, \[body\], \[args\] )](/docs/javascript-api/mokapi-http/options.md) | Sends an HTTP OPTIONS request |
45+
| [fetch( url, \[opts\] )](/docs/javascript-api/mokapi-http/fetch.md) | Create an HTTP request using Fetch API |
4546

4647
### mokapi/faker (Mock Data Generator)
4748

0 commit comments

Comments
 (0)