New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

openapi-cli-tool

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-cli-tool - pypi Package Compare versions

Comparing version
0.2.1
to
0.3.0
+38
src/utils/repository.py
import os
from src.utils.file_control import FileControl
from src.utils.resolver import resolve_once
from src.models.route import Route
from src.models.route_collection import RouteCollection
class Repository:
def __init__(self, file_path, file_control = FileControl()):
self.file_control = file_control
self.routes = self.generate(file_path)
def _set_from_file(self, collection, file):
content = self.file_control.load_dict_from_file(file)
if 'paths' not in content or len(content['paths']) == 0:
return
for path, spec in content['paths'].items():
spec = resolve_once(file, spec, self.file_control)
for method in spec:
collection.add(
Route(
method.upper(),
path,
file,
spec[method]
))
def generate(self, file_path):
collection = RouteCollection()
files = [p for p in file_path if os.path.isfile(p)]
for file in files:
try:
self._set_from_file(collection, file)
except Exception as e:
raise Exception(e)
collection.sort()
return collection
+2
-2
Metadata-Version: 2.1
Name: openapi-cli-tool
Version: 0.2.1
Version: 0.3.0
Summary: openapi cli tool

@@ -13,3 +13,3 @@ Home-page: https://github.com/hakopako/openapi-cli-tool

