You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d20dd31
Browse filesBrowse the repository at this point in the historyBrowse files
fix(openapi3): warn about a missing server variable default instead of picking one
Keep the empty default when a server variable with enum values has no
default, and report missing-server-variable-default only for OpenAPI
3.1.0 and later, which require the default to be one of the enum values.
Copy file name to clipboardExpand all lines: .chronus/changes/fix-openapi3-server-variable-enum-default-2026-9-19-11-21-11.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,4 +4,4 @@ packages:
4
4
- "@typespec/openapi3"
5
5
---
6
6
7
-
Server variables that have an `enum` but no default now use the first `enum`value as their `default` instead of an empty string, since OpenAPI 3.1 and laterrequire the default to be one of the `enum` values. A server variable typed as the service's versions enum uses the version of each emitted document instead. A new `missing-server-variable-default`warning is reported when that first value is used for a variable with more than one possible value.
7
+
Report a new `missing-server-variable-default` warning when a server variable that has an `enum`has no default and the document is emitted for OpenAPI 3.1.0 or later, since those versions require the default to be one of the `enum` values. The emitted `default`stays an empty string.
Copy file name to clipboardExpand all lines: packages/openapi3/src/diagnostics/missing-server-variable-default.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,17 @@
1
-
This diagnostic is issued when a variable in the `@server` decorator can take more than one value (an enum or a union of string literals) but has no default.
2
-
OpenAPI requires the `default` of a server variable to be one of its `enum` values, so the emitter uses the first value. That value might not be the one you intended.
1
+
This diagnostic is issued when a variable in the `@server` decorator has a fixed set of values (an enum, a union of string literals or a string literal) but no default, and the document is emitted for OpenAPI 3.1.0 or later.
2
+
Those versions require the `default` of a server variable to be one of its `enum` values. The emitter does not pick one for you, so the variable keeps an empty `default` and the document is not valid.
3
3
4
4
To fix this issue, set a default on the server parameter.
default: paramMessage`Server variable '${"propName"}' has no default, so '${"value"}', the first of its values, is used. Set a default on the parameter to choose a different one.`,
344
+
default: paramMessage`Server variable '${"propName"}' has no default, but OpenAPI ${"openapiVersion"} requires its default to be one of its enum values. Set a default on the parameter.`,
message: `Server variable '${name}' has no default, so '${value}', the first of its values, is used. Set a default on the parameter to choose a different one.`,
16
-
});
8
+
// OpenAPI 3.0 only says that a server variable default should be one of its enum values.
message: `Server variable '${name}' has no default, but OpenAPI ${specVersion} requires its default to be one of its enum values. Set a default on the parameter.`,
0 commit comments