Formatted all the changed files

This commit is contained in:
Exterminator11 committed 2023-10-15 17:16:12 +05:30
1 parent bd70e00f08
commit 36b243e9d2
4 files changed
+47 -13

No files matched your search

+1
View File
@@ -0,0 +1 @@
Path(url='/pets', summary=None, description=None, operations=[Operation(method=<OperationMethod.GET: 'get'>, responses=[Response(is_default=False, description='A paged array of pets', code=200, content=[Content(type=<ContentType.JSON: 'application/json'>, schema=Array(type=<DataType.ARRAY: 'array'>, title=None, enum=[], example=None, description=None, default=None, nullable=False, read_only=False, write_only=False, deprecated=False, extensions={}, max_items=100, min_items=None, unique_items=None, items=Object(type=<DataType.OBJECT: 'object'>, title=None, enum=[], example=None, description=None, default=None, nullable=False, read_only=False, write_only=False, deprecated=False, extensions={}, max_properties=None, min_properties=None, required=['id', 'name'], properties=[Property(name='id', schema=Integer(type=<DataType.INTEGER: 'integer'>, title=None, enum=[], example=None, description=None, default=None, nullable=False, read_only=False, write_only=False, deprecated=False, extensions={}, multiple_of=None, maximum=None, exclusive_maximum=None, minimum=None, exclusive_minimum=None, format=<IntegerFormat.INT64: 'int64'>)), Property(name='name', schema=String(type=<DataType.STRING: 'string'>, title=None, enum=[], example=None, description=None, default=None, nullable=False, read_only=False, write_only=False, deprecated=False, extensions={}, max_length=None, min_length=None, pattern=None, format=None)), Property(name='tag', schema=String(type=<DataType.STRING: 'string'>, title=None, enum=[], example=None, description=None, default=None, nullable=False, read_only=False, write_only=False, deprecated=False, extensions={}, max_length=None, min_length=None, pattern=None, format=None))])))], headers=[Header(name='x-next', schema=String(type=<DataType.STRING: 'string'>, title=None, enum=[], example=None, description=None, default=None, nullable=False, read_only=False, write_only=False, deprecated=False, extensions={}, max_length=None, min_length=None, pattern=None, format=None), description='A link to the next page of responses', required=False, deprecated=False)]), Response(is_default=True, description='unexpected error', code=None, content=[Content(type=<ContentType.JSON: 'application/json'>, schema=Object(type=<DataType.OBJECT: 'object'>, title=None, enum=[], example=None, description=None, default=None, nullable=False, read_only=False, write_only=False, deprecated=False, extensions={}, max_properties=None, min_properties=None, required=['code', 'message'], properties=[Property(name='code', schema=Integer(type=<DataType.INTEGER: 'integer'>, title=None, enum=[], example=None, description=None, default=None, nullable=False, read_only=False, write_only=False, deprecated=False, extensions={}, multiple_of=None, maximum=None, exclusive_maximum=None, minimum=None, exclusive_minimum=None, format=<IntegerFormat.INT32: 'int32'>)), Property(name='message', schema=String(type=<DataType.STRING: 'string'>, title=None, enum=[], example=None, description=None, default=None, nullable=False, read_only=False, write_only=False, deprecated=False, extensions={}, max_length=None, min_length=None, pattern=None, format=None))]))], headers=[])], summary='List all pets', description=None, operation_id='listPets', external_docs=None, request_body=None, deprecated=False, parameters=[Parameter(name='limit', location=<ParameterLocation.QUERY: 'query'>, schema=Integer(type=<DataType.INTEGER: 'integer'>, title=None, enum=[], example=None, description=None, default=None, nullable=False, read_only=False, write_only=False, deprecated=False, extensions={}, multiple_of=None, maximum=100, exclusive_maximum=None, minimum=None, exclusive_minimum=None, format=<IntegerFormat.INT32: 'int32'>), required=False, description='How many items to return at one time (max 100)', deprecated=False, style=<QueryParameterStyle.FORM: 'form'>, explode=True)], tags=['pets'], security=[]), Operation(method=<OperationMethod.POST: 'post'>, responses=[Response(is_default=False, description='Null response', code=201, content=None, headers=[]), Response(is_default=True, description='unexpected error', code=None, content=[Content(type=<ContentType.JSON: 'application/json'>, schema=Object(type=<DataType.OBJECT: 'object'>, title=None, enum=[], example=None, description=None, default=None, nullable=False, read_only=False, write_only=False, deprecated=False, extensions={}, max_properties=None, min_properties=None, required=['code', 'message'], properties=[Property(name='code', schema=Integer(type=<DataType.INTEGER: 'integer'>, title=None, enum=[], example=None, description=None, default=None, nullable=False, read_only=False, write_only=False, deprecated=False, extensions={}, multiple_of=None, maximum=None, exclusive_maximum=None, minimum=None, exclusive_minimum=None, format=<IntegerFormat.INT32: 'int32'>)), Property(name='message', schema=String(type=<DataType.STRING: 'string'>, title=None, enum=[], example=None, description=None, default=None, nullable=False, read_only=False, write_onlLine truncated
+12
View File
@@ -0,0 +1,12 @@
Base URL:http://petstore.swagger.io,https://api.example.com
Path1: /pets
description: None
parameters: []
methods:
get=A paged array of pets
post=Null response
Path2: /pets/{petId}
description: None
parameters: []
methods:
get=Expected response to a valid request
+4 -4
View File
@@ -4,7 +4,7 @@ from openapi_parser import parse
try:
from scripts.parser.file.base_parser import BaseParser
except:
except ModuleNotFoundError:
from base_parser import BaseParser
@@ -23,7 +23,7 @@ class OpenAPI3Parser(BaseParser):
def get_info_from_paths(self, path):
info = ""
if(path.operations):
if path.operations:
for operation in path.operations:
info += (
f"\n{operation.method.value}="
@@ -46,9 +46,9 @@ class OpenAPI3Parser(BaseParser):
f"parameters: {path.parameters}\nmethods: {info}\n"
)
i += 1
if(i==2):
if i == 2:
with open("reff.txt", "w") as f:
f.write(str(path))
with open("results.txt", "w") as f:
f.write(results)
return results
return results
+30 -9
View File
@@ -1,27 +1,48 @@
import pytest
from scripts.parser.file.openapi3_parser import OpenAPI3Parser
from openapi_parser import parse
from scripts.parser.file.openapi3_parser import OpenAPI3Parser
@pytest.mark.parametrize("urls, expected_base_urls", [
(["http://petstore.swagger.io/v1", "https://api.example.com/v1/resource",'https://api.example.com/v1/another/resource','https://api.example.com/v1/some/endpoint'], ["http://petstore.swagger.io",'https://api.example.com']),
])
@pytest.mark.parametrize(
"urls, expected_base_urls",
[
(
[
"http://petstore.swagger.io/v1",
"https://api.example.com/v1/resource",
"https://api.example.com/v1/another/resource",
"https://api.example.com/v1/some/endpoint",
],
["http://petstore.swagger.io", "https://api.example.com"],
),
],
)
def test_get_base_urls(urls, expected_base_urls):
assert OpenAPI3Parser().get_base_urls(urls) == expected_base_urls
def test_get_info_from_paths():
file_path = "tests/test_openapi3.yaml"
data = parse(file_path)
path=data.paths[1]
assert OpenAPI3Parser().get_info_from_paths(path)=="\nget=Expected response to a valid request"
path = data.paths[1]
assert (
OpenAPI3Parser().get_info_from_paths(path)
== "\nget=Expected response to a valid request"
)
def test_parse_file():
file_path = "tests/test_openapi3.yaml"
results_real = "Base URL:http://petstore.swagger.io,https://api.example.com\nPath1: /pets\ndescription: None\nparameters: []\nmethods: \nget=A paged array of pets\npost=Null response\nPath2: /pets/{petId}\ndescription: None\nparameters: []\nmethods: \nget=Expected response to a valid request\n"
results_real = (
"Base URL:http://petstore.swagger.io,https://api.example.com\nPath1: "
+ "/pets\ndescription: None\nparameters: []\nmethods: \n"
+ "get=A paged array of pets\npost=Null "
+ "response\nPath2: /pets/{petId}\ndescription: None\n"
+ "parameters: []\nmethods: "
+ "\nget=Expected response to a valid request\n"
)
openapi_parser_test = OpenAPI3Parser()
results=openapi_parser_test.parse_file(file_path)
results = openapi_parser_test.parse_file(file_path)
assert results == results_real