Skip to content

Conversation

@eceltov
Copy link
Collaborator

@eceltov eceltov commented Jul 16, 2025

This PR adds response Formats.
Action methods can be annotated with the ResponseFormat attribute that link them to a Format class similarly to how the Format attribute works.
Response Formats are only used for swagger generation to detail each response of the endpoint.

The GroupFormat class was added with a nested GroupPrivateDataFormat that was used on many GroupsPresenter endpoints.

Additionally, the PR adds a performance improvement to the BasePresenter that memoizes loose attributes.

Copy link
Member

Choose a reason for hiding this comment

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

I think (since this is like a demo format), all properties should be duly documented (for OAS).

public int $code;

#[FPost(new VMixed())]
public mixed $payload;
Copy link
Member

Choose a reason for hiding this comment

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

The properties should be properly documented (described) for OAS.

@eceltov
Copy link
Collaborator Author

eceltov commented Jul 23, 2025

I added descriptions to the formats (please check, some are really surface level because I could not infer much from the code).

I also added a new feature, where Format classes can be used for validation even in loose attributes:

    #[Query(
        "filters",
        new VObject(UserFilterFormat::class),
        "Named filters that prune the result.",
        required: false,
        nullable: true,
    )]
    public function actionDefault(

Although annotating key-value stores in URL parameters with VArray is valid, the new VObject method provides fine-grained validation and additionally writes the parameter schema to the swagger. The CLI client will then automatically validate user requests against the schema.

public array $students;

#[FPost(new VUuid(), required: false)]
#[FPost(new VUuid(), "The instance ID of the group", required: false)]
Copy link
Member

Choose a reason for hiding this comment

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

ID of an instance in which the group belongs.

public string $instanceId;

#[FPost(new VBool())]
#[FPost(new VBool(), "Whether the group has a valid license")]
Copy link
Member

Choose a reason for hiding this comment

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

Whether the instance where the group belongs has a valid license.

public array $shadowAssignments;

#[FPost(new VBool())]
#[FPost(new VBool(), "Whether the group statistics are public")]
Copy link
Member

Choose a reason for hiding this comment

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

Whether the student's results are visible to other students.

public bool $publicStats;

#[FPost(new VBool())]
#[FPost(new VBool(), "Whether the group is detaining")]
Copy link
Member

Choose a reason for hiding this comment

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

Whether the group detains the students (so they can be released only by the teacher).

public bool $detaining;

#[FPost(new VDouble(), required: false)]
#[FPost(new VDouble(), "The group assignment point threshold", required: false)]
Copy link
Member

Choose a reason for hiding this comment

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

A relative number of points a student must receive from assignments to fulfill the requirements of the group.

public ?float $threshold;

#[FPost(new VInt(), required: false)]
#[FPost(new VInt(), "The group points limit", required: false)]
Copy link
Member

Choose a reason for hiding this comment

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

A minimal number of points that a student must receive to fulfill the group's requirements.

public array $bindings;

#[FPost(new VTimestamp(), required: false)]
#[FPost(new VTimestamp(), "The time when the exam starts if there is an exam", required: false)]
Copy link
Member

Choose a reason for hiding this comment

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

....exam scheduled.

public ?int $examBegin;

#[FPost(new VTimestamp(), required: false)]
#[FPost(new VTimestamp(), "The time when the exam ends if there is an exam", required: false)]
Copy link
Member

Choose a reason for hiding this comment

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

...scheduled.

public ?int $examEnd;

#[FPost(new VBool(), required: false)]
#[FPost(new VBool(), "Whether there is a strict exam lock", required: false)]
Copy link
Member

Choose a reason for hiding this comment

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

Whether the scheduled exam requires a strict access lock.

public ?bool $examLockStrict;

#[FPost(new VArray())]
#[FPost(new VArray(), "All group exams")]
Copy link
Member

Choose a reason for hiding this comment

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

All past exams (with at least one student locked).

@krulis-martin krulis-martin merged commit 67df6ca into master Jul 25, 2025
12 checks passed
@krulis-martin krulis-martin deleted the output-formats branch July 25, 2025 13:03
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.

3 participants