Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ 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`. Optionally, you can specify the path of the proposed endpoints docs using `--file-path` or `-f` option like:

```pipenv run python serialize_data.py --file-path /pat/to/endpoints_data.json```
Copy link
Copy Markdown
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
Copy Markdown
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 --file-path /path/to/proposed_endpoints.md```

You can also provide multiple files as

```pipenv run python serialize_data.py -f /path/to/proposed_endpoints.md -f path/to/another_proposed_endpoints.md```
Copy link
Copy Markdown
Owner

@CuriousLearner CuriousLearner Jul 18, 2020

Choose a reason for hiding this comment

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

The docs does not have any mention for running like this:

 pipenv run python serialize_data.py *.md

You've this format mentioned in the docstring though 🤔

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated in the latest commit.


- 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