diff --git a/main.py b/main.py index 3a637ff..1179a96 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ -import codecs import io import json import zipfile @@ -27,6 +26,12 @@ del i['source'] ndc9_items[key] = i +with open('./templates/index.html', encoding='utf-8') as file: + index_html = file.read() + +with open('jsonschema.json', encoding='utf-8') as file: + json_schema = json.load(file) + @app.get( '/', @@ -37,8 +42,7 @@ response_class=HTMLResponse, ) async def index(): - with codecs.open('./templates/index.html', 'r', 'utf-8') as file: - return file.read() + return index_html @app.get( @@ -49,8 +53,6 @@ async def index(): response_description='JSONスキーマを返す', ) async def schema(): - with codecs.open('jsonschema.json', 'r', 'utf-8') as file: - json_schema = json.load(file) return ORJSONResponse(json_schema, headers={'Access-Control-Allow-Origin': '*'}) diff --git a/validate.py b/validate.py index fb1ae24..213bf0f 100644 --- a/validate.py +++ b/validate.py @@ -1,4 +1,3 @@ -import codecs import json import jsonschema @@ -8,7 +7,7 @@ url = 'http://127.0.0.1:8000/ndc9.json' r = requests.get(url, headers={'content-type': 'application/json'}) data = r.json() - with codecs.open('jsonschema.json', 'r', 'utf-8') as file: + with open('jsonschema.json', encoding='utf-8') as file: json_schema = json.load(file) for item in data.values(): jsonschema.validate(item, json_schema)