From fe7c940ef14ad5d51fe7ae7e017fc448e03071f5 Mon Sep 17 00:00:00 2001 From: Andrea Franchini <hello@andreafranchini.com> Date: Fri, 3 Mar 2023 16:25:06 +0100 Subject: [PATCH] Add ?version query param to /modelcheck endpoint --- mc_openapi/doml_mc/xmi_parser/doml_model.py | 6 +++++- mc_openapi/handlers.py | 11 +++++++---- mc_openapi/openapi/model_checker.yaml | 15 +++++++++++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/mc_openapi/doml_mc/xmi_parser/doml_model.py b/mc_openapi/doml_mc/xmi_parser/doml_model.py index 9841a6e..775eb72 100644 --- a/mc_openapi/doml_mc/xmi_parser/doml_model.py +++ b/mc_openapi/doml_mc/xmi_parser/doml_model.py @@ -1,5 +1,6 @@ import copy import importlib.resources as ilres +import sys from typing import Optional, Tuple from lxml import etree @@ -90,7 +91,10 @@ def parse_doml_model(raw_model: bytes, doml_version: Optional[DOMLVersion]) -> T model, doml_version = get_model(raw_model, doml_version) else: # if user specifies DOML version, respect that choice! - model = parse_xmi_model(raw_model, doml_version) + try: + model = parse_xmi_model(raw_model, doml_version) + except: + raise Exception("Parsing of DOML failed. Perhaps you are using the wrong DOML version or IDE?") print(f"Using DOML {doml_version.value}") diff --git a/mc_openapi/handlers.py b/mc_openapi/handlers.py index e4e82a2..7a8ad6a 100644 --- a/mc_openapi/handlers.py +++ b/mc_openapi/handlers.py @@ -15,17 +15,20 @@ def make_error(user_msg, debug_msg=None): print(f"ERROR [{datetime.datetime.now()}]: {debug_msg}") return result - -def post(body): +def post(body, version=None): doml_xmi = body try: doml_version = None try: doml_version: str = os.environ["DOML_VERSION"] - doml_version = DOMLVersion.get(doml_version) - print("Setting DOML version from DOML_VERSION") except: pass + if version: + doml_version: str = version + if doml_version: + doml_version = DOMLVersion.get(doml_version) + print(f"Forcing DOML {doml_version.value}") + dmc = ModelChecker(doml_xmi, doml_version) user_req_store = None diff --git a/mc_openapi/openapi/model_checker.yaml b/mc_openapi/openapi/model_checker.yaml index 66638bb..57d3261 100644 --- a/mc_openapi/openapi/model_checker.yaml +++ b/mc_openapi/openapi/model_checker.yaml @@ -3,12 +3,13 @@ info: license: name: Apache-2.0 title: PIACERE Model Checker - version: "1.0" + version: "2.2.0" paths: /modelcheck: post: + summary: Verify a DOML model description: Send a DOML model in XMI format and a requirement to check. - The response says whether the requirement is satisfied by the model, + The response says whether the requirements are satisfied by the model, with a description of the issue if it is not. operationId: mc_openapi.handlers.post requestBody: @@ -17,6 +18,16 @@ paths: schema: type: string required: true + parameters: + - in: query + name: version + schema: + type: string + description: > + The DOML version you're currently using, written as e.g. `2.0` or `V2_0`. + If not specified, it will try to infer it by trying to parse it for each supported + DOML version, starting with the most recent. + required: false responses: "200": content: -- GitLab