Skip to content

feat(api): add APIFlask decorators to improve generated API spec doc#857

Draft
tang-mm wants to merge 11 commits into
mainfrom
certtf-780-api-docstring
Draft

feat(api): add APIFlask decorators to improve generated API spec doc#857
tang-mm wants to merge 11 commits into
mainfrom
certtf-780-api-docstring

Conversation

@tang-mm
Copy link
Copy Markdown
Contributor

@tang-mm tang-mm commented Dec 31, 2025

This PR enhances the Server API documentation using inline docstrings and decorators in v1.py, following APIFlask pattern. This improves the auto-generated OpenAPI spec with comprehensive documentation.

Description

API endpoint documentation migrated from server/API.md to v1.py:

  • method docstring: the first line is "summary", followed by endpoint description text
  • @v1.input and @v1.output decorators for request/response
  • @v1.doc(responses={...}) decorators for non-200 status codes
  • Moved parameter descriptions from docstrings to Schema metadata in schema.py

Schema definition:

  • Added several new Marshmallow schemas for better explaining endpoint input and output
  • Added field-level metadata descriptions to schemas

Resolved issues

CERTTF-780

Documentation

Web service API changes

API docstring and decorators are added or updated, no behavior changes.

Tests

Using the test introduced in #852 :

$ uvx --with tox-uv tox run -e schema

Copy link
Copy Markdown
Collaborator

@ajzobro ajzobro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recognize that this was moved to DRAFT, but I left some comments anyway.

"tags": ["test", "sample"],
"provision_data": {"url": "<url>"},
"test_data": {"test_cmds": "lsb_release -a"},
},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to add missing parameters added since this was drafted.



class JobInQueueOut(Schema):
"""Job in queue output schema."""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Job in queue output schema."""
"""Job (sub-set of job data) for queue output schema."""

keys=fields.String(metadata={"description": "Queue name"}),
values=fields.Dict(
keys=fields.String(metadata={"description": "Image name"}),
values=fields.String(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a string, e.g. a URL to an image; or is this binary or otherwise encoded data?

values=fields.String(
metadata={"description": "Image provision data"}
),
metadata={"description": "Image data for the queue"},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on earlier answer, I think this also needs refinement.



class ImagePostIn(Schema):
"""Agent image input schema."""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would discard the word "Agent" and focus on Job or Queue.

class ClientId(Schema):
"""Client ID input schema."""

client_id = fields.String(required=True)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should try to disambiguate Agents from Clients and for that matter server clients from "Users"

class SecretPath(Schema):
"""Secret path schema."""

path = fields.String(required=True)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are rules about what makes for a good path, e.g. strings and forward slashes with some numbers, etc. That would be good to capture in an API.

"""Refresh token output schema."""

access_token = fields.String(required=True)
token_type = fields.String(required=True)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the token type will always be "Refresh" we could clarify that here.

"type": "string"
},
"log": {
"description": "Push and keep only the last 100 lines",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer accurate.

},
)
@v1.input(schemas.ClientId, location="path", arg_name="client_id")
@v1.auth_required(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many calls in this code that reference v1.auth_required but there is no such function defined in the current codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants