Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import codecs
import io
import json
import zipfile
Expand Down Expand Up @@ -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(
'/',
Expand All @@ -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(
Expand All @@ -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': '*'})


Expand Down
3 changes: 1 addition & 2 deletions validate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import codecs
import json

import jsonschema
Expand All @@ -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)
Expand Down
Loading