Update OpenAPI spec to improve descriptions and messages (#16260)

* Update OpenAPI spec

* lint fixes

* fix decorator for retrieve endpoints

* change decorator method

* fix import

* lint fix
This commit is contained in:
jessicamack
2026-02-04 17:32:57 -05:00
committed by GitHub
parent 5e93f60b9e
commit c9085e4b7f
2 changed files with 39 additions and 5 deletions

View File

@@ -3527,7 +3527,7 @@ class JobRelaunchSerializer(BaseSerializer):
choices=NEW_JOB_TYPE_CHOICES, choices=NEW_JOB_TYPE_CHOICES,
write_only=True, write_only=True,
) )
credential_passwords = VerbatimField(required=True, write_only=True) credential_passwords = VerbatimField(required=False, write_only=True)
class Meta: class Meta:
model = Job model = Job

View File

@@ -52,6 +52,7 @@ from ansi2html import Ansi2HTMLConverter
from datetime import timezone as dt_timezone from datetime import timezone as dt_timezone
from wsgiref.util import FileWrapper from wsgiref.util import FileWrapper
from drf_spectacular.utils import extend_schema_view, extend_schema
# django-ansible-base # django-ansible-base
from ansible_base.lib.utils.requests import get_remote_hosts from ansible_base.lib.utils.requests import get_remote_hosts
@@ -378,6 +379,10 @@ class DashboardJobsGraphView(APIView):
class InstanceList(ListCreateAPIView): class InstanceList(ListCreateAPIView):
"""
Creates an instance if used on a Kubernetes or OpenShift deployment of Ansible Automation Platform.
"""
name = _("Instances") name = _("Instances")
model = models.Instance model = models.Instance
serializer_class = serializers.InstanceSerializer serializer_class = serializers.InstanceSerializer
@@ -1603,7 +1608,11 @@ class CredentialExternalTest(SubDetailAPIView):
obj_permission_type = 'use' obj_permission_type = 'use'
resource_purpose = 'test external credential' resource_purpose = 'test external credential'
@extend_schema_if_available(extensions={"x-ai-description": "Test update the input values and metadata of an external credential"}) @extend_schema_if_available(extensions={"x-ai-description": """Test update the input values and metadata of an external credential.
This endpoint supports testing credentials that connect to external secret management systems
such as CyberArk AIM, CyberArk Conjur, HashiCorp Vault, AWS Secrets Manager, Azure Key Vault,
Centrify Vault, Thycotic DevOps Secrets Vault, and GitHub App Installation Access Token Lookup.
It does not support standard credential types such as Machine, SCM, and Cloud."""})
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
obj = self.get_object() obj = self.get_object()
backend_kwargs = {} backend_kwargs = {}
@@ -1617,9 +1626,12 @@ class CredentialExternalTest(SubDetailAPIView):
with set_environ(**settings.AWX_TASK_ENV): with set_environ(**settings.AWX_TASK_ENV):
obj.credential_type.plugin.backend(**backend_kwargs) obj.credential_type.plugin.backend(**backend_kwargs)
return Response({}, status=status.HTTP_202_ACCEPTED) return Response({}, status=status.HTTP_202_ACCEPTED)
except requests.exceptions.HTTPError as exc: except requests.exceptions.HTTPError:
message = 'HTTP {}'.format(exc.response.status_code) message = """Test operation is not supported for credential type {}.
return Response({'inputs': message}, status=status.HTTP_400_BAD_REQUEST) This endpoint only supports credentials that connect to
external secret management systems such as CyberArk, HashiCorp
Vault, or cloud-based secret managers.""".format(obj.credential_type.kind)
return Response({'detail': message}, status=status.HTTP_400_BAD_REQUEST)
except Exception as exc: except Exception as exc:
message = exc.__class__.__name__ message = exc.__class__.__name__
exc_args = getattr(exc, 'args', []) exc_args = getattr(exc, 'args', [])
@@ -2469,6 +2481,11 @@ class JobTemplateDetail(RelatedJobsPreventDeleteMixin, RetrieveUpdateDestroyAPIV
resource_purpose = 'job template detail' resource_purpose = 'job template detail'
@extend_schema_view(
retrieve=extend_schema(
extensions={'x-ai-description': 'List job template launch criteria'},
)
)
class JobTemplateLaunch(RetrieveAPIView): class JobTemplateLaunch(RetrieveAPIView):
model = models.JobTemplate model = models.JobTemplate
obj_permission_type = 'start' obj_permission_type = 'start'
@@ -2477,6 +2494,9 @@ class JobTemplateLaunch(RetrieveAPIView):
resource_purpose = 'launch a job from a job template' resource_purpose = 'launch a job from a job template'
def update_raw_data(self, data): def update_raw_data(self, data):
"""
Use the ID of a job template to retrieve its launch details.
"""
try: try:
obj = self.get_object() obj = self.get_object()
except PermissionDenied: except PermissionDenied:
@@ -3310,6 +3330,11 @@ class WorkflowJobTemplateLabelList(JobTemplateLabelList):
resource_purpose = 'labels of a workflow job template' resource_purpose = 'labels of a workflow job template'
@extend_schema_view(
retrieve=extend_schema(
extensions={'x-ai-description': 'List workflow job template launch criteria.'},
)
)
class WorkflowJobTemplateLaunch(RetrieveAPIView): class WorkflowJobTemplateLaunch(RetrieveAPIView):
model = models.WorkflowJobTemplate model = models.WorkflowJobTemplate
obj_permission_type = 'start' obj_permission_type = 'start'
@@ -3318,6 +3343,9 @@ class WorkflowJobTemplateLaunch(RetrieveAPIView):
resource_purpose = 'launch a workflow job from a workflow job template' resource_purpose = 'launch a workflow job from a workflow job template'
def update_raw_data(self, data): def update_raw_data(self, data):
"""
Use the ID of a workflow job template to retrieve its launch details.
"""
try: try:
obj = self.get_object() obj = self.get_object()
except PermissionDenied: except PermissionDenied:
@@ -3710,6 +3738,11 @@ class JobCancel(GenericCancelView):
return super().post(request, *args, **kwargs) return super().post(request, *args, **kwargs)
@extend_schema_view(
retrieve=extend_schema(
extensions={'x-ai-description': 'List job relaunch criteria'},
)
)
class JobRelaunch(RetrieveAPIView): class JobRelaunch(RetrieveAPIView):
model = models.Job model = models.Job
obj_permission_type = 'start' obj_permission_type = 'start'
@@ -3717,6 +3750,7 @@ class JobRelaunch(RetrieveAPIView):
resource_purpose = 'relaunch a job' resource_purpose = 'relaunch a job'
def update_raw_data(self, data): def update_raw_data(self, data):
"""Use the ID of a job to retrieve data on retry attempts and necessary passwords."""
data = super(JobRelaunch, self).update_raw_data(data) data = super(JobRelaunch, self).update_raw_data(data)
try: try:
obj = self.get_object() obj = self.get_object()