Skip to content

Commit 243ca39

Browse files
authored
Skip untyped internal C# RPC properties (#2298)
Remove internal properties without a representable schema shape before C# RPC generation, while preserving typed internal properties and strict failures for public schemas. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 510b87fe-e424-4389-a811-2a4c3a2181ff
1 parent 25c0bea commit 243ca39

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

scripts/codegen/csharp.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,41 @@ function failUnmappable(context: string, schema: JSONSchema7): never {
355355
);
356356
}
357357

358+
function omitUntypedInternalProperties(value: unknown): void {
359+
if (!value || typeof value !== "object") return;
360+
if (Array.isArray(value)) {
361+
value.forEach(omitUntypedInternalProperties);
362+
return;
363+
}
364+
365+
const node = value as Record<string, unknown>;
366+
const properties = node.properties;
367+
if (properties && typeof properties === "object" && !Array.isArray(properties)) {
368+
for (const [name, property] of Object.entries(properties)) {
369+
if (!property || typeof property !== "object" || Array.isArray(property)) continue;
370+
const schema = property as JSONSchema7;
371+
const hasType =
372+
schema.type !== undefined ||
373+
schema.$ref !== undefined ||
374+
schema.anyOf !== undefined ||
375+
schema.oneOf !== undefined ||
376+
schema.allOf !== undefined ||
377+
schema.enum !== undefined ||
378+
schema.const !== undefined ||
379+
isOpaqueJson(schema);
380+
if (isSchemaInternal(schema) && !hasType) {
381+
delete (properties as Record<string, unknown>)[name];
382+
} else {
383+
omitUntypedInternalProperties(property);
384+
}
385+
}
386+
}
387+
388+
for (const [name, child] of Object.entries(node)) {
389+
if (name !== "properties") omitUntypedInternalProperties(child);
390+
}
391+
}
392+
358393
function requiresArgumentNullCheck(typeName: string, isRequired: boolean): boolean {
359394
return isRequired && !typeName.endsWith("?") && !isNonNullableCSharpValueType(typeName);
360395
}
@@ -2568,6 +2603,8 @@ function generateRpcCode(
25682603
externalJsonSerializableRefs: Map<string, Set<string>> = new Map(),
25692604
externalValueTypes: Set<string> = new Set()
25702605
): string {
2606+
schema = cloneSchemaForCodegen(schema);
2607+
omitUntypedInternalProperties(schema);
25712608
emittedRpcClassSchemas.clear();
25722609
emittedRpcEnumResultTypes.clear();
25732610
experimentalRpcTypes.clear();

0 commit comments

Comments
 (0)