Skip to content

Commit

Permalink
Merge pull request #18 from OWASP/load-file-from-url
Browse files Browse the repository at this point in the history
FEATURE: allow users to load file using URL
  • Loading branch information
dmdhrumilmistry authored Nov 13, 2023
2 parents 49b04c5 + a67c870 commit 7a3d253
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
11 changes: 9 additions & 2 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ The disclaimer advises users to use the open-source project for ethical and legi

```bash
python -m offat.api
# OR
offat-api
```

- API Documentation can be found at <http://localhost:8000/docs>
Expand All @@ -136,7 +140,8 @@ The disclaimer advises users to use the open-source project for ethical and legi
- Run offat

```bash
offat -f swagger_file.json
offat -f swagger_file.json # using file
offat -f https://example.com/docs.json # using url
```

- To get all the commands use `help`
Expand All @@ -148,7 +153,9 @@ The disclaimer advises users to use the open-source project for ethical and legi
- Save result in `json`, `yaml` or `html` formats.

```bash
offat -f swagger_file.json -o output.html -of html
offat -f swagger_file.json -o output.json # json
offat -f swagger_file.json -o output.html -of html # html
offat -f swagger_file.json -o output.yaml -of yaml # yaml
```

> `json` format is default output format.
Expand Down
2 changes: 1 addition & 1 deletion src/offat/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def start():
banner()

parser = ArgumentParser(prog='offat')
parser.add_argument('-f','--file', dest='fpath', type=str, help='path of openapi/swagger specification file', required=True)
parser.add_argument('-f','--file', dest='fpath', type=str, help='path or url of openapi/swagger specification file', required=True)
parser.add_argument('-v','--version', action='version', version=f'%(prog)s {get_package_version()}')
parser.add_argument('-rl', '--rate-limit', dest='rate_limit', help='API requests rate limit. -dr should be passed in order to use this option', type=int, default=None, required=False)
parser.add_argument('-dr', '--delay-rate', dest='delay_rate', help='API requests delay rate in seconds. -rl should be passed in order to use this option', type=float, default=None, required=False)
Expand Down
19 changes: 9 additions & 10 deletions src/offat/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@

class OpenAPIParser:
''''''
def __init__(self, fpath:str, spec:dict=None) -> None:
if fpath:
self._parser = ResolvingParser(fpath, backend = 'openapi-spec-validator')
if self._parser.valid:
logger.info('Specification file is valid')
else:
logger.error('Specification file is invalid!')
self._spec = self._parser.specification
def __init__(self, fpath_or_url:str, spec:dict=None) -> None:
self._parser = ResolvingParser(fpath_or_url, backend = 'openapi-spec-validator', spec_string=spec)

if self._parser.valid:
logger.info('Specification file is valid')
else:
self._spec = spec
logger.error('Specification file is invalid!')

self._spec = self._parser.specification

self.hosts = []
self._populate_hosts()
Expand All @@ -38,7 +37,7 @@ def _populate_hosts(self):
host = self._spec.get('host') # for swagger files
if not host:
logger.error('Invalid Host: Host is missing')
raise ValueError(f'Host Not Found in spec file')
raise ValueError('Host Not Found in spec file')
hosts = [host]

self.hosts = hosts
Expand Down

0 comments on commit 7a3d253

Please sign in to comment.