Skip to content

feat(gooddata-sdk): [AUTO] Add WidgetDescriptor, DashboardContext, UIContext schemas; extend UserContext#1558

Closed
yenkins-admin wants to merge 1 commit intomasterfrom
auto/openapi-sync-C007-20260419-r49222
Closed

feat(gooddata-sdk): [AUTO] Add WidgetDescriptor, DashboardContext, UIContext schemas; extend UserContext#1558
yenkins-admin wants to merge 1 commit intomasterfrom
auto/openapi-sync-C007-20260419-r49222

Conversation

@yenkins-admin
Copy link
Copy Markdown
Contributor

Summary

Added SDK wrapper models for WidgetDescriptor, DashboardContext, UIContext, ObjectReference, ObjectReferenceGroup, and the extended UserContext (with referencedObjects and view). Updated ai_chat/ai_chat_stream to accept optional CatalogUserContext. Exported all new classes from init.py. Unit tests added for all new model serialization paths.

Impact: new_feature | Services: gooddata-afm-client
Tickets: LX-2141

Files changed

  • packages/gooddata-sdk/src/gooddata_sdk/compute/model/user_context.py
  • packages/gooddata-sdk/src/gooddata_sdk/compute/service.py
  • packages/gooddata-sdk/src/gooddata_sdk/__init__.py
  • packages/gooddata-sdk/tests/compute/test_user_context.py

Agent decisions

Decisions (5)

model location — Placed all new models in packages/gooddata-sdk/src/gooddata_sdk/compute/model/user_context.py

  • Alternatives: Place under catalog/workspace/ (AI context is request-time, not catalog/entity), Place under catalog/organization/ alongside llm_provider.py
  • Why: UserContext is a ChatRequest input model consumed by ComputeService. Co-locating with compute/model/ keeps it alongside the execution-model classes it is used with.

widget descriptor polymorphism — Three independent @attrs.define classes unified via Union TypeAlias CatalogWidgetDescriptor

  • Alternatives: Single base class with attrs inheritance (fragile field ordering), Single flat class with widget_type discriminator
  • Why: Follows existing llm_provider.py Union-alias pattern (CatalogLlmProviderConfig). Avoids attrs inheritance field-ordering pitfalls.

Union alias import style — from typing import Union used for the CatalogWidgetDescriptor alias

  • Alternatives: X | Y | Z runtime syntax (requires Python 3.10+)
  • Why: Module-level | alias fails Python 3.9; Union matches existing llm_provider.py convention.

as_api_model() vs Base.to_api() — Explicit as_api_model() on each model without extending Base

  • Alternatives: Extend Base and use to_api() via cattrs
  • Why: These are write-only request models, never deserialized from API. Explicit as_api_model() is simpler and handles polymorphic WidgetDescriptor subtypes cleanly.

referenced_objects omission when empty — Omit referenced_objects from UserContext API model when list is empty

  • Alternatives: Always pass empty list
  • Why: Consistent with how active_object and view are gated. An empty list is semantically equivalent to omission.
Assumptions to verify (3)
  • DashboardContext.widgets accepts InsightWidgetDescriptor/RichText/VisualizationSwitcher subtypes with _check_type=False because JSON serialization is type-agnostic.
  • Pre-existing ty check errors in compute/model/filter.py (EmptyValueHandling invalid-return-type) are unrelated to this change.
  • unresolved-import: pytest ty errors in test files are an environment-level issue pre-existing across the whole test suite.
Risks (1)
  • If the backend strictly validates widgetType values, callers must use the exact discriminator values ('insight', 'richText', 'visualizationSwitcher') as shown in the OpenAPI mapping — the SDK wrapper exposes raw string fields and does not enforce these.
Layers touched (3)
  • entity_model — New compute request-model classes: CatalogActiveObjectIdentification, CatalogObjectReference, CatalogObjectReferenceGroup, CatalogInsightWidgetDescriptor, CatalogRichTextWidgetDescriptor, CatalogVisualizationSwitcherWidgetDescriptor, CatalogDashboardContext, CatalogUIContext, CatalogUserContext
    • packages/gooddata-sdk/src/gooddata_sdk/compute/model/user_context.py
  • public_api — Exported 10 new classes; added user_context parameter to ai_chat and ai_chat_stream
    • packages/gooddata-sdk/src/gooddata_sdk/__init__.py
    • packages/gooddata-sdk/src/gooddata_sdk/compute/service.py
  • tests — Unit tests covering as_api_model() for all new model classes
    • packages/gooddata-sdk/tests/compute/test_user_context.py

Source commits (gdc-nas)

  • 3f2b607 Merge pull request #21274 from gooddata/smac/LX-2141
  • 63dd6bf feat(gen-ai): refactor widgets polymorphism and enhance OpenAPI spec
  • 075d22d Merge pull request #21389 from gooddata/dho/trivial-fix
OpenAPI diff
diff --git a/microservices/afm-exec-api/src/test/resources/openapi/open-api-spec.json
@@ Added schemas: DashboardContext, InsightWidgetDescriptor, RichTextWidgetDescriptor, VisualizationSwitcherWidgetDescriptor, WidgetDescriptor (discriminator), ObjectReference, ObjectReferenceGroup, UIContext @@
+      "DashboardContext" : {
+        "description" : "Dashboard the user is currently viewing.",
+        "properties" : {
+          "id" : { "description" : "Dashboard object ID.", "type" : "string" },
+          "widgets" : { "description" : "Widgets currently visible on the dashboard.", "$ref" : "#/components/schemas/WidgetDescriptor" }
+        },
+        "required" : [ "id", "widgets" ],
+        "type" : "object"
+      },
+      "WidgetDescriptor" : {
+        "description" : "Descriptor for a widget on the dashboard.",
+        "discriminator" : {
+          "mapping" : { "insight" : "#/components/schemas/InsightWidgetDescriptor", "richText" : "#/components/schemas/RichTextWidgetDescriptor", "visualizationSwitcher" : "#/components/schemas/VisualizationSwitcherWidgetDescriptor" },
+          "propertyName" : "widgetType"
+        },
+        "properties" : { "title" : { "type" : "string" }, "widgetId" : { "type" : "string" }, "widgetType" : { "type" : "string" } },
+        "type" : "object"
+      },
+      "InsightWidgetDescriptor" : { "description" : "Insight widget.", "properties" : { "resultId" : ..., "title" : ..., "visualizationId" : ..., "widgetId" : ... }, "required" : [ "title", "visualizationId", "widgetId" ], "type" : "object" },
+      "RichTextWidgetDescriptor" : { "description" : "Rich text widget.", "properties" : { "title" : ..., "widgetId" : ... }, "required" : [ "title", "widgetId" ], "type" : "object" },
+      "VisualizationSwitcherWidgetDescriptor" : { "description" : "Visualization switcher widget.", "required" : [ "activeVisualizationId", "title", "visualizationIds", "widgetId" ], "type" : "object" },
+      "ObjectReference" : { "properties" : { "id" : ..., "type" : { "enum" : [ "WIDGET", "METRIC", "ATTRIBUTE", "DASHBOARD" ] } }, "required" : [ "id", "type" ], "type" : "object" },
+      "ObjectReferenceGroup" : { "properties" : { "context" : { "$ref" : "#/components/schemas/ObjectReference" }, "objects" : { "items" : { "$ref" : "#/components/schemas/ObjectReference" } } }, "required" : [ "objects" ], "type" : "object" },
+      "UIContext" : { "description" : "Ambient UI state.", "properties" : { "dashboard" : { "$ref" : "#/components/schemas/DashboardContext" } }, "type" : "object" },
@@ UserContext extended (required removed by 075d22d5) @@
       "UserContext" : {
-        "description" : "User context, which can affect the behavior of the underlying AI features.",
+        "description" : "User context with ambient UI state (view) and explicitly referenced objects.",
         "properties" : {
           "activeObject" : { "$ref" : "#/components/schemas/ActiveObjectIdentification" },
+          "referencedObjects" : { "description" : "Groups of explicitly referenced objects.", "items" : { "$ref" : "#/components/schemas/ObjectReferenceGroup" }, "type" : "array" },
+          "view" : { "$ref" : "#/components/schemas/UIContext" }
         },
-        "required" : [ "activeObject" ],
         "type" : "object"
       },

Workflow run


Generated by SDK OpenAPI Sync workflow

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 19, 2026

Codecov Report

❌ Patch coverage is 92.30769% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.76%. Comparing base (37d0593) to head (b004a3f).

Files with missing lines Patch % Lines
...s/gooddata-sdk/src/gooddata_sdk/compute/service.py 27.27% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1558      +/-   ##
==========================================
+ Coverage   78.66%   78.76%   +0.09%     
==========================================
  Files         230      231       +1     
  Lines       15405    15505     +100     
==========================================
+ Hits        12118    12212      +94     
- Misses       3287     3293       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tychtjan tychtjan closed this Apr 20, 2026
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