Skip to content

Commit 5538eeb

Browse files
NPA-3895: Poetry install
1 parent 755fa34 commit 5538eeb

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

.github/workflows/openapi-validate.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ jobs:
1717
with:
1818
python-version: 3.9
1919

20-
# - name: Install dependencies
21-
# run: |
22-
# pip install -r requirements.txt # If you have dependencies
20+
- name: Install Script Packages with Poetry
21+
shell: bash
22+
run: |
23+
poetry install
2324
2425
- name: Run Python script for all files
2526
run: |

scripts/validate_schema.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,33 @@
44
55
Validates a given example file against the schema specification
66
"""
7-
from json import loads
87
from yaml import safe_load
9-
from typing import Union
108
from os import path
119
from openapi_schema_validator import OAS30Validator
1210
import json
1311
import datetime
14-
from requests import get
1512
import sys
1613

1714
SCHEMA_FILE_PATH = "../specification/validated-relationships-service-api.yaml"
18-
SCHEMA_FILE = path.join(
19-
path.dirname(path.realpath(__file__)), SCHEMA_FILE_PATH
20-
)
15+
SCHEMA_FILE = path.join(path.dirname(path.realpath(__file__)), SCHEMA_FILE_PATH)
2116
openapi_schema = {}
22-
import pdb
2317

24-
def main(openapi_schema:dict):
18+
19+
def main(openapi_schema: dict):
2520
"""Main entrypoint"""
2621
args = sys.argv
27-
if (len(args) != 3):
22+
if len(args) != 3:
2823
print("Require schema reference and file to validate")
2924
exit()
3025

3126
schema = schema_lookup(args[1])
3227
file = args[2]
33-
if (len(openapi_schema) == 0):
28+
if len(openapi_schema) == 0:
3429
openapi_schema = safe_load(load_file(SCHEMA_FILE))
3530
validate_consent(openapi_schema, schema, file)
3631

37-
def schema_lookup(schema:str) -> str:
32+
33+
def schema_lookup(schema: str) -> str:
3834
schema = schema.lower()
3935
if schema == "consent":
4036
return "#/components/schemas/ConsentBundle"
@@ -43,7 +39,8 @@ def schema_lookup(schema:str) -> str:
4339

4440
print("")
4541

46-
def validate_consent(schema:dict, schema_ref:str, file:str) -> None:
42+
43+
def validate_consent(schema: dict, schema_ref: str, file: str) -> None:
4744
schema["$ref"] = schema_ref
4845
# openapi_schema["$ref"] = [
4946
# "#/components/schemas/ConsentBundle",
@@ -53,15 +50,17 @@ def validate_consent(schema:dict, schema_ref:str, file:str) -> None:
5350
json_contents = load_example_file(file)
5451
OAS30Validator(schema).validate(json_contents)
5552

56-
def load_example_file(file:str) -> dict:
5753

58-
patch = path.join(
59-
path.dirname(path.realpath(__file__)), file
60-
)
54+
def load_example_file(file: str) -> dict:
55+
56+
patch = path.join(path.dirname(path.realpath(__file__)), file)
6157
yamlfile = safe_load(load_file(patch))
62-
jsonstr = json.dumps(yamlfile[next(iter(yamlfile))]["value"], default=date_converter)
58+
jsonstr = json.dumps(
59+
yamlfile[next(iter(yamlfile))]["value"], default=date_converter
60+
)
6361
return json.loads(jsonstr)
6462

63+
6564
def date_converter(obj):
6665
"""Date and datetime converter to correctly render dates in json"""
6766
if isinstance(obj, datetime.datetime):
@@ -70,9 +69,11 @@ def date_converter(obj):
7069
return obj.isoformat()
7170
return obj
7271

72+
7373
def load_file(file_path) -> None:
7474
with open(file_path) as file:
7575
return file.read()
7676

77+
7778
if __name__ == "__main__":
7879
main(openapi_schema)

0 commit comments

Comments
 (0)