Generating a SKY SDK for .NET

Sharing here in case it's useful to anyone. This is my process for generating a .NET SDK for the SKY API. It outputs classes representing the endpoints and models in the OpenAPI spec available on developer.sky.blackbaud.com.

Steps:

  • Download and install the Chocolatey package manager for Windows
  • Install NSwag by running this in a shell:

    choco install NSwagStudio -y

  • Go to https://developer.sky.blackbaud.com/api#api=school
  • Click the API definition dropdown
  • Click Open API 3 (JSON)
  • Save the downloaded file as swagger.json in a directory
  • To customize your namespace and create a base class where you can customize things like obtaining a new refresh token, create a file in the same directory called nswag.json. For example:

    {
    "runtime": "WinX64",
    "documentGenerator": {
    "fromDocument": {
    "json": "swagger.json"
    }
    },
    "codeGenerators": {
    "openApiToCSharpClient": {
    "namespace": "Your.Namespace.Here",
    "output": "SkyApiClient.g.cs",
    "clientBaseClass": "SkyApiClientBase",
    "configurationClass": "SkyApiConfiguration",
    "generateClientInterfaces": true,
    "useHttpRequestMessageCreationMethod": true,
    "jsonLibrary": "SystemTextJson"
    }
    }
    }
  • In your shell, run:

    nswag run

Note: The generated classes don't handle refresh tokens out of the box IIRC. I ended up writing custom refresh token logic in SkyApiClientBase (fetch from DB, detect expiration, refresh if expiring soon).