Repository navigation
fix(backstage-plugin-dql-backend): apply environments array type to both auth variants - #432
Open
MatheusMartinho wants to merge 1 commit into
Open
MatheusMartinho wants to merge 1 commit into
MatheusMartinho wants to merge 1 commit into
Conversation
…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
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduction
Fixes #331.
The TypeScript union type for
environmentsinplugins/dql-backend/config.d.tshad incorrect operator precedence, causing Backstage's config schema compiler to generate anobjecttype instead of anarraytype fordynatrace.environments. As a result, Backstage failed to start withConfig validation failed, Config must be object { type=object } at /dynatrace/environmentswhen using the array format documented in the README.Technical solution before this PR
The type was declared as:
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:
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:Against the previous
config.d.tsthese tests fail, reproducing the error reported in #331; with this change they pass. Full plugin test suite (yarn testinplugins/dql-backend): 68 tests passing.✔️ Common checklist
Helpful resources: TypeScript operator precedence for union and array types, introduced in #257.