From 686fc8447a668e7884df0a0cdaa5cbbbfa838976 Mon Sep 17 00:00:00 2001 From: Cornelia Michlits <cornelia.michlits@tuwien.ac.at> Date: Thu, 24 Nov 2022 20:05:21 +0100 Subject: [PATCH] add descriptions, update flasgger endpoints --- fda-units-service/app.py | 24 ++++++++++----------- fda-units-service/onto_feat.py | 1 + fda-units-service/us-yml/getconcept.yml | 2 +- fda-units-service/us-yml/ontologie.yml | 18 ---------------- fda-units-service/us-yml/ontologies.yml | 17 ++++++++++++--- fda-units-service/us-yml/ontology.yml | 11 ++++++++++ fda-units-service/us-yml/ontologybyname.yml | 19 ++++++++++++++++ fda-units-service/us-yml/suggest.yml | 2 +- fda-units-service/us-yml/validate.yml | 2 +- 9 files changed, 60 insertions(+), 36 deletions(-) delete mode 100644 fda-units-service/us-yml/ontologie.yml create mode 100644 fda-units-service/us-yml/ontology.yml create mode 100644 fda-units-service/us-yml/ontologybyname.yml diff --git a/fda-units-service/app.py b/fda-units-service/app.py index 58cd365190..06460a4ff2 100644 --- a/fda-units-service/app.py +++ b/fda-units-service/app.py @@ -87,7 +87,7 @@ def validate(unit): except Exception as e: logging.error(e) res = {"success": False, "message": str(e)} - return jsonify(res) + return jsonify(res), 500 @app.route('/api/units/uri/<uname>', methods=["GET"], endpoint='uri') @@ -141,7 +141,7 @@ def save_column_concept(): res = {"success": False, "message": str(e)} return jsonify(res), 500 -@app.route('/api/units/getconcept/<cname>', methods=["GET"], endpoint='get_concept') +@app.route('/api/ontologies/getconcept/<cname>', methods=["GET"], endpoint='get_concept') @swag_from('getconcept.yml') def get_concept(cname): logging.debug('endpoint get concept, cname=%s, body=%s', cname, request) @@ -156,33 +156,33 @@ def get_concept(cname): ONTOLOGIES_DIRECTORY = 'ontologies' -@app.route('/api/ontologies', methods=["POST"], endpoint='upload_onto') -@swag_from('ontologie.yml') +@app.route('/api/ontology', methods=["POST"], endpoint='upload_onto') +@swag_from('ontologies.yml') def post_ontologies(): if 'file' not in request.files: return "no file", 500 file = request.files['file'] if file.filename == '': - return "no file selected", 500 + return "no file selected", 400 if file and allowed_file(file.filename): filename = secure_filename(file.filename) if ontology_exists(Path(filename).stem): - return "ontology name already exists", 500 + return "ontology name already exists", 409 setup_ontology_dir() file.save(os.path.join(ONTOLOGIES_DIRECTORY, filename)) logging.debug('created ontology: %s', filename) - return "created", 200 + return "created", 201 @app.route('/api/ontologies', methods=["GET"], endpoint='get_ontos') -@swag_from('ontologies.yml') +@swag_from('ontology.yml') def get_ontologies(): print(list_ontologies()) return jsonify(list_ontologies()) -@app.route('/api/ontologies/<name>', methods=["GET"], endpoint='get_onto') -@swag_from('ontologie.yml') -def get_ontologies(name): - ontology = get_ontology(name) +@app.route('/api/ontologies/<o_name>', methods=["GET"], endpoint='get_onto') +@swag_from('ontologybyname.yml') +def get_ontologies(o_name): + ontology = get_ontology(o_name) if ontology is None: return "ontology does not exist", 404 return ontology diff --git a/fda-units-service/onto_feat.py b/fda-units-service/onto_feat.py index 8b13d7cd5e..5fb56a70d7 100644 --- a/fda-units-service/onto_feat.py +++ b/fda-units-service/onto_feat.py @@ -3,6 +3,7 @@ import glob import sys import os from pathlib import Path +import rdflib ALLOWED_EXTENSIONS = {'ttl', 'nt'} diff --git a/fda-units-service/us-yml/getconcept.yml b/fda-units-service/us-yml/getconcept.yml index 6def46d690..1a2e13c264 100644 --- a/fda-units-service/us-yml/getconcept.yml +++ b/fda-units-service/us-yml/getconcept.yml @@ -8,7 +8,7 @@ parameters: - in: "path" type: "string" name: "cname" - description: "Enter a table name or attribute name.ยด" + description: "Enter a concept name." required: true responses: 200: diff --git a/fda-units-service/us-yml/ontologie.yml b/fda-units-service/us-yml/ontologie.yml deleted file mode 100644 index 3e5edc5601..0000000000 --- a/fda-units-service/us-yml/ontologie.yml +++ /dev/null @@ -1,18 +0,0 @@ -summary: "Get ontology" -description: "This is a simple API for getting ontologies (.nt, .ttl files) used in DB-Repo." -consumes: -- "application/json" -produces: -- "application/json" -parameters: -- name: file - required: false - in: formData - type: file -responses: - 200: - description: "OK" - 201: - description: "Created" - 405: - description: "Invalid input" \ No newline at end of file diff --git a/fda-units-service/us-yml/ontologies.yml b/fda-units-service/us-yml/ontologies.yml index 348024df3b..2934080935 100644 --- a/fda-units-service/us-yml/ontologies.yml +++ b/fda-units-service/us-yml/ontologies.yml @@ -1,11 +1,22 @@ -summary: "Get list of ontologies" -description: "This is a simple API for getting the list of all ontologies contained in DB-Repo." +summary: "Post / Upload ontology" +description: "This is a simple API for posting ontologies (.nt, .ttl files) to DB-Repo." consumes: - "application/json" produces: - "application/json" +parameters: +- name: file + required: false + in: formData + type: file responses: 200: description: "OK" + 201: + description: "Created" + 400: + description: "Bad request" 405: - description: "Invalid input" \ No newline at end of file + description: "Invalid input" + 409: + description: "Conflict" \ No newline at end of file diff --git a/fda-units-service/us-yml/ontology.yml b/fda-units-service/us-yml/ontology.yml new file mode 100644 index 0000000000..2ea5c02e4c --- /dev/null +++ b/fda-units-service/us-yml/ontology.yml @@ -0,0 +1,11 @@ +summary: "Get ontology" +description: "This is a simple API for listing all ontologies (.nt, .ttl files) used in DB-Repo." +consumes: +- "application/json" +produces: +- "application/json" +responses: + 200: + description: "OK" + 405: + description: "Invalid input" \ No newline at end of file diff --git a/fda-units-service/us-yml/ontologybyname.yml b/fda-units-service/us-yml/ontologybyname.yml new file mode 100644 index 0000000000..ccccc3fee9 --- /dev/null +++ b/fda-units-service/us-yml/ontologybyname.yml @@ -0,0 +1,19 @@ +summary: "Get ontology" +description: "This is a simple API for getting a certain ontologies (.nt, .ttl files) stored in DB-Repo." +consumes: +- "application/json" +produces: +- "application/json" +parameters: + - name: o_name + in: path + required: true + type: string + default: "VOCAB_QUDT-UNITS-ALL-v2.1" +responses: + 200: + description: "OK" + 404: + description: "Not found" + 405: + description: "Invalid input" diff --git a/fda-units-service/us-yml/suggest.yml b/fda-units-service/us-yml/suggest.yml index b47a657ae9..62696fe99c 100644 --- a/fda-units-service/us-yml/suggest.yml +++ b/fda-units-service/us-yml/suggest.yml @@ -7,7 +7,7 @@ produces: parameters: - in: "body" name: "body" - description: "to-do description" + description: "Json containing ustring, i.e., string of a unit, and an offset." required: true schema: type: "object" diff --git a/fda-units-service/us-yml/validate.yml b/fda-units-service/us-yml/validate.yml index 01cbb337c1..81ac877ead 100644 --- a/fda-units-service/us-yml/validate.yml +++ b/fda-units-service/us-yml/validate.yml @@ -8,7 +8,7 @@ parameters: - in: "path" type: "string" name: "unit" - description: "to-do description" + description: "Validates unit against om-2." required: true responses: 200: -- GitLab