Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bogus variable parsing handler #263

Merged
merged 36 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a64c667
Updated interface for variable parsing handler examples
Aug 14, 2022
a4d6e8a
Added examples to handlers
Aug 14, 2022
e3824f8
Moved variable parser input to separate component
Aug 14, 2022
dbb3831
Added example selector
Aug 14, 2022
225127c
Added BaseVariableParsingHandler for retrieving description from disk
Aug 18, 2022
67b3ac2
Added descriptions for all variable parsing handlers
Aug 18, 2022
7ba1c5e
Fixed unit test and added basic FakePersonDataVariableParsingHandler
Aug 18, 2022
da95020
Updated VariableHandlerModel; added description
Aug 18, 2022
2cbcaf1
Added new fields to DTOs of client and REST API
Aug 18, 2022
375141d
Refactored variable parsing selection component to show a list instea…
Aug 18, 2022
abfdaab
Yaml => Markdown
Aug 18, 2022
b6be02d
New implementation in VariableHandlerSelector.vue
Aug 18, 2022
613d23f
Added locales and documentation for FakeDataVariableParsingHHandler
Aug 19, 2022
7277e2e
Added interface for FakerService
Aug 19, 2022
c3d3e28
Added groundwork for fake data handler.
Aug 19, 2022
9497a15
Added all generators to FakerService
Aug 19, 2022
f3cd030
Fixed fake_data handler variable string
Aug 19, 2022
18883ba
Further built formatting
Aug 19, 2022
511da3b
Added formatting to all fake data generators
Aug 19, 2022
e7971cd
Updated VariableHandlerSelector.vue UI
Aug 19, 2022
401ce6d
Added unit test for BaseVariableParsingHandler
Aug 19, 2022
6cb3d36
Added unit tests for FakerService
Aug 19, 2022
25ae17d
Added more examples for FakeDataVariableParsingHandler
Aug 19, 2022
a5644ec
Updated unit tests for .NET client
Aug 19, 2022
8f499e4
Added unit tests for FakeDataVariableParsingHandler class
Aug 20, 2022
49334ac
Added example for fake data generation
Aug 20, 2022
3c61528
Updated examples Postman collection
Aug 20, 2022
ea82fd9
Updated fake data sample
Aug 20, 2022
77121ca
Added integration test for fake data
Aug 20, 2022
4e5b225
Updated Postman integration test
Aug 20, 2022
6e411a1
Fixed docs link
Aug 20, 2022
37595fb
Removed TODO item
Aug 20, 2022
2dbaf37
Updated docs
Aug 20, 2022
e44fed0
Code cov fix
Aug 20, 2022
ddb863b
Updated changelog
Aug 20, 2022
bb391ba
Fixed examples
Aug 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
- The YAML file stub contents are no longer logged when there are any YAML stub files and the logging is set to verbose (https://github.com/dukeofharen/httplaceholder/pull/256).
- When setting verbose logging on with environment variable, it now also logs the configuration (https://github.com/dukeofharen/httplaceholder/pull/256).
- Removed .NET client doc generation. Not that interesting, we already have an example project and the code is already documented for anyone interested (https://github.com/dukeofharen/httplaceholder/pull/256).
- Make it possible to select multiple examples when you are inserting a variable parsing handler in the stub response (https://github.com/dukeofharen/httplaceholder/issues/262).
- Make it possible to insert fake data in the stub response using [Bogus](https://github.com/bchavez/Bogus) (https://github.com/dukeofharen/httplaceholder/issues/72).

# BREAKING CHANGES
- Minor one, but the YAML file stub contents are no longer logged when there are any YAML stub files and the logging is set to verbose.
Expand Down
87 changes: 74 additions & 13 deletions docs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
- [Local and UTC date & time](#local-and-utc-date--time)
- [JSONPath](#jsonpath-parser)
- [Scenario state / hit count](#scenario-state--hit-count)
- [Fake data](#fake-data)
- [Reverse proxy](#reverse-proxy)
- **[REST API](#rest-api)**
- **[Configuration](#configuration)**
Expand Down Expand Up @@ -1938,6 +1939,65 @@ Current scenario hit count: 1
scenario123 hit count: 10
```

### Fake data

This body parser can be used to insert fake data in the response. The fake data is generated using [Bogus](https://github.com/bchavez/Bogus). The following data can be inserted using this parser:

- Address: zipcode, city, street_address, city_prefix, city_suffix, street_name, building_number, street_suffix, secondary_address, county, country, full_address, country_code, state, state_abbreviation, direction, cardinal_direction, ordinal_direction
- Name: first_name, last_name, full_name, prefix, suffix, job_title, job_descriptor, job_area, job_type
- Phone: phone_number
- Internet: email, example_email, user_name, user_name_unicode, domain_name, domain_word, domain_suffix, ip, port, ipv6, user_agent, mac, password, color, protocol, url, url_with_path, url_rooted_path
- Lorem: word, words, letter, sentence, sentences, paragraph, paragraphs, text, lines, slug
- Date: past, past_offset, soon, soon_offset, future, future_offset, recent, recent_offset, month, weekday, timezone_string
- Finance: account, account_name, amount, currency_name, currency_code, credit_card_number, credit_card_cvv, routing_number, bic, iban, bitcoin_address, ethereum_address, litecoin_address
- System: file_name, directory_path, file_path, common_file_name, mime_type, common_file_type, common_file_ext, file_type, file_ext, semver, android_id, apple_push_token
- Commerce: department, price, product_name, product, product_adjective, product_description, ean8, ean13

The following locales are supported (can be found on the [Bogus documentation](https://github.com/bchavez/Bogus)): af_ZA, fr_CH, ar, ge, az, hr, cz, id_ID, de, it, de_AT, ja, de_CH, ko, el, lv, en, nb_NO, en_AU, ne, en_AU_ocker, nl, en_BORK, nl_BE, en_CA, pl, en_GB, pt_BR, en_IE, pt_PT, en_IND, ro, en_NG, ru, en_US, sk, en_ZA, sv, es, tr, es_MX, uk, fa, vi, fi, zh_CN, fr, zh_TW, fr_CA, zu_ZA

The parser cane be inserted in the following ways:

- `((fake_data:first_name))` (only specify the generator).
- `((fake_data:en_US:first_name))` (specify generator and locale).
- `((fake_data:past:yyyy-MM-dd HH:mm:ss))` (specify generator and formatting string, if applicable).
- `((fake_data:en_US:past:yyyy-MM-dd HH:mm:ss))` (specify locale, generator and formatting string, if applicable).

```yml
- id: dynamic-mode-fake-data
conditions:
method: GET
url:
path:
equals: /dynamic-mode-fake-data.txt
response:
enableDynamicMode: true
contentType: text/plain;charset=utf-8
text: |
first_name: ((fake_data:pt_BR:first_name))
soon: ((fake_data:tr:soon:yyyy MMMM dd))
priority: 0
```

A request / response might look like this:

**URL**
```
http://localhost:5000/dynamic-mode-fake-data.txt
```

**Method**
```
GET
```

The response will look something like this:
```
first_name: Isabela
soon: 2022 Ağustos 20
```

A stub with all the possible fake data types can be found [here](samples/14.12-dynamic-mode-fake-data.yml) (or go to [samples](#samples)).

## Reverse proxy

HttPlaceholder contains a very simple reverse proxy as response option. In short, if you want to route some requests (or any request that doesn't match any other stub) to an external web service, you can do this with the reverse proxy response writer. Here are some examples that you can use.
Expand Down Expand Up @@ -2335,20 +2395,21 @@ httplaceholder --inputFile C:\path\to\samples\dir\01-get.yml
* Set response content type: [.yml](samples/18-content-type.yml)
* Stub images: [.yml](samples/19-stub-image.yml)
* Dynamic mode:
* Dynamic mode - query strings: [.yml](samples/14.1-dynamic-mode-query.yml)
* Dynamic mode - UUIDs: [.yml](samples/14.2-dynamic-mode-uuid.yml)
* Dynamic mode - request headers: [.yml](samples/14.3-dynamic-mode-request-header.yml)
* Dynamic mode - form post: [.yml](samples/14.4-dynamic-mode-form-post.yml)
* Dynamic mode - request body: [.yml](samples/14.5-dynamic-mode-request-body.yml)
* Dynamic mode - display URL: [.yml](samples/14.6-dynamic-mode-display-url.yml)
* Dynamic mode - root URL: [.yml](samples/14.7-dynamic-mode-root-url.yml)
* Dynamic mode - client IP: [.yml](samples/14.8-dynamic-mode-client-ip.yml)
* Dynamic mode - current local or UTC date and time: [.yml](samples/14.9-dynamic-mode-datetime-now.yml)
* Dynamic mode - JSONPath: [.yml](samples/14.10-dynamic-mode-jsonpath.yml)
* Dynamic mode - scenario state / hit count: [.yml](samples/14.11-dynamic-mode-scenario-state-hitcount.yml)
* Dynamic mode - query strings: [.yml](samples/14.1-dynamic-mode-query.yml)
* Dynamic mode - UUIDs: [.yml](samples/14.2-dynamic-mode-uuid.yml)
* Dynamic mode - request headers: [.yml](samples/14.3-dynamic-mode-request-header.yml)
* Dynamic mode - form post: [.yml](samples/14.4-dynamic-mode-form-post.yml)
* Dynamic mode - request body: [.yml](samples/14.5-dynamic-mode-request-body.yml)
* Dynamic mode - display URL: [.yml](samples/14.6-dynamic-mode-display-url.yml)
* Dynamic mode - root URL: [.yml](samples/14.7-dynamic-mode-root-url.yml)
* Dynamic mode - client IP: [.yml](samples/14.8-dynamic-mode-client-ip.yml)
* Dynamic mode - current local or UTC date and time: [.yml](samples/14.9-dynamic-mode-datetime-now.yml)
* Dynamic mode - JSONPath: [.yml](samples/14.10-dynamic-mode-jsonpath.yml)
* Dynamic mode - scenario state / hit count: [.yml](samples/14.11-dynamic-mode-scenario-state-hitcount.yml)
* Dynamic mode - fake data: [.yml](samples/14.12-dynamic-mode-fake-data.yml)
* Scenarios:
* Scenarios - hit counter: [.yml](samples/20.1-scenario-hit-counter.yml)
* Scenarios - state checking and setting: [.yml](samples/20.2-state-checking.yml)
* Scenarios - hit counter: [.yml](samples/20.1-scenario-hit-counter.yml)
* Scenarios - state checking and setting: [.yml](samples/20.2-state-checking.yml)

# Management interface

Expand Down
151 changes: 151 additions & 0 deletions docs/samples/14.12-dynamic-mode-fake-data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Response variable handler for inserting fake data in the response. The response contains all possible fake data types.
- id: dynamic-mode-fake-data
tenant: 14-dynamic
conditions:
method: GET
url:
path:
equals: /dynamic-mode-fake-data.txt
response:
enableDynamicMode: true
contentType: text/plain;charset=utf-8
text: |
Examples with locale:
first_name: ((fake_data:pt_BR:first_name))
soon: ((fake_data:tr:soon:yyyy MMMM dd))

Address:
zipcode: ((fake_data:zipcode))
city: ((fake_data:city))
street_address: ((fake_data:street_address))
city_prefix: ((fake_data:city_prefix))
city_suffix: ((fake_data:city_suffix))
street_name: ((fake_data:street_name))
building_number: ((fake_data:building_number))
street_suffix: ((fake_data:street_suffix))
secondary_address: ((fake_data:secondary_address))
county: ((fake_data:county))
country: ((fake_data:country))
full_address: ((fake_data:full_address))
country_code: ((fake_data:country_code))
state: ((fake_data:state))
state_abbreviation: ((fake_data:state_abbreviation))
direction: ((fake_data:direction))
cardinal_direction: ((fake_data:cardinal_direction))
ordinal_direction: ((fake_data:ordinal_direction))

Name:
first_name: ((fake_data:first_name))
last_name: ((fake_data:last_name))
full_name: ((fake_data:full_name))
prefix: ((fake_data:prefix))
suffix: ((fake_data:suffix))
job_title: ((fake_data:job_title))
job_descriptor: ((fake_data:job_descriptor))
job_area: ((fake_data:job_area))
job_type: ((fake_data:job_type))

Phone:
phone_number: ((fake_data:phone_number))

Internet:
email: ((fake_data:email))
example_email: ((fake_data:example_email))
user_name: ((fake_data:user_name))
user_name_unicode: ((fake_data:user_name_unicode))
domain_name: ((fake_data:domain_name))
domain_word: ((fake_data:domain_word))
domain_suffix: ((fake_data:domain_suffix))
ip: ((fake_data:ip))
port: ((fake_data:port))
ipv6: ((fake_data:ipv6))
user_agent: ((fake_data:user_agent))
mac: ((fake_data:mac))
password: ((fake_data:password))
color: ((fake_data:color))
protocol: ((fake_data:protocol))
url: ((fake_data:url))
url_with_path: ((fake_data:url_with_path))
url_rooted_path: ((fake_data:url_rooted_path))

Lorem:
word: ((fake_data:word))
words: ((fake_data:words))
words with formatting: ((fake_data:words:10))
letter: ((fake_data:letter))
letter with formatting: ((fake_data:letter:30))
sentence: ((fake_data:sentence))
sentence with formatting: ((fake_data:sentence:20))
sentences: ((fake_data:sentences))
sentences with formatting: ((fake_data:sentences:10))
paragraph: ((fake_data:paragraph))
paragraph with formatting: ((fake_data:paragraph:10))
paragraphs: ((fake_data:paragraphs))
paragraphs with formatting: ((fake_data:paragraphs:8))
text: ((fake_data:text))
lines: ((fake_data:lines))
lines with formatting: ((fake_data:lines:10))
slug: ((fake_data:slug))
slug with formatting: ((fake_data:slug:10))

Date:
past: ((fake_data:past))
past with formatting: ((fake_data:past:yyyy-MM-dd))
past_offset: ((fake_data:past_offset))
past_offset with formatting: ((fake_data:past_offset:yyyy-MM-dd))
soon: ((fake_data:soon))
soon with formatting: ((fake_data:soon:yyyy-MM-dd))
soon_offset: ((fake_data:soon_offset))
soon_offset with formatting: ((fake_data:soon_offset:yyyy-MM-dd))
future: ((fake_data:future))
future_with_formatting: ((fake_data:future:yyyy-MM-dd))
future_offset: ((fake_data:future_offset))
future_offset with formatting: ((fake_data:future_offset:yyyy-MM-dd))
recent: ((fake_data:recent))
recent with formatting: ((fake_data:recent:yyyy-MM-dd))
recent_offset: ((fake_data:recent_offset))
recent_offset with formatting: ((fake_data:recent_offset:yyyy-MM-dd))
month: ((fake_data:month))
weekday: ((fake_data:weekday))
timezone_string: ((fake_data:timezone_string))

Finance:
account: ((fake_data:account))
account_name: ((fake_data:account_name))
amount: ((fake_data:amount))
amount with formatting: ((fake_data:amount:0.000))
currency_name: ((fake_data:currency_name))
currency_code: ((fake_data:currency_code))
credit_card_number: ((fake_data:credit_card_number))
credit_card_cvv: ((fake_data:credit_card_cvv))
routing_number: ((fake_data:routing_number))
bic: ((fake_data:bic))
iban: ((fake_data:iban))
bitcoin_address: ((fake_data:bitcoin_address))
ethereum_address: ((fake_data:ethereum_address))
litecoin_address: ((fake_data:litecoin_address))

System:
file_name: ((fake_data:file_name))
directory_path: ((fake_data:directory_path))
file_path: ((fake_data:file_path))
common_file_name: ((fake_data:common_file_name))
mime_type: ((fake_data:mime_type))
common_file_type: ((fake_data:common_file_type))
common_file_ext: ((fake_data:common_file_ext))
file_type: ((fake_data:file_type))
file_ext: ((fake_data:file_ext))
semver: ((fake_data:semver))
android_id: ((fake_data:android_id))
apple_push_token: ((fake_data:apple_push_token))

Commerce:
department: ((fake_data:department))
price: ((fake_data:price))
product_name: ((fake_data:product_name))
product: ((fake_data:product))
product_adjective: ((fake_data:product_adjective))
product_description: ((fake_data:product_description))
ean8: ((fake_data:ean8))
ean13: ((fake_data:ean13))
priority: 0
20 changes: 20 additions & 0 deletions docs/samples/requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,26 @@
"response": []
}
]
},
{
"name": "12 Fake data",
"item": [
{
"name": "Fake data",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{rootUrl}}dynamic-mode-scenario-state.txt",
"host": [
"{{rootUrl}}dynamic-mode-scenario-state",
"txt"
]
}
},
"response": []
}
]
}
]
},
Expand Down
19 changes: 15 additions & 4 deletions gui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dayjs": "^1.11.2",
"highlight.js": "^11.5.1",
"js-yaml": "^4.1.0",
"marked": "^4.0.15",
"pinia": "^2.0.14",
"register-service-worker": "^1.7.2",
"sprintf-js": "^1.1.2",
Expand All @@ -34,6 +35,7 @@
"@types/codemirror": "^5.60.5",
"@types/js-yaml": "^4.0.5",
"@types/jsdom": "^16.2.14",
"@types/marked": "^4.0.5",
"@types/node": "^17.0.31",
"@types/sprintf-js": "^1.1.2",
"@types/toastr": "^2.1.39",
Expand All @@ -46,7 +48,6 @@
"eslint-plugin-vue": "^8.7.0",
"fs-extra": "^10.1.0",
"jsdom": "^19.0.0",
"marked": "^4.0.15",
"mustache": "^4.2.0",
"prettier": "^2.6.2",
"sass": "^1.51.0",
Expand Down
Loading