Skip to content

fix(docker): emit literal null for string env vars set to "null"#10860

Open
yogeshwaran-c wants to merge 1 commit into
swagger-api:masterfrom
yogeshwaran-c:fix/docker-translator-null-string
Open

fix(docker): emit literal null for string env vars set to "null"#10860
yogeshwaran-c wants to merge 1 commit into
swagger-api:masterfrom
yogeshwaran-c:fix/docker-translator-null-string

Conversation

@yogeshwaran-c
Copy link
Copy Markdown

Description

The Docker entrypoint translator emits the string "null" instead of the JS literal null whenever a string-typed env var is set to null (e.g. VALIDATOR_URL=null). Per docs/usage/configuration.md, null is the documented way to disable the validator badge:

validatorUrl | VALIDATOR_URL | String="https://validator.swagger.io/validator" OR null

Today, running

docker run -d -p 80:8080 -e URL=http://mySwaggerSpec -e VALIDATOR_URL=null swaggerapi/swagger-ui

injects

validatorUrl: "null",

into the swagger-initializer.js, which the validator badge component then treats as a relative URL and renders as a broken link.

This change makes the translator detect the literal string "null" for string-typed config variables and emit the JS null value instead, restoring the documented behaviour. The fix applies to every string-typed config variable (URL, VALIDATOR_URL, OAUTH2_REDIRECT_URL, FILTER, etc.), which matches what the issue reporter and follow-up commenters described.

Motivation and Context

Closes #5519. The bug was acknowledged by a maintainer in the original thread:

Thanks for the report. You indeed discovered a bug in the docker work, as it's likely that NULL is parsed as "NULL", so we'll have to get that fixed.

A follow-up comment confirmed it also breaks URL=null (and any other string variable that allows null), which the present fix addresses.

How Has This Been Tested?

  • npm run test:unit -- test/unit/docker/translator.js — 17 tests pass (15 existing + 2 new).
  • npx eslint --max-warnings 0 docker/configurator/translator.js test/unit/docker/translator.js — clean.
  • Two new regression tests cover both VALIDATOR_URL=null and the more general case (URL=null, FILTER=null).

The translator is build-time configuration code (it edits the dist HTML before nginx serves it), so it does not have a Cypress/browser surface to exercise.

Checklist

  • My change requires a change to the documentation. — No, the existing docs already promise this behaviour.
  • My code follows the code style of this project.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

The Docker entrypoint translator was emitting the string `"null"` for
any string-typed env var assigned the literal value `null` (e.g.
`VALIDATOR_URL=null`). Per docs/usage/configuration.md, `null` is the
documented way to disable the validator badge, but the resulting
`validatorUrl: "null"` was treated as a URL and produced a broken link.

Detect the literal string "null" in the translator and emit the JS
`null` value instead so that the documented behaviour works for any
string-typed config variable (URL, VALIDATOR_URL, FILTER, etc.).

Refs swagger-api#5519
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.

Setting VALIDATOR_URL=null with Docker results in broken link

1 participant