[![Build Status](https://travis-ci.com/hakopako/openapi-cli-tool.svg?branch=master)](https://travis-ci.com/hakopako/openapi-cli-tool)
<img src="https://img.shields.io/badge/version-v0.2.1-green.svg">
<img src="https://img.shields.io/badge/version-v0.3.0-green.svg">
<img src="https://img.shields.io/badge/license-MIT-lightgray.svg">

@@ -16,0 +16,0 @@ <img src="https://img.shields.io/badge/python-2.7,3.4<=-blue.svg"> <img src="https://img.shields.io/badge/swagger-3.x-yellow.svg">

@@ -24,2 +24,3 @@ README.md

src/utils/file_control.py
src/utils/repository.py
src/utils/resolver.py
Metadata-Version: 2.1
Name: openapi-cli-tool
Version: 0.2.1
Version: 0.3.0
Summary: openapi cli tool

@@ -13,3 +13,3 @@ Home-page: https://github.com/hakopako/openapi-cli-tool

[![Build Status](https://travis-ci.com/hakopako/openapi-cli-tool.svg?branch=master)](https://travis-ci.com/hakopako/openapi-cli-tool)
<img src="https://img.shields.io/badge/version-v0.2.1-green.svg">
<img src="https://img.shields.io/badge/version-v0.3.0-green.svg">
<img src="https://img.shields.io/badge/license-MIT-lightgray.svg">

@@ -16,0 +16,0 @@ <img src="https://img.shields.io/badge/python-2.7,3.4<=-blue.svg"> <img src="https://img.shields.io/badge/swagger-3.x-yellow.svg">

@@ -5,3 +5,3 @@ ![openapi-cli-tool](https://raw.githubusercontent.com/hakopako/openapi-cli-tool/master/doc/logo.png)

[![Build Status](https://travis-ci.com/hakopako/openapi-cli-tool.svg?branch=master)](https://travis-ci.com/hakopako/openapi-cli-tool)
<img src="https://img.shields.io/badge/version-v0.2.1-green.svg">
<img src="https://img.shields.io/badge/version-v0.3.0-green.svg">
<img src="https://img.shields.io/badge/license-MIT-lightgray.svg">

@@ -8,0 +8,0 @@ <img src="https://img.shields.io/badge/python-2.7,3.4<=-blue.svg"> <img src="https://img.shields.io/badge/swagger-3.x-yellow.svg">

@@ -8,3 +8,3 @@ from setuptools import setup, find_packages

long_description_content_type='text/markdown',
version='0.2.1',
version='0.3.0',
author="Ayaka Shimada",

@@ -11,0 +11,0 @@ author_email='aya.a.shimada@gmail.com',

@@ -1,10 +0,9 @@

from src.commands.list import get_list
from src.utils.resolver import resolver
from src.utils.export import export_json, export_yaml, export_html
from src.utils.file_control import FileControl
from src.utils.repository import Repository
def run_bundle(spec_paths, filename=None):
file_control = FileControl()
collection = get_list(spec_paths)
repository = Repository(spec_paths)
collection = repository.routes
if collection.len() == 0 and filename is None:

@@ -17,3 +16,3 @@ return {}

try:
data = file_control.load_dict_from_file(header_file)
data = repository.file_control.load_dict_from_file(header_file)
if isinstance(data, dict):

@@ -31,3 +30,3 @@ data['paths'] = {}

data['paths'][route.url] = {}
resolved_spec = resolver(route.file, route.spec, file_control)
resolved_spec = resolver(route.file, route.spec, repository.file_control)
data['paths'][route.url].update({route.method.lower(): resolved_spec})

@@ -34,0 +33,0 @@

@@ -1,30 +0,7 @@

import os
from glob import glob
from src.utils.file_control import FileControl
from src.utils.repository import Repository
from src.utils.export import export_table
from src.models.route import Route
from src.models.route_collection import RouteCollection
def get_list(paths):
file_control = FileControl()
collection = RouteCollection()
files = [p for p in paths if os.path.isfile(p)]
for file in files:
try:
spec = file_control.load_dict_from_file(file)
if 'paths' not in spec or len(spec['paths']) == 0:
continue
routes = [Route(m.upper(), p, file, spec['paths'][p][m]) for p in spec['paths'] for m in spec['paths'][p]]
collection.extend(routes)
except Exception as e:
print(e)
return RouteCollection()
collection.sort()
return collection
def list(paths):
routes = get_list(paths)
export_table(routes.to_list(), ['Method', 'Path', 'File'])
repository = Repository(paths)
export_table(repository.routes.to_list(), ['Method', 'Path', 'File'])

@@ -1,11 +0,10 @@

from src.commands.list import get_list
from src.utils.resolver import resolver
from src.utils.export import export_json, export_yaml
from src.utils.file_control import FileControl
from src.utils.repository import Repository
def run_resolve(method, path, spec_paths):
file_control = FileControl()
collection = get_list(spec_paths)
specs = [resolver(route.file, route.spec, file_control) for route in collection.get() if route.method == method.upper() and route.url == path]
repository = Repository(spec_paths)
collection = repository.routes
specs = [resolver(route.file, route.spec, repository.file_control) for route in collection.get() if route.method == method.upper() and route.url == path]
return specs

@@ -16,2 +15,4 @@

specs = run_resolve(method, path, spec_paths)
if len(specs) == 0:
print("Not found")
if type == 'json':

@@ -18,0 +19,0 @@ export_json(specs)

@@ -1,3 +0,1 @@

class RouteCollection:

@@ -16,4 +14,4 @@

def extend(self, routes):
self.collection.extend(routes)
def add(self, route):
self.collection.append(route)

@@ -20,0 +18,0 @@

@@ -10,1 +10,4 @@

self.spec = spec
def __repr__(self):
return 'method='+self.method+' url='+self.url+' file='+self.file+' spec='+str(self.spec)
import os
import json
import yaml
from copy import deepcopy

@@ -23,3 +24,3 @@

if file_path in self.spec_dict:
return self.spec_dict[file_path]
return deepcopy(self.spec_dict[file_path])
try:

@@ -32,3 +33,3 @@ r = open(file_path, 'r')

if not os.path.exists(file_path):
raise Exception('Faild not found.')
raise Exception('File not found.')
if file_extension == '.json':

@@ -35,0 +36,0 @@ spec = json.loads(content)

import os
from src.utils.file_control import FileControl
def _resolve_escape_character(value):
return value.replace("~0", "~").replace("~1", "/")
def _find_reference(link, base_file_path, file_control):

@@ -14,10 +19,10 @@ if '#/' in link:

for key in items:
spec = spec[key]
spec = spec[_resolve_escape_character(key)]
return spec, spec_file
except Exception as e:
print('Failed to load referance. file=' + base_file_path + ' $ref=' + link)
print('Failed to load reference. file=' + base_file_path + ' $ref=' + link + ' (' + str(e) + ')')
return '', spec_file
def resolver(file_path, data, file_control):
def resolver(file_path, data, file_control = FileControl()):
if not isinstance(data, dict):

@@ -34,1 +39,12 @@ return data

return data
def resolve_once(file_path, data, file_control = FileControl()):
if not isinstance(data, dict):
return data
if '$ref' in data:
new_value, _ = _find_reference(data['$ref'], file_path, file_control)
return new_value
return data