Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum support for OpenAPI and Looker spec enum types #241

Merged
merged 20 commits into from
Jun 23, 2020
Merged

Conversation

jkaster
Copy link
Contributor

@jkaster jkaster commented Jun 21, 2020

Counting on enums

This PR generates enums for all 5 language SDKs. If a parameter, property, or type has an x-looker-values or enum value list declaration, a corresponding enum type is created. Previously, parameters or properties that were usually typed as string are now an enum type.

Examples

C#

public enum PermissionType
{
  [EnumMember(Value = "view")]
  view,
  [EnumMember(Value = "edit")]
  edit
}

Kotlin

enum class PermissionType : Serializable {
  view,
  edit
}

Python

class PermissionType(enum.Enum):
    view = "view"
    edit = "edit"

Swift

enum PermissionType: String, Codable {
    case view = "view"
    case edit = "edit"
}

Typescript

export enum PermissionType {
  view = 'view',
  edit = 'edit',
}

TODO - Python unit test

The Python SDK still needs an enum property serialization/deserialization test. All other SDKs have at least one working test.

BONUS: C# generator optimization

This PR also optimizes C# method generation so generic type specifiers are only required for responses that take more than one type.

yarn sdk c#

or

yarn sdk csharp

will generate the C# SDK code. C# is also generated with all other languages if a language specifier isn't included.

jkaster added 17 commits June 3, 2020 15:38
- enum detection is written, need to verify tests w/ canary upgrade
Still lots to do, things are definitely broken for the generators right now
Lots of linty freshness

Much more to go
- replacing `x-looker-values` with `enum` in converted OA spec
- putting license statement into generated files using the `LICENSE` file contents in the package folder
- made `commentHeader` a little smarter
- All languages have enum types now
- Kotlin, Typescript, and Swift are not broken with this enum implementation, but enum-specific tests need to be written
- Python isn't happy. More investigation required.

Do not ship any SDK using the code generated by this branch!
- merged master that has api-explorer package
- yarn build works
- tests work in intellij
- testUtils is not in package builds
The generated C# code is the best looking of all our generated code now. It optimizes method interfaces and has excellent documentation.

It helps that C# has a clear documentation standard, but we can take advantage of some of the new methodologies it has for the other generators. Particularly Kotlin and Swift can be made much cleaner.

Added unit test for C# enum support also. More method unit tests are still required, but Look# is moving along nicely.

There's also an alias `c#` for `csharp` so both:

```sh
yarn sdk csharp
```

and

```sh
yarn sdk c#
```

work (language match is case-insensitive)
@jkaster jkaster added enhancement New feature request swift Swift SDK issues kotlin Kotlin SDK issues typescript Typescript or Javascript SDK issues python Python SDK issues c# C# SDK issues labels Jun 21, 2020
Copy link
Contributor

@joeldodge79 joeldodge79 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work! I have a few haphazard comments on the code-gen stuff (nothing blocking approval) but the python needs some tweaks to be functional. Once you have the python formatter fixed it would be good to have an additional integration/smoke test that verifies [de]serialization works in python for these new enums

@@ -132,6 +135,7 @@ class ${this.packageName}(api_methods.APIMethods):
# ${this.warnEditing()}
import datetime
from typing import Any, MutableMapping, Optional, Sequence
import enum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's sandwich this between datetime and typing - I don't think black alphabetizes imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this and pushed the change, but for some reason Github is refusing to update the status of this comment. 😖

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also put

import attr

first, but GitHub is absolutely refusing to show the code updates

jkaster added 2 commits June 22, 2020 10:07
- We need to turn off that sort-keys linting rule everywhere. It doesn't want to go away.
- Cleaned up sdkModels tests based on PR feedback
- regenerated all SDK language source with right trimmed comment headers
- A forwardref for enum types may still be required for Python?
Copy link
Contributor

@josephaxisa josephaxisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We synced offline but I started a draft PR (#242) that addresses the Python side of this PR and Joel will be continuing it in the meantime.

@jkaster jkaster merged commit 5eef1d2 into master Jun 23, 2020
@jkaster jkaster deleted the jk/enums branch June 23, 2020 19:28
This was referenced Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c# C# SDK issues enhancement New feature request kotlin Kotlin SDK issues python Python SDK issues swift Swift SDK issues typescript Typescript or Javascript SDK issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants