google-api-swift-client icon indicating copy to clipboard operation
google-api-swift-client copied to clipboard

Enhance code generation to support enum definitions in the "schemas" section of JSON

Open tjerwinchen opened this issue 9 months ago • 2 comments

This commit introduces the ability to define enums in the "schemas" section of a JSON file. The code now has the capability to properly parse and handle enum definitions.

Example, we define a Role as an enum

"schemas": {
  ……
  "Role": {
      "id": "Role",
      "type": "string",
      "default": "HARM_CATEGORY_UNSPECIFIED",
      "enum": [
        "user",
        "assistant",
        "function"
      ],
      "enumDescriptions": [
        "User",
        "Chat Assistant",
        "Func"
      ]
    },
    ……
}

The generated code:

    public enum Role: String, Codable, CaseIterable {
        case user // User
        case assistant // Chat Assistant
        case function // Func
    }

tjerwinchen avatar Oct 21 '23 05:10 tjerwinchen

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Oct 21 '23 05:10 google-cla[bot]

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot https://conventionalcommits.org/