Bug 52862 - 73_udm-rest/01_openapi_validation fails
73_udm-rest/01_openapi_validation fails
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UDM - REST API
UCS 4.4
Other Linux
: P5 normal (vote)
: UCS 4.4-7-errata
Assigned To: Florian Best
Felix Botner
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2021-03-02 14:50 CET by Felix Botner
Modified: 2021-03-03 18:46 CET (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

Note You need to log in before you can comment on or make changes to this bug.
Description Felix Botner univentionstaff 2021-03-02 14:50:39 CET
Test test fails with

File "/usr/local/lib/python3.5/dist-packages/openapi_schema_validator/validators.py", line 1, in <module>
(2021-03-02 13:11:22.837827)     from jsonschema import _legacy_validators, _utils, _validators
(2021-03-02 13:11:22.837873) ImportError: cannot import name '_legacy_validators'

seems that jsonschema is to old for the new openapi_schema_validator
Comment 1 Felix Botner univentionstaff 2021-03-02 14:59:57 CET
just added

 pip3 install -U jsonschema

to update the jsonschema module

still fails with

+ curl -u Administrator:univention http://localhost/univention/udm/openapi.json
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1313k  100 1313k    0     0   144k      0  0:00:09  0:00:09 --:--:--  136k
{'in': 'query', 'description': 'The `LDAP` search scope (sub, base, one).', 'examples': {'one': {'value': 'one', 'summary': 'one-scope'}, 'base': {'value': 'base', 'summary': 'base-scope'}, 'sub': {'value': 'sub', 'summary': 'sub-scope'}}, 'name': 'scope', 'example': 'sub', 'schema': {'default': 'sub', 'type': 'string'}} is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['components']['properties']['parameters']['patternProperties']['^[a-zA-Z0-9\\.\\-_]+$']:
    {'oneOf': [{'$ref': '#/definitions/Reference'},
               {'$ref': '#/definitions/Parameter'}]}

On instance['components']['parameters']['search.scope']:
    {'description': 'The `LDAP` search scope (sub, base, one).',
     'example': 'sub',
     'examples': {'base': {'summary': 'base-scope', 'value': 'base'},
                  'one': {'summary': 'one-scope', 'value': 'one'},
                  'sub': {'summary': 'sub-scope', 'value': 'sub'}},
     'in': 'query',
     'name': 'scope',
     'schema': {'default': 'sub', 'type': 'string'}}
Comment 2 Florian Best univentionstaff 2021-03-02 22:52:23 CET
The schema validation works again when removing parameter examples.
I still have to check if this is an error in the openapi validator or if our schema really was invalid.

diff --git management/univention-directory-manager-rest/src/univention/admin/rest/module.py management/univention-directory-manager-rest/src/univention/admin/rest/module.py
index 74605dbf87..cd2ea2f32f 100755
--- management/univention-directory-manager-rest/src/univention/admin/rest/module.py
+++ management/univention-directory-manager-rest/src/univention/admin/rest/module.py
@@ -1504,11 +1504,6 @@ class OpenAPI(Resource):
                                                },
                                                "example": "sub",
                                                "description": "The `LDAP` search scope (sub, base, one).",
-                                               "examples": {
-                                                       "sub": {"value": "sub", "summary": "sub-scope"},
-                                                       "base": {"value": "base", "summary": "base-scope"},
-                                                       "one": {"value": "one", "summary": "one-scope"},
-                                               }
                                        },
                                        'search.filter': {
                                                "in": "query",
@@ -1516,11 +1511,6 @@ class OpenAPI(Resource):
                                                "schema": {"type": "string", "default": ""},
                                                "description": "A ldap filter which may contain `UDM` property names instead of `LDAP` attribute names.",
                                                "example": "(objectClass=*)",
-                                               "examples": {
-                                                       "users-user": {
-                                                               "value": "(|(username=Administrator)(username=Admin*))",
-                                                       }
-                                               },
                                        },
                                        'search.query': {
                                                "in": "query",
Comment 3 Florian Best univentionstaff 2021-03-03 13:37:57 CET
The OpenAPI schema has been adjusted:
examples and example were both specified but are mutually exclusive.
The old swagger UI does not show examples.
I upgraded swagger UI in UCS 5.0, if you want to have a look: http://fqdn/univention/udm/schema/.

univention-directory-manager-rest.yaml
e1c42a508758 | YAML Bug #52862

univention-directory-manager-rest (9.0.16-13)
6579096c3ac1 | Bug #52862: fix OpenAPI schema: remove mutual exclusive "example" and "examples"

ucs-test (9.0.7-25)
1c482f42ca92 | Bug #52862: 73_udm-rest/01_openapi_validation fails

Merged to UCS 5.0:

univention-directory-manager-rest (10.0.1-3)
90e6a347bc41 | Bug #52862: fix OpenAPI schema: remove mutual exclusive "example" and "examples"

ucs-test (10.0.4-13)
457a75dd6bfa | Bug #52862: 73_udm-rest/01_openapi_validation fails
Comment 4 Felix Botner univentionstaff 2021-03-03 14:01:24 CET
still get 

+ curl -u Administrator:univention http://localhost/univention/udm/openapi.json
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1693k  100 1693k    0     0   114k      0  0:00:14  0:00:14 --:--:--  109k
{'examples': {'any-object': {'value': '(objectClass=*)'}, 'admin-user': {'value': '(|(username=Administrator)(username=Admin*))'}}, 'name': 'filter', 'description': 'A ldap filter which may contain `UDM` property names instead of `LDAP` attribute names.', 'in': 'query', 'schema': {'type': 'string', 'default': ''}, 'example': '(objectClass=*)'} is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['components']['properties']['parameters']['patternProperties']['^[a-zA-Z0-9\\.\\-_]+$']:
    {'oneOf': [{'$ref': '#/definitions/Reference'},
               {'$ref': '#/definitions/Parameter'}]}

On instance['components']['parameters']['search.filter']:
    {'description': 'A ldap filter which may contain `UDM` property names '
                    'instead of `LDAP` attribute names.',
     'example': '(objectClass=*)',
     'examples': {'admin-user': {'value': '(|(username=Administrator)(username=Admin*))'},
                  'any-object': {'value': '(objectClass=*)'}},
     'in': 'query',
     'name': 'filter',
     'schema': {'default': '', 'type': 'string'}}

univention-directory-manager-rest:
  Installiert:           9.0.16-13A~4.4.0.202103031329
  Installationskandidat: 9.0.16-13A~4.4.0.202103031329
Comment 5 Florian Best univentionstaff 2021-03-03 15:04:00 CET
Sorry, accidentally did not remove the "example" property.

univention-directory-manager-rest (9.0.16-14)
b25c8cd31866 | fixup! Bug #52862: fix OpenAPI schema: remove mutual exclusive "example" and "examples"
univention-directory-manager-rest (10.0.1-3)
b0102b976cea | fixup! Bug #52862: fix OpenAPI schema: remove mutual exclusive "example" and "examples"
Comment 6 Felix Botner univentionstaff 2021-03-03 15:07:07 CET
OK - univention-directory-manager-rest
OK - 73_udm-rest/01_openapi_validation
OK - yaml

OK - merged to 5.0-0