Skip to content

Commit

Permalink
fix: RND-74: Generate swagger.json (HumanSignal#5911)
Browse files Browse the repository at this point in the history
When generating schema in CI, we need to access the latest swagger json

Create a command:
```
make generate-swagger
```

that outputs `swagger.json` in the root directory

**Additional changes to openapi schema**
- a few more endpoints with extensions (projects, tasks, annotations,
predictions)
- example response

---------

Co-authored-by: nik <[email protected]>
  • Loading branch information
niklub and nik authored May 22, 2024
1 parent 81eaa91 commit 48fa4f7
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ fmt-check-all:
# Configure pre-push hook using pre-commit
configure-hooks:
pre-commit install --hook-type pre-push

# Generate swagger.json
generate-swagger:
DJANGO_DB=sqlite LOG_DIR=tmp DEBUG=true LOG_LEVEL=DEBUG DJANGO_SETTINGS_MODULE=core.settings.label_studio python label_studio/manage.py generate_swagger swagger.json
1 change: 1 addition & 0 deletions label_studio/core/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
'SUPPORTED_SUBMIT_METHODS': ['get', 'post', 'put', 'delete', 'patch'],
'OPERATIONS_SORTER': 'alpha',
'DEFAULT_AUTO_SCHEMA_CLASS': 'core.utils.openapi_extensions.XVendorExtensionsAutoSchema',
'DEFAULT_INFO': 'core.urls.open_api_info',
}

