Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If OBA does not find a base ontology, it will load no paths #132

Closed
DougalW opened this issue Oct 8, 2020 · 13 comments
Closed

If OBA does not find a base ontology, it will load no paths #132

DougalW opened this issue Oct 8, 2020 · 13 comments

Comments

@DougalW
Copy link

DougalW commented Oct 8, 2020

Hi, I created a simple ontology and ran OBA to create a server. It completes successfully but then returns "No operations defined in spec!" when I access the swagger spec through the UI as shown here:

image

I have attached my config.yaml and ontology.xml files. The ontology is very simple, and was created using Protege v5.5.

Archive.zip

When I run these through OBA as per the instructions, each step completes successfully, but when I checked through the config files in the servers directory I noticed a few odd things:

  • the openapi.yaml file does not contain the expected paths entries for this ontology
  • the context.json file seems mangled

servers_files.zip

I am also running a local copy of GraphDB as a sparql endpoint.

Please let me know what's missing or incorrect here.

Regards

Dougal

@dgarijo
Copy link
Contributor

dgarijo commented Oct 8, 2020

Thanks @DougalW,
if there is no operations in the yaml, then it means that the first part of OBA is not working with your ontology. We will have to check that up with the ontology you shared, I personally tried this with many ontologies successfully (all the ones in examples). Maybe some missing annotations (e.g., labels and comments) make the system perform in a weird manner.

@DougalW
Copy link
Author

DougalW commented Oct 8, 2020

Thanks @dgarijo - it's a very minimal ontology just for testing purposes so it may well be missing sufficient metadata.

@dgarijo
Copy link
Contributor

dgarijo commented Oct 9, 2020

@DougalW I dug into it, and I think there is something weird with the way you declared the namespace prefixes.

I changed the first two lines of your ontology file to:

xmlns="https://businessontology.com/ontology/"
xml:base="https://businessontology.com/ontology/"

And obtained the yaml I attach below. Before, these two lines did not have the /ontology/ part in the URI, and I think it's confusing our program because it assumes that the ontology to load is the base one (you could have several ontologies loaded in your file)

I add the YAML and the changes in the ontology.
business.zip

In this case, I think OBA should tell you that it wasn't able to load a base ontology. I will rephrase the issue, and I will leave it open.

image

@dgarijo dgarijo changed the title 'No operations defined in spec!' returned from a simple ontology If OBA does not find a base ontology, it will load no paths Oct 9, 2020
@DougalW
Copy link
Author

DougalW commented Oct 9, 2020

Thanks for looking at this. I used your new version of the ontology but it won't generate a server.

I ran OBA using the same config file as before, and the new version of the ontology you sent. It completes successfully:

