Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@ pipenv install

## Usage

- Run `pipenv run python serialize_data.py` to generate JSON file named `endpoints_data.json`. Optionally, you can specify the path of the proposed endpoints docs using `--file-path` option like:
- Run `pipenv run python serialize_data.py` to generate JSON file named `endpoints_data.json`. However, you have to specify the path of the proposed endpoints docs as

```pipenv run python serialize_data.py --file-path /pat/to/endpoints_data.json```
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, the endpoints_data.json was wrong in this command earlier? It needed a .md file instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The last commit does that.

```pipenv run python serialize_data.py /path/to/proposed_endpoints.md```

You can also provide multiple files by using the regex shorthand as

```pipenv run python serialize_data.py *.md```

If files resides at different paths, then you may provide them as positional argument to it. For e.g

```pipenv run python serialize_data.py /path/to/some_file.md /path/to/another_file.md```
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show in example that you meant another path ;)


- Run `pipenv run python create_mock_endpoints.py` to generate `app.py` with all the code for the Mocked end points.

Expand Down
25 changes: 17 additions & 8 deletions src/serialize_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,24 @@ def get_json_from_endpoints(lines):


@click.command()
@click.option(
"--file-path",
default="proposed_endpoints.md",
help="Path for the proposed endpoints docs",
@click.argument(
"file_paths",
nargs=-1,
type=click.Path(exists=True),
required=True,
)
def generate_json_from_docs_file(file_path):
lines = None
with open(file_path, "r") as endpoint_file:
lines = endpoint_file.read()
def generate_json_from_docs_file(file_paths):
"""
FILE_PATHS: Path(s) to the proposed endpoints docs. This can have multiple file values like

serialize_data.py proposed_endpoint.md api_endpoint.md

serialize_data.py *.md
"""
lines = ''
for path in file_paths:
with open(path, "r") as endpoint_file:
lines += endpoint_file.read()
json_data = get_json_from_endpoints(lines)

with open("endpoints_data.json", "w") as json_file:
Expand Down