SENTRY_DSN = get_env('SENTRY_DSN', None)
Expand Down
70 changes: 70 additions & 0 deletions label_studio/projects/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class ProjectFilterSet(FilterSet):
name='get',
decorator=swagger_auto_schema(
tags=['Projects'],
x_fern_sdk_group_name='projects',
x_fern_sdk_method_name='list',
operation_summary='List your projects',
operation_description="""
Return a list of the projects that you've created.
Expand All @@ -127,6 +129,8 @@ class ProjectFilterSet(FilterSet):
decorator=swagger_auto_schema(
tags=['Projects'],
operation_summary='Create new project',
x_fern_sdk_group_name='projects',
x_fern_sdk_method_name='create',
operation_description="""
Create a project and set up the labeling interface in Label Studio using the API.
Expand Down Expand Up @@ -189,14 +193,76 @@ def post(self, request, *args, **kwargs):
name='get',
decorator=swagger_auto_schema(
tags=['Projects'],
x_fern_sdk_group_name='projects',
x_fern_sdk_method_name='get',
operation_summary='Get project by ID',
operation_description='Retrieve information about a project by project ID.',
responses={
'200': openapi.Response(
description='Project information',
schema=ProjectSerializer,
examples={
'application/json': {
'id': 1,
'title': 'My project',
'description': 'My first project',
'label_config': '<View>[...]</View>',
'expert_instruction': 'Label all cats',
'show_instruction': True,
'show_skip_button': True,
'enable_empty_annotation': True,
'show_annotation_history': True,
'organization': 1,
'color': '#FF0000',
'maximum_annotations': 1,
'is_published': True,
'model_version': '1.0.0',
'is_draft': False,
'created_by': {
'id': 1,
'first_name': 'Jo',
'last_name': 'Doe',
'email': '[email protected]',
},
'created_at': '2023-08-24T14:15:22Z',
'min_annotations_to_start_training': 0,
'start_training_on_annotation_update': True,
'show_collab_predictions': True,
'num_tasks_with_annotations': 10,
'task_number': 100,
'useful_annotation_number': 10,
'ground_truth_number': 5,
'skipped_annotations_number': 0,
'total_annotations_number': 10,
'total_predictions_number': 0,
'sampling': 'Sequential sampling',
'show_ground_truth_first': True,
'show_overlap_first': True,
'overlap_cohort_percentage': 100,
'task_data_login': 'user',
'task_data_password': 'secret',
'control_weights': {},
'parsed_label_config': '{"tag": {...}}',
'evaluate_predictions_automatically': False,
'config_has_control_tags': True,
'skip_queue': 'REQUEUE_FOR_ME',
'reveal_preannotations_interactively': True,
'pinned_at': '2023-08-24T14:15:22Z',
'finished_task_number': 10,
'queue_total': 10,
'queue_done': 100,
}
},
)
},
),
)
@method_decorator(
name='delete',
decorator=swagger_auto_schema(
tags=['Projects'],
x_fern_sdk_group_name='projects',
x_fern_sdk_method_name='delete',
operation_summary='Delete project',
operation_description='Delete a project by specified project ID.',
),
Expand All @@ -205,6 +271,8 @@ def post(self, request, *args, **kwargs):
name='patch',
decorator=swagger_auto_schema(
tags=['Projects'],
x_fern_sdk_group_name='projects',
x_fern_sdk_method_name='update',
operation_summary='Update project',
operation_description='Update the project settings for a specific project.',
request_body=ProjectSerializer,
Expand Down Expand Up @@ -268,6 +336,8 @@ def put(self, request, *args, **kwargs):
decorator=swagger_auto_schema(
tags=['Projects'],
operation_summary='Get next task to label',
x_fern_sdk_group_name='projects',
x_fern_sdk_method_name='next_task',
operation_description="""
Get the next task for labeling. If you enable Machine Learning in
your project, the response might include a "predictions"
Expand Down
28 changes: 28 additions & 0 deletions label_studio/tasks/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
name='post',
decorator=swagger_auto_schema(
tags=['Tasks'],
x_fern_sdk_group_name='tasks',
x_fern_sdk_method_name='create',
operation_summary='Create task',
operation_description='Create a new labeling task in Label Studio.',
request_body=TaskSerializer,
Expand All @@ -56,6 +58,8 @@
name='get',
decorator=swagger_auto_schema(
tags=['Tasks'],
x_fern_sdk_group_name='tasks',
x_fern_sdk_method_name='list',
operation_summary='Get tasks list',
operation_description="""
Retrieve a list of tasks with pagination for a specific view or project, by using filters and ordering.
Expand Down Expand Up @@ -107,6 +111,8 @@ def perform_create(self, serializer):
name='get',
decorator=swagger_auto_schema(
tags=['Tasks'],
x_fern_sdk_group_name='tasks',
x_fern_sdk_method_name='get',
operation_summary='Get task',
operation_description="""
Get task data, metadata, annotations and other attributes for a specific labeling task by task ID.
Expand All @@ -120,6 +126,8 @@ def perform_create(self, serializer):
name='patch',
decorator=swagger_auto_schema(
tags=['Tasks'],
x_fern_sdk_group_name='tasks',
x_fern_sdk_method_name='update',
operation_summary='Update task',
operation_description='Update the attributes of an existing labeling task.',
manual_parameters=[
Expand All @@ -132,6 +140,8 @@ def perform_create(self, serializer):
name='delete',
decorator=swagger_auto_schema(
tags=['Tasks'],
x_fern_sdk_group_name='tasks',
x_fern_sdk_method_name='delete',
operation_summary='Delete task',
operation_description='Delete a task in Label Studio. This action cannot be undone!',
manual_parameters=[
Expand Down Expand Up @@ -249,6 +259,8 @@ def put(self, request, *args, **kwargs):
name='patch',
decorator=swagger_auto_schema(
tags=['Annotations'],
x_fern_sdk_group_name='annotations',
x_fern_sdk_method_name='update',
operation_summary='Update annotation',
operation_description='Update existing attributes on an annotation.',
request_body=AnnotationSerializer,
Expand All @@ -258,6 +270,8 @@ def put(self, request, *args, **kwargs):
name='delete',
decorator=swagger_auto_schema(
tags=['Annotations'],
x_fern_sdk_group_name='annotations',
x_fern_sdk_method_name='delete',
operation_summary='Delete annotation',
operation_description="Delete an annotation. This action can't be undone!",
),
Expand Down Expand Up @@ -316,6 +330,8 @@ def delete(self, request, *args, **kwargs):
name='get',
decorator=swagger_auto_schema(
tags=['Annotations'],
x_fern_sdk_group_name='annotations',
x_fern_sdk_method_name='list',
operation_summary='Get all task annotations',
operation_description='List all annotations for a task.',
manual_parameters=[
Expand All @@ -327,6 +343,8 @@ def delete(self, request, *args, **kwargs):
name='post',
decorator=swagger_auto_schema(
tags=['Annotations'],
x_fern_sdk_group_name='annotations',
x_fern_sdk_method_name='create',
operation_summary='Create annotation',
operation_description="""
Add annotations to a task like an annotator does. The content of the result field depends on your
Expand Down Expand Up @@ -489,6 +507,8 @@ class AnnotationDraftAPI(generics.RetrieveUpdateDestroyAPIView):
name='list',
decorator=swagger_auto_schema(
tags=['Predictions'],
x_fern_sdk_group_name='predictions',
x_fern_sdk_method_name='list',
operation_summary='List predictions',
filter_inspectors=[DjangoFilterDescriptionInspector],
operation_description='List all predictions and their IDs.',
Expand All @@ -498,6 +518,8 @@ class AnnotationDraftAPI(generics.RetrieveUpdateDestroyAPIView):
name='create',
decorator=swagger_auto_schema(
tags=['Predictions'],
x_fern_sdk_group_name='predictions',
x_fern_sdk_method_name='create',
operation_summary='Create prediction',
operation_description='Create a prediction for a specific task.',
),
Expand All @@ -506,6 +528,8 @@ class AnnotationDraftAPI(generics.RetrieveUpdateDestroyAPIView):
name='retrieve',
decorator=swagger_auto_schema(
tags=['Predictions'],
x_fern_sdk_group_name='predictions',
x_fern_sdk_method_name='get',
operation_summary='Get prediction details',
operation_description='Get details about a specific prediction by its ID.',
manual_parameters=[
Expand All @@ -528,6 +552,8 @@ class AnnotationDraftAPI(generics.RetrieveUpdateDestroyAPIView):
name='partial_update',
decorator=swagger_auto_schema(
tags=['Predictions'],
x_fern_sdk_group_name='predictions',
x_fern_sdk_method_name='update',
operation_summary='Update prediction',
operation_description='Update prediction data by prediction ID.',
manual_parameters=[
Expand All @@ -539,6 +565,8 @@ class AnnotationDraftAPI(generics.RetrieveUpdateDestroyAPIView):
name='destroy',
decorator=swagger_auto_schema(
tags=['Predictions'],
x_fern_sdk_group_name='predictions',
x_fern_sdk_method_name='delete',
operation_summary='Delete prediction',
operation_description='Delete a prediction by prediction ID.',
manual_parameters=[
Expand Down

0 comments on commit 48fa4f7

Please sign in to comment.