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

Adds support for serialization of csv values for Go enums #3210

Merged
merged 1 commit into from
Aug 31, 2023

Conversation

rkodev
Copy link
Contributor

@rkodev rkodev commented Aug 28, 2023

Resolves microsoftgraph/msgraph-sdk-go#517

Adds support for serialization of csv values for Go enums by adding a value mask that can support multiple Go values

func (i ConditionalAccessGuestOrExternalUserTypes) String() string {
	var data []string
	for p := ConditionalAccessGuestOrExternalUserTypes(1); p <= UNKNOWNFUTUREVALUE_CONDITIONALACCESSGUESTOREXTERNALUSERTYPES; p <<= 1 {
		if i&p == p {
			data = append(data, []string{"none", "internalGuest", "b2bCollaborationGuest", "b2bCollaborationMember", "b2bDirectConnectUser", "otherExternalUser", "serviceProvider", "unknownFutureValue"}[p])
		}
	}
	return strings.Join(data, ",")
}
func ParseConditionalAccessGuestOrExternalUserTypes(v string) (any, error) {
	// detect a command in the string and return enum as mask
	var result ConditionalAccessGuestOrExternalUserTypes
	values := strings.Split(v, ",")
	for _, str := range values {
		switch str {
		case "none":
			result |= NONE_CONDITIONALACCESSGUESTOREXTERNALUSERTYPES
		case "internalGuest":
			result |= INTERNALGUEST_CONDITIONALACCESSGUESTOREXTERNALUSERTYPES
		case "b2bCollaborationGuest":
			result |= B2BCOLLABORATIONGUEST_CONDITIONALACCESSGUESTOREXTERNALUSERTYPES
		case "b2bCollaborationMember":
			result |= B2BCOLLABORATIONMEMBER_CONDITIONALACCESSGUESTOREXTERNALUSERTYPES
		case "b2bDirectConnectUser":
			result |= B2BDIRECTCONNECTUSER_CONDITIONALACCESSGUESTOREXTERNALUSERTYPES
		case "otherExternalUser":
			result |= OTHEREXTERNALUSER_CONDITIONALACCESSGUESTOREXTERNALUSERTYPES
		case "serviceProvider":
			result |= SERVICEPROVIDER_CONDITIONALACCESSGUESTOREXTERNALUSERTYPES
		case "unknownFutureValue":
			result |= UNKNOWNFUTUREVALUE_CONDITIONALACCESSGUESTOREXTERNALUSERTYPES
		default:
			return 0, errors.New("Unknown ConditionalAccessGuestOrExternalUserTypes value: " + v)
		}
	}
	return &result, nil
}

@rkodev rkodev requested a review from a team as a code owner August 28, 2023 12:17
@rkodev rkodev changed the title Adds support for serialization of csv values for Go enuams Adds support for serialization of csv values for Go enums Aug 28, 2023
src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs Outdated Show resolved Hide resolved
src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs Outdated Show resolved Hide resolved
src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs Outdated Show resolved Hide resolved
src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs Outdated Show resolved Hide resolved
src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs Outdated Show resolved Hide resolved
src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs Outdated Show resolved Hide resolved
src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs Outdated Show resolved Hide resolved
src/Kiota.Builder/Writers/Go/CodeEnumWriter.cs Outdated Show resolved Hide resolved
@rkodev rkodev force-pushed the feat/go-enums-add-musks branch from 5d44c0e to e9914cc Compare August 28, 2023 12:37
@baywet
Copy link
Member

baywet commented Aug 28, 2023

@rkodev multiple integration tests are failing, can you have a look please?

@rkodev rkodev force-pushed the feat/go-enums-add-musks branch from 549fa21 to 219bfd4 Compare August 29, 2023 07:28
@rkodev rkodev enabled auto-merge (squash) August 29, 2023 07:46
@rkodev rkodev force-pushed the feat/go-enums-add-musks branch from 95c25d3 to dd29479 Compare August 30, 2023 11:37
@rkodev rkodev force-pushed the feat/go-enums-add-musks branch from dd29479 to 3ffc4ab Compare August 30, 2023 11:40
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Copy link
Member

@andrueastman andrueastman left a comment

Choose a reason for hiding this comment

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

@baywet I'm okay to have this merged as it fits into the general bigger picture of what we'd want to do, and I've documented the conversations/findings at #3237.
@rkodev You can probably assign the related Go SDK issues to me and then I'll close them once the issue is closed (hopefully before the next generation cycle 😅 ).

Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

I'm perfectly fine with merging this one as is and have the work on the flags being implemented later. I know this won't solve the customer issue that's linked right now, but we're making progress towards it. @rkodev maybe unlink the "fixes" before you merge the PR?

@rkodev rkodev merged commit d58a64e into main Aug 31, 2023
@rkodev rkodev deleted the feat/go-enums-add-musks branch August 31, 2023 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error while fetching Conditional Access Policies
3 participants