Bug 50049 - [UDM HTTP API] invalid swagger / OpenAPI schema
[UDM HTTP API] invalid swagger / OpenAPI schema
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UDM - REST API
UCS 4.4
Other Linux
: P5 normal (vote)
: ---
Assigned To: Florian Best
UMC maintainers
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2019-08-24 07:06 CEST by Daniel Tröder
Modified: 2019-10-02 16:06 CEST (History)
1 user (show)

See Also:
What kind of report is it?: Development Internal
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments
Swagger schema of VM dtroeder_66-m66 (10.200.3.66) (672.87 KB, application/json)
2019-08-26 08:56 CEST, Daniel Tröder
Details
Error messages shown by the Swagger Editor (copied inner HTML from dynamic page). (413.73 KB, text/html)
2019-08-26 09:01 CEST, Daniel Tröder
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Tröder univentionstaff 2019-08-24 07:06:36 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
Comment 1 Florian Best univentionstaff 2019-08-24 07:44:59 CEST
Can you pastebin the error messages?
Comment 2 Daniel Tröder univentionstaff 2019-08-25 03:40:49 CEST
Just copy and paste the schema into the online validators.
Comment 3 Florian Best univentionstaff 2019-08-25 10:10:18 CEST
(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.
Comment 4 Daniel Tröder univentionstaff 2019-08-26 08:56:01 CEST
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
Comment 5 Daniel Tröder univentionstaff 2019-08-26 09:01:27 CEST
Created attachment 10163 [details]
Error messages shown by the Swagger Editor (copied inner HTML from dynamic page).
Comment 6 Daniel Tröder univentionstaff 2019-08-26 09:05:59 CEST
apidevtools.org seems to be down atm.
Comment 7 Florian Best univentionstaff 2019-08-26 21:14:23 CEST
Improoved that. Schema now validates.

univention-management-console-module-udm (9.0.12-29)
3e192c393cd2 | Bug #27816: Bug #50049: fix/improove swagger definition
Comment 8 Daniel Tröder univentionstaff 2019-09-04 23:01:24 CEST
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": ""}}
Comment 9 Daniel Tröder univentionstaff 2019-09-04 23:03:57 CEST
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
Comment 10 Florian Best univentionstaff 2019-09-05 09:39:53 CEST
(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.
Comment 11 Daniel Tröder univentionstaff 2019-09-05 17:09:39 CEST
I need to generate a client for 20 modules. Generating 20 clients is not desirable. Please create a complete openapi schema.
Comment 12 Daniel Tröder univentionstaff 2019-09-06 11:27:43 CEST
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.
Comment 13 Florian Best univentionstaff 2019-09-06 13:37:38 CEST
(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.
Comment 14 Florian Best univentionstaff 2019-09-06 13:40:21 CEST
(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.
Comment 15 Daniel Tröder univentionstaff 2019-09-08 09:41:15 CEST
→ 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.
Comment 16 Daniel Tröder univentionstaff 2019-09-11 09:08:15 CEST
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".
Comment 17 Daniel Tröder univentionstaff 2019-09-13 20:35:51 CEST
The OpenAPI schema does not contain the "filter" parameter.
That prevents clients to use that feature.
We need this in the UCS@school client.
Comment 18 Daniel Tröder univentionstaff 2019-09-13 21:01:16 CEST
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.
Comment 19 Florian Best univentionstaff 2019-09-17 16:07:55 CEST
Everything should be valid now.
Comment #17: filter argument has been added.
Comment #18: objets in the search are embedded as HAL objects now.
Comment 20 Florian Best univentionstaff 2019-10-02 16:06:35 CEST
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".