(
graph: List[Tuple[Path, Schema]], grpc: bool = False
)
| 212 | |
| 213 | |
| 214 | def validate_csharp_generation( |
| 215 | graph: List[Tuple[Path, Schema]], grpc: bool = False |
| 216 | ) -> bool: |
| 217 | output_owners: Dict[str, List[str]] = {} |
| 218 | module_owners: Dict[Tuple[str, str], List[str]] = {} |
| 219 | symbol_owners: Dict[Tuple[str, str], List[str]] = {} |
| 220 | for path, schema in graph: |
| 221 | for output_path, owner in csharp_output_paths(schema, include_services=grpc): |
| 222 | output_owners.setdefault(output_path, []).append(f"{path} {owner}") |
| 223 | namespace_name = csharp_namespace_for_schema(schema) |
| 224 | module_name = csharp_module_class_name(schema) |
| 225 | module_owners.setdefault((namespace_name, module_name), []).append(str(path)) |
| 226 | for symbol_name, owner in csharp_top_level_symbols( |
| 227 | schema, include_services=grpc |
| 228 | ): |
| 229 | symbol_owners.setdefault((namespace_name, symbol_name), []).append( |
| 230 | f"{path} {owner}" |
| 231 | ) |
| 232 | |
| 233 | output_collisions = { |
| 234 | output_path: owners |
| 235 | for output_path, owners in output_owners.items() |
| 236 | if len(owners) > 1 |
| 237 | } |
| 238 | if output_collisions: |
| 239 | details = ", ".join( |
| 240 | f"{output_path}: {', '.join(owners)}" |
| 241 | for output_path, owners in sorted(output_collisions.items()) |
| 242 | ) |
| 243 | raise ValueError( |
| 244 | "C# generated file path collision; rename schema files or services, " |
| 245 | f"or use distinct C# namespaces. Collisions: {details}" |
| 246 | ) |
| 247 | |
| 248 | module_collisions = { |
| 249 | owner: paths for owner, paths in module_owners.items() if len(paths) > 1 |
| 250 | } |
| 251 | if module_collisions: |
| 252 | details = ", ".join( |
| 253 | f"{namespace_name}.{module_name}: {', '.join(paths)}" |
| 254 | for (namespace_name, module_name), paths in sorted( |
| 255 | module_collisions.items() |
| 256 | ) |
| 257 | ) |
| 258 | raise ValueError( |
| 259 | "C# schema module owner collision; rename schema files or use " |
| 260 | f"distinct C# namespaces. Collisions: {details}" |
| 261 | ) |
| 262 | symbol_collisions = { |
| 263 | owner: paths for owner, paths in symbol_owners.items() if len(paths) > 1 |
| 264 | } |
| 265 | if symbol_collisions: |
| 266 | details = ", ".join( |
| 267 | f"{namespace_name}.{symbol_name}: {', '.join(paths)}" |
| 268 | for (namespace_name, symbol_name), paths in sorted( |
| 269 | symbol_collisions.items() |
| 270 | ) |
| 271 | ) |
no test coverage detected