Skip to content

fix(backstage-plugin-dql-backend): apply environments array type to both auth variants - #432

Open
MatheusMartinho wants to merge 1 commit into
Dynatrace:mainfrom
MatheusMartinho:fix/environments-array-config-schema
Open

MatheusMartinho wants to merge 1 commit into
Dynatrace:mainfrom
MatheusMartinho:fix/environments-array-config-schema

Conversation

@MatheusMartinho

Copy link
Copy Markdown

Introduction

Fixes #331.

The TypeScript union type for environments in plugins/dql-backend/config.d.ts had incorrect operator precedence, causing Backstage's config schema compiler to generate an object type instead of an array type for dynatrace.environments. As a result, Backstage failed to start with Config validation failed, Config must be object { type=object } at /dynatrace/environments when using the array format documented in the README.

Technical solution before this PR

The type was declared as:

environments: { /* OAuth variant */ } | { /* platform token variant */ }[]

Due to TypeScript operator precedence this is parsed as OAuthConfig | (TokenConfig[]) — a union of a single OAuth object or an array of token configs. The config schema compiler resolved this to { "type": "object" }, so the documented array format was rejected at startup (and, conversely, a single OAuth object was incorrectly accepted).

Technical solution after this PR

The union is wrapped in parentheses so the array applies to both variants:

environments: ({ /* OAuth variant */ } | { /* platform token variant */ })[]

The compiled schema is now unambiguously an array of either environment variant, matching the documented config format and the runtime behavior of parseEnvironments.

A regression test (plugins/dql-backend/src/configSchema.test.ts) compiles the package's config schema with @backstage/config-loader (added as a devDependency; it was already present in the lockfile transitively) and verifies that:

  • a list of OAuth environments is accepted
  • a list of platform token environments is accepted
  • a list mixing both variants is accepted
  • a single (non-array) environment object is rejected

Against the previous config.d.ts these tests fail, reproducing the error reported in #331; with this change they pass. Full plugin test suite (yarn test in plugins/dql-backend): 68 tests passing.

✔️ Common checklist

  • Added tests for new functionality and regression tests for bug fixes
  • Screenshots of before and after attached (for UI changes) — n/a, no UI changes
  • Added or updated documentation (if applicable) — n/a, the README already documents the array format this fix restores
  • Helpful resources linked (if applicable)

Helpful resources: TypeScript operator precedence for union and array types, introduced in #257.

…oth auth variants

Due to TypeScript operator precedence, the environments config type was
parsed as OAuthConfig | TokenConfig[] instead of an array of either
variant. The config schema compiler therefore generated an object type
for dynatrace.environments, rejecting the documented array format at
startup with "Config must be object".

Wrap the union in parentheses so the compiled schema accepts an array
of both environment variants, and add a regression test that compiles
the package config schema and validates the documented config formats.

Fixes Dynatrace#331
@MatheusMartinho
MatheusMartinho requested a review from a team as a code owner August 14, 2026 16:34
@MatheusMartinho

Copy link
Copy Markdown
Author

Gentle ping whenever someone from @Dynatrace/backstage-plugin-maintainers has a moment. This fixes #331: with the array format documented in the README, Backstage fails to start with Config must be object at /dynatrace/environments, because of the operator precedence in the environments union in plugins/dql-backend/config.d.ts. Happy to rebase or adjust anything.

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.

config.d.ts union type precedence bug causes config validation failure for dynatrace.environments

1 participant