OBA dwatt$ java -jar oba-3.5.0-jar-with-dependencies.jar -c config.yaml 
outputs/BusinessOntology/ontology0.owl
[main] WARN org.semanticweb.owlapi.util.SAXParsers - http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit not supported by parser type org.apache.xerces.jaxp.SAXParserImpl, error message: Property 'http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit' is not recognized.
[main] WARN org.semanticweb.owlapi.util.SAXParsers - entityExpansionLimit not supported by parser type org.apache.xerces.jaxp.SAXParserImpl, error message: Property 'entityExpansionLimit' is not recognized.
<https://businessontology.com/ontology/Artifact>
<https://businessontology.com/ontology/Building>
<https://businessontology.com/ontology/Business_User>
<https://businessontology.com/ontology/Customer>
<https://businessontology.com/ontology/Location>
<https://businessontology.com/ontology/Transaction_Document>
[2020-10-09 20:42:46] [INFO   ] Analyzing restrictions of Class: <https://businessontology.com/ontology/Building> with axiom: ObjectSomeValuesFrom(<https://businessontology.com/ontology/locatedAt> <https://businessontology.com/ontology/Location>) 
[2020-10-09 20:42:46] [INFO   ] Analyzing restrictions of Class: <https://businessontology.com/ontology/Building> with axiom: ObjectSomeValuesFrom(<https://businessontology.com/ontology/locatedAt> <https://businessontology.com/ontology/Location>) 
[2020-10-09 20:42:46] [INFO   ] Parsing class <https://businessontology.com/ontology/Building> 
[2020-10-09 20:42:46] [INFO   ] Parsing class <https://businessontology.com/ontology/Building> 
[2020-10-09 20:42:46] [INFO   ] Parsing class <https://businessontology.com/ontology/Business_User> 
[2020-10-09 20:42:46] [INFO   ] Parsing class <https://businessontology.com/ontology/Business_User> 
[2020-10-09 20:42:46] [INFO   ] Analyzing restrictions of Class: <https://businessontology.com/ontology/Customer> with axiom: ObjectSomeValuesFrom(<https://businessontology.com/ontology/hasOrder> <https://businessontology.com/ontology/Transaction_Document>) 
[2020-10-09 20:42:46] [INFO   ] Analyzing restrictions of Class: <https://businessontology.com/ontology/Customer> with axiom: ObjectSomeValuesFrom(<https://businessontology.com/ontology/hasOrder> <https://businessontology.com/ontology/Transaction_Document>) 
[2020-10-09 20:42:46] [INFO   ] Parsing class <https://businessontology.com/ontology/Customer> 
[2020-10-09 20:42:46] [INFO   ] Parsing class <https://businessontology.com/ontology/Customer> 
[2020-10-09 20:42:46] [INFO   ] Parsing class <https://businessontology.com/ontology/Location> 
[2020-10-09 20:42:46] [INFO   ] Parsing class <https://businessontology.com/ontology/Location> 
[2020-10-09 20:42:46] [INFO   ] Parsing class <https://businessontology.com/ontology/Transaction_Document> 
[2020-10-09 20:42:46] [INFO   ] Parsing class <https://businessontology.com/ontology/Transaction_Document> 

But each class seems to be parsed twice. Did you get this output?

It successfully generates a new server config:

openapi.yaml.zip

but then returns an error when running the generate-server.sh script:

Dougal-Watts-Retina-MacBook-Pro:python dwatt$ bash generate-server.sh 
Docker is installed
Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 1, Warning count: 0
Errors: 
	-attribute .servers.url is missing

	at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:424)
	at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:453)
	at org.openapitools.codegen.cmd.Generate.run(Generate.java:407)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)

@dgarijo
Copy link
Contributor

dgarijo commented Oct 9, 2020 via email

@DougalW
Copy link
Author

DougalW commented Oct 9, 2020

I copied the yaml into the python director and ran the generate-server.sh script and it still returns this error:

Dougal-Watts-Retina-MacBook-Pro:python dwatt$ bash generate-server.sh 
Docker is installed
Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 1, Warning count: 0
Errors: 
	-attribute .servers.url is missing

	at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:424)
	at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:453)
	at org.openapitools.codegen.cmd.Generate.run(Generate.java:407)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)

@dgarijo
Copy link
Contributor

dgarijo commented Oct 9, 2020

Ok, I have re-checked, and I did not share the right yaml with you.
You have to remove line 11 which has:

- description: localhost server

instead of a URL. This happens because in the config.yaml used as input there is a:

  servers:
    - url: http://localhost:8080/v1
    - description: localhost server

