-
Notifications
You must be signed in to change notification settings - Fork 60
[Repo Assist] feat: generate CLI enum types for top-level named enum schemas #409
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
Merged
sergey-tihon
merged 10 commits into
master
from
repo-assist/feat-cli-enum-types-20260427-57faed9678d0f999
Apr 28, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c209736
feat: generate CLI enum types for top-level named enum schemas
github-actions[bot] 3f2cd6a
ci: trigger checks
github-actions[bot] a895848
fix: update provider tests to use WebAPI.UriKind enum type instead ofβ¦
Copilot 5318b60
feat: add Priority enum (4 cases) provider tests and fix enum array qβ¦
Copilot 672a8f6
fix: address inline review comments on enum generation
Copilot c04afbc
fix: remove redundant registerNew call in named-enum branch
Copilot 893d284
merge: resolve conflict with master's toParam GetType() refactoring
Copilot 111b134
fix: use JsonStringEnumMemberName instead of JsonPropertyName for enuβ¦
Copilot 6d2ec94
review: use typeof<JsonStringEnumMemberNameAttribute> directly in tesβ¦
Copilot 317dfc9
Update src/SwaggerProvider.Runtime/RuntimeHelpers.fs
sergey-tihon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/SwaggerProvider.ProviderTests/Schemas/enum-types.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| openapi: "3.0.0" | ||
| info: | ||
| title: Enum Types Test API | ||
| version: "1.0.0" | ||
| paths: | ||
| /string-status: | ||
| get: | ||
| operationId: getStringStatus | ||
| responses: | ||
| "200": | ||
| description: Returns a string enum value | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/StringStatus" | ||
| /int-status: | ||
| get: | ||
| operationId: getIntStatus | ||
| responses: | ||
| "200": | ||
| description: Returns an integer enum value | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/IntStatus" | ||
| /large-code: | ||
| get: | ||
| operationId: getLargeCode | ||
| responses: | ||
| "200": | ||
| description: Returns an int64 enum value | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/LargeCode" | ||
| components: | ||
| schemas: | ||
| StringStatus: | ||
| type: string | ||
| enum: | ||
| - active | ||
| - in-active | ||
| - pending | ||
| IntStatus: | ||
| type: integer | ||
| enum: | ||
| - 200 | ||
| - 404 | ||
| - 500 | ||
| LargeCode: | ||
| type: integer | ||
| format: int64 | ||
| enum: | ||
| - 1 | ||
| - 2 | ||
| - 3 |
71 changes: 71 additions & 0 deletions
71
tests/SwaggerProvider.ProviderTests/Swagger.EnumTypes.Tests.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| module Swagger.EnumTypes.Tests | ||
|
|
||
| open Xunit | ||
| open FsUnitTyped | ||
| open SwaggerProvider | ||
|
|
||
| [<Literal>] | ||
| let Schema = __SOURCE_DIRECTORY__ + "/Schemas/enum-types.yaml" | ||
|
|
||
| type EnumApi = OpenApiClientProvider<Schema, SsrfProtection=false> | ||
|
|
||
| // ββ String enum ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | ||
|
|
||
| [<Fact>] | ||
| let ``string enum is a CLI enum type``() = | ||
| typeof<EnumApi.StringStatus>.IsEnum |> shouldEqual true | ||
|
|
||
| [<Fact>] | ||
| let ``string enum has int32 underlying type``() = | ||
| System.Enum.GetUnderlyingType typeof<EnumApi.StringStatus> | ||
| |> shouldEqual typeof<int32> | ||
|
|
||
| [<Fact>] | ||
| let ``string enum member names are sanitised from OpenAPI values``() = | ||
| System.Enum.GetNames typeof<EnumApi.StringStatus> | ||
| |> Array.sort | ||
| |> shouldEqual [| "Active"; "InActive"; "Pending" |] | ||
|
|
||
| // Compile-time assertion: sanitised member names are accessible as enum cases. | ||
| [<Fact>] | ||
| let ``string enum members are accessible as typed enum cases``() = | ||
| let active: EnumApi.StringStatus = EnumApi.StringStatus.Active | ||
| let inActive: EnumApi.StringStatus = EnumApi.StringStatus.InActive | ||
| let pending: EnumApi.StringStatus = EnumApi.StringStatus.Pending | ||
| active |> shouldEqual EnumApi.StringStatus.Active | ||
| inActive |> shouldEqual EnumApi.StringStatus.InActive | ||
| pending |> shouldEqual EnumApi.StringStatus.Pending | ||
|
|
||
| // ββ Integer (int32) enum βββββββββββββββββββββββββββββββββββββββββββββββββββ | ||
|
|
||
| [<Fact>] | ||
| let ``int32 enum is a CLI enum type``() = | ||
| typeof<EnumApi.IntStatus>.IsEnum |> shouldEqual true | ||
|
|
||
| [<Fact>] | ||
| let ``int32 enum has int32 underlying type``() = | ||
| System.Enum.GetUnderlyingType typeof<EnumApi.IntStatus> | ||
| |> shouldEqual typeof<int32> | ||
|
|
||
| [<Fact>] | ||
| let ``int32 enum has correct integer values``() = | ||
| int EnumApi.IntStatus.V200 |> shouldEqual 200 | ||
| int EnumApi.IntStatus.V404 |> shouldEqual 404 | ||
| int EnumApi.IntStatus.V500 |> shouldEqual 500 | ||
|
|
||
| // ββ Integer (int64) enum βββββββββββββββββββββββββββββββββββββββββββββββββββ | ||
|
|
||
| [<Fact>] | ||
| let ``int64 enum is a CLI enum type``() = | ||
| typeof<EnumApi.LargeCode>.IsEnum |> shouldEqual true | ||
|
|
||
| [<Fact>] | ||
| let ``int64 enum has int64 underlying type``() = | ||
| System.Enum.GetUnderlyingType typeof<EnumApi.LargeCode> | ||
| |> shouldEqual typeof<int64> | ||
|
|
||
| [<Fact>] | ||
| let ``int64 enum has correct integer values``() = | ||
| int64 EnumApi.LargeCode.V1 |> shouldEqual 1L | ||
| int64 EnumApi.LargeCode.V2 |> shouldEqual 2L | ||
| int64 EnumApi.LargeCode.V3 |> shouldEqual 3L |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.