Skip to content

feat: add @Metric annotation to simplify metrics OpenAPI metadata - #2871

Open
Vinu2111 wants to merge 1 commit into
TimefoldAI:mainfrom
Vinu2111:feat/metric-annotation
Open

Vinu2111 wants to merge 1 commit into
TimefoldAI:mainfrom
Vinu2111:feat/metric-annotation

Conversation

@Vinu2111

@Vinu2111 Vinu2111 commented Dec 3, 2026

Copy link
Copy Markdown

Fixes #2755

Summary

  • Add ai.timefold.solver.service.definition.api.metrics.Metric with title, description, example, format (defaults to DataFormat.Values.NUMBER), minimum (defaults to "0", "" to omit), and priority (defaults to -1 for 1-based declaration order).
  • Expand @Metric at build time in timefold-solver-service-quarkus-deployment via AddToOpenAPIDefinitionBuildItem (MetricOpenApiFilter) using Jandex metadata (MetricMetadataResolver) without runtime reflection, keeping static build-time OpenAPI specs complete.
  • Update TimefoldModelDescriptorProcessor to read @Metric (while keeping @Schema backward compatibility) into InputMetricDescriptor and OutputMetricDescriptor.
  • Migrate EmployeeScheduleInputMetrics and EmployeeScheduleOutputMetrics in service/test-model and update service/test-model/src/build/openapi.json via -Dupdate-api (inferred integer type and minimum: 0).
  • Update docs/src/modules/ROOT/pages/running-timefold-solver/service/exposing-metrics.adoc with @Metric examples.

Implementation Notes

  • In Quarkus 3.40.1.2, SmallRyeOpenApiProcessor.smallryeOpenApiIndex(...) builds OpenApiFilteredIndexViewBuildItem directly from CombinedIndexBuildItem + BeanArchiveIndexBuildItem, so AddToOpenAPIDefinitionBuildItem is used to apply @Metric expansion at build time without runtime reflection.
  • Uses OpenAPI example (singular) because quarkus.smallrye-openapi.open-api-version is locked to 3.0.3.

Tests

  • Added MetricAnnotationOpenApiTest (Quarkus extension test verifying OpenAPI output and timefold-model-descriptor.json for records, classes, methods, declaration-order priority, explicit priority, minimum omission, Duration, and @Schema fallback).
  • Added MetricOpenApiFilterTest (unit tests for invalid minimum, missing schema targets, example parsing, and @JsonProperty / @Schema(name) property resolution).
  • Extended OpenApiTest in service/test-model.
  • Verified locally with ./mvnw -pl service/definition,service/quarkus/deployment install, ./mvnw -pl service/quarkus/integration-tests verify, ./mvnw -B verify --file service/test-model/pom.xml, and ./mvnw -pl docs generate-resources -Dfull.

@Vinu2111
Vinu2111 requested a review from a team December 3, 2026 15:10

This branch has not been deployed

No deployments
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.

SDK: Simplify OpenAPI Spec annotations

1 participant