Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions scripts/codegen/csharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,41 @@ function failUnmappable(context: string, schema: JSONSchema7): never {
);
}

function omitUntypedInternalProperties(value: unknown): void {
if (!value || typeof value !== "object") return;
if (Array.isArray(value)) {
value.forEach(omitUntypedInternalProperties);
return;
}

const node = value as Record<string, unknown>;
const properties = node.properties;
if (properties && typeof properties === "object" && !Array.isArray(properties)) {
for (const [name, property] of Object.entries(properties)) {
if (!property || typeof property !== "object" || Array.isArray(property)) continue;
const schema = property as JSONSchema7;
const hasType =
schema.type !== undefined ||
schema.$ref !== undefined ||
schema.anyOf !== undefined ||
schema.oneOf !== undefined ||
schema.allOf !== undefined ||
schema.enum !== undefined ||
schema.const !== undefined ||
isOpaqueJson(schema);
if (isSchemaInternal(schema) && !hasType) {
delete (properties as Record<string, unknown>)[name];
} else {
omitUntypedInternalProperties(property);
}
}
}

for (const [name, child] of Object.entries(node)) {
if (name !== "properties") omitUntypedInternalProperties(child);
}
}

function requiresArgumentNullCheck(typeName: string, isRequired: boolean): boolean {
return isRequired && !typeName.endsWith("?") && !isNonNullableCSharpValueType(typeName);
}
Expand Down Expand Up @@ -2568,6 +2603,8 @@ function generateRpcCode(
externalJsonSerializableRefs: Map<string, Set<string>> = new Map(),
externalValueTypes: Set<string> = new Set()
): string {
schema = cloneSchemaForCodegen(schema);
omitUntypedInternalProperties(schema);
emittedRpcClassSchemas.clear();
emittedRpcEnumResultTypes.clear();
experimentalRpcTypes.clear();
Expand Down
Loading