Skip to content

Add C# language support to the Facebook Business SDK Codegen#128

Open
BranislavMateas wants to merge 2 commits intofacebook:mainfrom
BranislavMateas:main
Open

Add C# language support to the Facebook Business SDK Codegen#128
BranislavMateas wants to merge 2 commits intofacebook:mainfrom
BranislavMateas:main

Conversation

@BranislavMateas
Copy link
Copy Markdown

Checklist

Pull Request Details

This PR adds C# language support to the Facebook Business SDK Codegen, enabling automatic generation of the C# SDK for the Facebook Marketing API.

Changes

New C# Language Support

  • CodeGenLanguageCs.js: Language processor with C# type mappings and code generation logic
  • C# Templates (templates/csharp/):
    • codegen.mustache: Main template for API object classes
    • APIContext.cs.versioned.mustache: API context configuration with template variables
    • APINode.cs.versioned.mustache: Base class for API resources
    • APIRequest.cs.versioned.mustache: HTTP request handling with proper error handling
    • APIConfig.cs.versioned.mustache: Configuration constants
    • FacebookBusinessSDK.csproj.mustache: .NET project file

Configuration Updates

  • api_specs/version_path.json: Added C# version detection
  • src/common/Utils.js: Added 'csharp' to supported languages
  • src/processors/CodeGenLanguages.js: Registered C# processor
  • README.md: Updated to reflect 6 language support

Critical Bug Fix

  • SpecOverridingProcessor.js: Fixed jsonpath-plus v10.3.0 breaking change
    • This fix unblocks code generation for ALL languages (Java, Python, Node.js, Ruby, PHP)

API Request Improvements

  • Added explicit PUT HTTP method handling (was incorrectly defaulting to GET)
  • Added JsonException catching for deserialization errors
  • Consistent exception handling through APIException wrapper

Source Code Restoration

  • Restored src/ directory for language extensibility
  • All source files rebuilt to lib/ via npm run build

At the same time, the build is present here - https://github.com/BranislavMateas/facebook-business-sdk-dotnet

Test Plan

Test Plan

1. Codegen Execution

  • Run npm install && npm run build successfully
  • Execute node lib/CodeGenerator.js csharp generates 952 C# classes without errors
  • All files generated in correct structure: src/Meta/Ads/SDK/

2. Generated Code Validation

  • APIContext.cs uses dynamic {{api_version}} template variable
  • APIConfig.cs contains correct API version, base URLs, and user agent
  • APIRequest.cs properly handles GET, POST, PUT, and DELETE methods
  • Exception handling catches HttpRequestException and JsonException
  • Generated code follows C# naming conventions

3. Configuration Verification

  • api_specs/version_path.json has csharp entry pointing to correct version file
  • src/common/Utils.js includes 'csharp' in supported languages
  • src/processors/CodeGenLanguages.js registers C# processor
  • Version detection reads from FacebookBusinessSDK.csproj

4. Bug Fix Verification

  • jsonpath-plus v10.3.0 fix works (SpecOverridingProcessor.js uses new API)
  • All languages still generate without errors: Java, Python, Node.js, Ruby, PHP

5. Generated SDK Repository

@meta-cla meta-cla bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant