Univention Bugzilla – Bug 50049
[UDM HTTP API] invalid swagger / OpenAPI schema
Last modified: 2019-10-02 16:06:35 CEST
The schema downloadable at http://FQDN/univention/udm/swagger.json does not validate. Online validators: * https://editor.swagger.io/ * https://apidevtools.org/swagger-parser/online/ Offline validation is possible through * https://openapi.tools * https://github.com/p1c2u/openapi-spec-validator (Python) Swagger client creation is not possible. I tried with two client libraries: * https://github.com/pyopenapi/pyswagger * https://github.com/Yelp/bravado
Can you pastebin the error messages?
Just copy and paste the schema into the online validators.
(In reply to Daniel Tröder from comment #2) > Just copy and paste the schema into the online validators. I did that, that works fine for me. I don't get any error message and can just work with it. Please attach the swagger.json you used.
Created attachment 10162 [details] Swagger schema of VM dtroeder_66-m66 (10.200.3.66) You can start the VM dtroeder_66-m66 (10.200.3.66) for this: http://10.200.3.66/univention/udm/swagger.json
Created attachment 10163 [details] Error messages shown by the Swagger Editor (copied inner HTML from dynamic page).
apidevtools.org seems to be down atm.
Improoved that. Schema now validates. univention-management-console-module-udm (9.0.12-29) 3e192c393cd2 | Bug #27816: Bug #50049: fix/improove swagger definition
I installed univention-management-console-module-udm 9.0.12-32 on a UCS 4.4-1 errata251 and now at /univention/udm/schema/ I get "No API definition provided." I looked at the page source and found "/univention/udm/openapi.json". But when I go there, I get: {"error": {"message": "'module' object has no attribute 'mapping'", "code": 500, "traceback": "Traceback (most recent call last):\n File \"/usr/lib/python2.7/dist-packages/tornado/web.py\", line 1467, in _execute\n result = method(*self.path_args, **self.path_kwargs)\n File \"/usr/lib/pymodules/python2.7/univention/management/modules/udm/module.py\", line 1387, in get\n \"example\": self.abspath(module.name) + '/%s=foo,dc=example,dc=net' % (module.module.mapping.mapName(module.identifies) or 'cn',),\nAttributeError: 'module' object has no attribute 'mapping'\n", "error": {}, "title": ""}}
I tried /univention/udm/swagger.json and got a traceback sent as text document: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 1446, in _execute result = self.prepare() File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 2174, in prepare raise HTTPError(self._status_code) HTTPError: HTTP 404: Not Found
(In reply to Daniel Tröder from comment #9) > I tried /univention/udm/swagger.json and got a traceback sent as text > document: > > Traceback (most recent call last): > File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 1446, in > _execute > result = self.prepare() > File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 2174, in > prepare > raise HTTPError(self._status_code) > HTTPError: HTTP 404: Not Found It has been renamed into openapi.json. As workaround for today you can replace /univention/udm/openapi.json with /univention/udm/users/user/openapi.json for example.
I need to generate a client for 20 modules. Generating 20 clients is not desirable. Please create a complete openapi schema.
I'm using https://github.com/OpenAPITools/openapi-generator to create an API client. It works well. Just download the jar an go :) The validation of the schemas (I tryed groups/group and users/user) was successful: $ java -jar ~/dev/openapi-generator-cli.jar generate -g python --library asyncio -i /tmp/udm_swagger_groups_group.json When generating the client... $ java -jar ~/dev/openapi-generator-cli.jar validate -i /tmp/udm_swagger_users_user.json It writes a lot of WARN lines: [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one But the client is generated nonetheless. I haven't finished testing it, but a first looks is promising.
(In reply to Daniel Tröder from comment #11) > I need to generate a client for 20 modules. Generating 20 clients is not > desirable. Please create a complete openapi schema. You can get a complete schema via the regular link. There was just a typo for modules, which don't have a mapping (traceback comment #8). It's fixed in the latest version: 9.0.12-33A~4.4.0.201909061335.
(In reply to Daniel Tröder from comment #12) > It writes a lot of WARN lines: > > [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in > content, returning only the first one > > But the client is generated nonetheless. I haven't finished testing it, but > a first looks is promising. Maybe test this again with the global schema? There are also unmerged changes in the schema generation due to Bug #50047 not being merged.
→ univention-management-console-module-udm 9.0.12-34 $ java -jar ~/dev/openapi-generator-cli.jar validate -i http://10.200.3.66/univention/udm/openapi.json Validating spec (http://10.200.3.66/univention/udm/openapi.json) Errors: -attribute components.schemas.dns-forward_zone.default is not of type `string` -attribute components.schemas.dns-alias.default is not of type `string` -attribute components.schemas.dns-txt_record.default is not of type `string` -attribute components.schemas.dns-reverse_zone.default is not of type `string` -attribute components.schemas.container-dc.default is not of type `array` -attribute components.schemas.dns-host_record.default is not of type `string` -attribute components.schemas.dns-srv_record.default is not of type `string` -attribute components.schemas.dns-ns_record.default is not of type `string` [error] Spec has 8 errors.
No validation errors anymore: $ java -jar ~/dev/openapi-generator-cli.jar validate -i http://10.200.3.66/univention/udm/openapi.json Validating spec (http://10.200.3.66/univention/udm/openapi.json) No validation issues detected. ------- When generating a python client.... $ java -jar ~/dev/openapi-generator-cli.jar generate -g python --library asyncio -i http://10.200.3.66/univention/udm/openapi.json ... I get a ton of those warnings: [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.DefaultCodegen - Multiple MediaTypes found, using only the first one But the client is generated anyway. The generated code is the same as it was before (when using --skip-validate-spec). ------- I suggest to create a ucs-test that installs multiple OpenAPI validators and checks the schema automatically. Check https://github.com/OpenAPITools/openapi-generator#launcher-script for a script that automatically downloads the newest version of "openapi-generator".
The OpenAPI schema does not contain the "filter" parameter. That prevents clients to use that feature. We need this in the UCS@school client.
Searching is not possible through the OpenAPI schema. The schema says it is --------------------------------------------------------------------- { _embedded { udm:object [ users-user{ dn _embedded uuid uri policies position properties {...} objectType } ] } } --------------------------------------------------------------------- But the returned data for /univention/udm/appcenter/app/?scope=sub&hidden=true is: --------------------------------------------------------------------- { _embedded { udm:form [ .. ], udm:layout [ .. ] }, _links { .. }, results: 20, entries: [ { dn: .. name: .. }, { dn: .. name: .. }, .. ] } --------------------------------------------------------------------- This prevents clients from performing searches. We need this in the UCS@school client.
Everything should be valid now. Comment #17: filter argument has been added. Comment #18: objets in the search are embedded as HAL objects now.
UCS 4.4-2 has been released: https://docs.software-univention.de/release-notes-4.4-2-en.html https://docs.software-univention.de/release-notes-4.4-2-de.html If this error occurs again, please use "Clone This Bug".