diff --git a/awx/main/fields.py b/awx/main/fields.py index 325ae25967..e523afa16d 100644 --- a/awx/main/fields.py +++ b/awx/main/fields.py @@ -542,6 +542,10 @@ class CredentialTypeInputField(JSONSchemaField): 'type': 'object', 'additionalProperties': False, 'properties': { + 'required': { + 'type': 'array', + 'items': {'type': 'string'} + }, 'fields': { 'type': 'array', 'items': { diff --git a/awx/main/tests/functional/api/test_credential_type.py b/awx/main/tests/functional/api/test_credential_type.py index e0666e60fa..eea1d42e8a 100644 --- a/awx/main/tests/functional/api/test_credential_type.py +++ b/awx/main/tests/functional/api/test_credential_type.py @@ -170,6 +170,30 @@ def test_create_with_valid_inputs(get, post, admin): assert fields[0]['type'] == 'string' +@pytest.mark.django_db +def test_create_with_required_inputs(get, post, admin): + response = post(reverse('api:credential_type_list'), { + 'kind': 'cloud', + 'name': 'MyCloud', + 'inputs': { + 'fields': [{ + 'id': 'api_token', + 'label': 'API Token', + 'type': 'string', + 'secret': True + }], + 'required': ['api_token'], + }, + 'injectors': {} + }, admin) + assert response.status_code == 201 + + response = get(reverse('api:credential_type_list'), admin) + assert response.data['count'] == 1 + required = response.data['results'][0]['inputs']['required'] + assert required == ['api_token'] + + @pytest.mark.django_db @pytest.mark.parametrize('inputs', [ True,