and the description should not be there. Please give it a try with the attached yaml, or regenerate the config without description in the config.yaml. I will open another issue to make sure that OBA only copies from the documentation the things we need (instead of also copying things we don't)

righ_yaml.zip

@DougalW
Copy link
Author

DougalW commented Oct 10, 2020

I removed the description line from the config.yaml file and re-generated it. Everything works fine until I try and start the server when it returns two errors:

Dougal-Watts-Retina-MacBook-Pro:server dwatt$ docker run -p 8080:8080 openapi_server
2020-10-10 04:20:29,473 - root - ERROR - /usr/src/app/contexts/context_overwrite.json missing
2020-10-10 04:20:29,905 - openapi_server.cached - WARNING - Cache file does not exist: [Errno 2] No such file or directory: '/usr/src/app/openapi_server/openapi/openapi.yaml.cache'
2020-10-10 04:20:30,018 - root - ERROR - /usr/src/app/contexts/context_overwrite.json missing
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/connexion/apis/abstract.py", line 209, in add_paths
    self.add_operation(path, method)
  File "/usr/local/lib/python3.8/site-packages/connexion/apis/abstract.py", line 162, in add_operation
    operation = make_operation(
  File "/usr/local/lib/python3.8/site-packages/connexion/operations/__init__.py", line 8, in make_operation
    return spec.operation_cls.from_spec(spec, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/connexion/operations/openapi.py", line 128, in from_spec
    return cls(
  File "/usr/local/lib/python3.8/site-packages/connexion/operations/openapi.py", line 75, in __init__
    super(OpenAPIOperation, self).__init__(
  File "/usr/local/lib/python3.8/site-packages/connexion/operations/abstract.py", line 96, in __init__
    self._resolution = resolver.resolve(self)
  File "/usr/local/lib/python3.8/site-packages/connexion/resolver.py", line 40, in resolve
    return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
  File "/usr/local/lib/python3.8/site-packages/connexion/resolver.py", line 64, in resolve_function_from_operation_id
    raise ResolverError(msg, sys.exc_info())
connexion.exceptions.ResolverError: <ResolverError: Cannot resolve operationId "openapi_server.controllers.business_user_controller.business_users_get"! Import error was "cannot import name 'BUSINESSUSER_TYPE_NAME' from 'openapi_server.utils.vars' (/usr/src/app/openapi_server/utils/vars.py)">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/src/app/openapi_server/__main__.py", line 20, in <module>
    main()
  File "/usr/src/app/openapi_server/__main__.py", line 13, in main
    app.add_api('openapi.yaml',
  File "/usr/local/lib/python3.8/site-packages/connexion/apps/flask_app.py", line 57, in add_api
    api = super(FlaskApp, self).add_api(specification, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/connexion/apps/abstract.py", line 144, in add_api
    api = self.api_cls(specification,
  File "/usr/local/lib/python3.8/site-packages/connexion/apis/abstract.py", line 111, in __init__
    self.add_paths()
  File "/usr/local/lib/python3.8/site-packages/connexion/apis/abstract.py", line 216, in add_paths
    self._handle_add_operation_error(path, method, err.exc_info)
  File "/usr/local/lib/python3.8/site-packages/connexion/apis/abstract.py", line 231, in _handle_add_operation_error
    raise value.with_traceback(traceback)
  File "/usr/local/lib/python3.8/site-packages/connexion/resolver.py", line 61, in resolve_function_from_operation_id
    return self.function_resolver(operation_id)
  File "/usr/local/lib/python3.8/site-packages/connexion/utils.py", line 123, in get_function_from_name
    raise last_import_error
  File "/usr/local/lib/python3.8/site-packages/connexion/utils.py", line 111, in get_function_from_name
    module = importlib.import_module(module_name)
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/src/app/openapi_server/controllers/business_user_controller.py", line 4, in <module>
    from openapi_server.utils.vars import BUSINESSUSER_TYPE_NAME, BUSINESSUSER_TYPE_URI
ImportError: cannot import name 'BUSINESSUSER_TYPE_NAME' from 'openapi_server.utils.vars' (/usr/src/app/openapi_server/utils/vars.py)

@dgarijo
Copy link
Contributor

dgarijo commented Oct 10, 2020 via email

@mosoriob
Copy link
Contributor

The reason of the original error is the config.yaml file.

  servers:
    - url: http://localhost:8080/v1
    - description: localhost server

Must be:

  servers:
    - url: http://localhost:8080/v1
      description: localhost server

image

@mosoriob
Copy link
Contributor

I'm going to close this issue.
@DougalW the issue for the second error is: #134

mosoriob added a commit that referenced this issue Oct 12, 2020
mosoriob added a commit that referenced this issue Oct 12, 2020
* fix: wrong opeanpi spec

fix: #132

* fix: remove '_' from the class_name

mustache (the template manager used by the openapi generator) is
removing the underscore symbol from the class name

The serializer python creates a variable file with the URI and name of
the class. However, it wasn't removing the symbol.

The commit fixes #134
@dgarijo
Copy link
Contributor

dgarijo commented Oct 12, 2020

@DougalW the issue seems to have been fixed. Can you please give it another try?

@DougalW
Copy link
Author

DougalW commented Oct 12, 2020

Just re-ran it and it runs just fine. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants