Playground Link
Package: @typespec/json-schema
Version: 1.11.0
Description
When two TypeSpec models in different @jsonschema namespaces share the same name, the emitter correctly raises a duplicate-id error. However, if @@id augment decorators are used to give them distinct $id values, the error is suppressed — but the $defs key in the bundle still uses the TypeSpec model name, not the @id value. One type silently overwrites the other with no warning.
Steps to reproduce
import "@typespec/json-schema";
using TypeSpec.JsonSchema;
@jsonSchema
namespace StringExpressions {
model Equals { equals: string; }
}
@jsonSchema
namespace IntegerExpressions {
model Equals { equals: integer; }
}
@@id(StringExpressions.Equals, "StringEquals");
@@id(IntegerExpressions.Equals, "IntegerEquals");
Compile with bundleId: "bundle.json". No errors are raised, but $defs
contains only one Equals entry — the other is silently dropped.
Expected behavior
When @@id gives types distinct identities, the $defs key should reflect
those distinct identities (e.g. StringEquals and IntegerEquals),
preventing the collision.
Actual behavior
$defs key is derived from the TypeSpec model name (Equals) regardless of
the @@id value. One type is silently lost. No error or warning.
Note
Without @@id, the duplicate-id error is correctly raised. The problem is
that @@id appears to "fix" the issue but actually just hides it.
Playground Link
Package: @typespec/json-schema
Version: 1.11.0
Description
When two TypeSpec models in different @jsonschema namespaces share the same name, the emitter correctly raises a duplicate-id error. However, if @@id augment decorators are used to give them distinct $id values, the error is suppressed — but the $defs key in the bundle still uses the TypeSpec model name, not the @id value. One type silently overwrites the other with no warning.
Steps to reproduce
Compile with bundleId: "bundle.json". No errors are raised, but $defs
contains only one Equals entry — the other is silently dropped.
Expected behavior
When @@id gives types distinct identities, the $defs key should reflect
those distinct identities (e.g. StringEquals and IntegerEquals),
preventing the collision.
Actual behavior
$defs key is derived from the TypeSpec model name (Equals) regardless of
the @@id value. One type is silently lost. No error or warning.
Note
Without @@id, the duplicate-id error is correctly raised. The problem is
that @@id appears to "fix" the issue but actually just hides it.