Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
fix: only remove OpenAPI discriminator objects, not user properties named 'discriminator'
jkomyno committed
Jan 15, 2026 at 01:14 UTC
b4454f00d787d98b9226e00253036fa18257d7d4
1 file changed
+22
-3
ts/packages/cli/src/generation/typescript/generate-type-from-json-schema.ts
+22
-3
@@ -148,11 +148,15 @@ function isInterfaceComponents(node: ts.Node): node is ts.InterfaceDeclaration {
148
}
149
150
/**
151
- * Recursively removes `discriminator` objects from a JSON schema.
151
+ * Recursively removes OpenAPI `discriminator` objects from a JSON schema.
152
* This is needed because Composio's API returns schemas with discriminator.mapping
153
* that reference #/$defs/... paths, but the types are inlined in oneOf/anyOf arrays
154
* rather than defined in a $defs section. openapi-typescript fails to resolve these refs.
155
* Since oneOf/anyOf work fine without discriminator, we simply remove it.
156
+ *
157
+ * IMPORTANT: We only remove `discriminator` keys when the value is an actual OpenAPI
158
+ * discriminator object (identified by having a `propertyName` field per the OpenAPI spec).
159
+ * This avoids accidentally stripping user-defined properties that happen to be named "discriminator".
160
*/
161
function removeDiscriminators(obj: unknown): unknown {
162
if (obj === null || typeof obj !== 'object') {
@@ -165,11 +169,26 @@ function removeDiscriminators(obj: unknown): unknown {
169
170
const result: Record<string, unknown> = {};
171
for (const [key, value] of Object.entries(obj)) {
168
- if (key === 'discriminator') {
169
- // Skip discriminator objects entirely
172
+ if (key === 'discriminator' && isOpenApiDiscriminator(value)) {
173
+ // Skip OpenAPI discriminator objects (must have `propertyName` per spec)
174
continue;
175
}
176
result[key] = removeDiscriminators(value);
177
}
178
return result;
179
}
180
+
181
+/**
182
+ * Checks if a value is an OpenAPI discriminator object.
183
+ * Per the OpenAPI 3.0/3.1 spec, a discriminator object MUST have a `propertyName` field.
184
+ * @see https://spec.openapis.org/oas/v3.1.0#discriminator-object
185
+ */
186
+function isOpenApiDiscriminator(value: unknown): boolean {
187
+ return (
188
+ value !== null &&
189
+ typeof value === 'object' &&
190
+ !Array.isArray(value) &&
191
+ 'propertyName' in value &&
192
+ typeof (value as Record<string, unknown>)['propertyName'] === 'string'
193
+ );
194
+}