Skip to content

Commit

Permalink
Update Readme (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan5e3s6ares authored Aug 20, 2024
1 parent ff1fcb6 commit f284d6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ run/tests:
server/start:
uvicorn main:app --reload

docker/start:
arma/start:
docker compose up --build -d

coverage:
Expand Down
90 changes: 16 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<p align="center">
<em>ARMA, high performance, easy to learn, fast to code, ready for production</em>
</p>

# A Real Mock API

ARMA is a set of packages for API mocking and contract testing with **OpenAPI v3.x**.
Expand All @@ -19,89 +20,30 @@ ARMA is an open-source HTTP server run from the command-line. It provides mockin

### Start Self-hosted ARMA

Update a_real_settings.json
```json
{
"mock_api_swaggerUrl": "https//www.apitomock.com/doc/swagger.json",
"update_on_start": true,
}
```

ARMA requires

- Docker-Compose >= 2.29.1

```bash
docker compose up --build
make arma/start
```
<p>
<p>
<p>

### Mocking

ARMA can help you create a fake "mock" based off an OpenAPI document, which helps people see how your API will work before you even have it built. Run it locally with the HTTP server.

Update the file:
- a_real_settings.json

Add one of the following keys to mock from URL:

| Key | Type | Description |
| :---: | :---: | :---: |
| mock_api_swaggerUrl | string | Mock an API from Json Swagger URL |
| mock_api_swaggerYamlUrl | string | Mock an API from Yaml Swagger URL |
| update_on_start | boolean | True to update allways after restart the container |
| update_time_interval | integer | Feature not ready
** HINT - For the first run, you need to set ```"update_on_start": true```

Add one of the following keys to mock from file:

| Key | Type | Description |
| :---: | :---: | :---: |
| mock_api_from_json_file | boolean | Mock an API from Json Swagger FILE |
| mock_api_from_yaml_file | boolean | Mock an API from Yaml Swagger FILE |
* save the file in the folder ```files``` with the name ```openapi.json or openapi.yaml```

### Scenarios

With ARMA you can create scenarios by adding your own uses cases to OpenAPI paths.

Update the file:
- functions_to_endpoints/main.py

Add one of the following keys to a_real_settings file:

| Key | Type | Description |
| :---: | :---: | :---: |
| <path_url> | string | The url key from paths and your Class Name|
------
### [Click here to Full Documentation](https://dan5e3s6ares.github.io/arma/)
------

Example Function:

```python
from fastapi import Request
from fastapi.responses import JSONResponse
from jsf import JSF


class SimpleFunction:

@classmethod
async def response(cls, request: Request, url_data: dict):

return JSONResponse("from SimpleFunction", status_code=201)


class CheckBodyVariableValue:

@classmethod
async def response(cls, request: Request, url_data: dict):
payload = await request.json()

if payload["payload_id"] == "123":
faker = JSF(url_data['responses']["200"]['schema'])
fake_payload_response = faker.generate(
n=1, use_defaults=True, use_examples=True
)
return JSONResponse(fake_payload_response, status_code=200)
else:
faker = JSF(url_data['responses']["405"]['schema'])
fake_payload_response = faker.generate(
n=1, use_defaults=True, use_examples=True
)
return JSONResponse(fake_payload_response, status_code=405)


```


### 🏁 Help Others Utilize ARMA
Expand Down

0 comments on commit f284d6e

Please sign in to comment.