-
Notifications
You must be signed in to change notification settings - Fork 42
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
[Internal] Added Service.NamedIdMap #1016
Merged
Merged
Changes from all commits
Commits
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 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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -99,9 +99,38 @@ func (svc *Service) Methods() (methods []*Method) { | |||||||
return methods | ||||||||
} | ||||||||
|
||||||||
// NamedIdMap allows to retrieve a special NamedIdMap object from all methods | ||||||||
// in the service which returns name-to-id mapping retrieval definition for all | ||||||||
// entities of a type | ||||||||
// If there are multiple NamedIdMap for the service, it will panic, because this is not allowed. | ||||||||
func (svc *Service) NamedIdMap() *NamedIdMap { | ||||||||
entities := make([]*NamedIdMap, 0) | ||||||||
for _, v := range svc.Methods() { | ||||||||
// NamedIdMap is defined only for list operations | ||||||||
if v.Operation.Crud != "list" { | ||||||||
continue | ||||||||
} | ||||||||
|
||||||||
n := v.NamedIdMap() | ||||||||
if n != nil { | ||||||||
Comment on lines
+114
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] this makes it clear that
Suggested change
|
||||||||
entities = append(entities, n) | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
if len(entities) > 1 { | ||||||||
panic(fmt.Errorf("methods for service %s has more than one NamedIdMap operations", svc.Name)) | ||||||||
} | ||||||||
|
||||||||
if len(entities) == 0 { | ||||||||
return nil | ||||||||
} | ||||||||
|
||||||||
return entities[0] | ||||||||
} | ||||||||
|
||||||||
// List returns a method annotated with x-databricks-crud:list | ||||||||
func (svc *Service) List() *Method { | ||||||||
for _, v := range svc.methods { | ||||||||
for _, v := range svc.Methods() { | ||||||||
if v.Operation.Crud == "list" { | ||||||||
return v | ||||||||
} | ||||||||
|
@@ -111,7 +140,7 @@ func (svc *Service) List() *Method { | |||||||
|
||||||||
// List returns a method annotated with x-databricks-crud:create | ||||||||
func (svc *Service) Create() *Method { | ||||||||
for _, v := range svc.methods { | ||||||||
for _, v := range svc.Methods() { | ||||||||
if v.Operation.Crud == "create" { | ||||||||
return v | ||||||||
} | ||||||||
|
@@ -121,7 +150,7 @@ func (svc *Service) Create() *Method { | |||||||
|
||||||||
// List returns a method annotated with x-databricks-crud:read | ||||||||
func (svc *Service) Read() *Method { | ||||||||
for _, v := range svc.methods { | ||||||||
for _, v := range svc.Methods() { | ||||||||
if v.Operation.Crud == "read" { | ||||||||
return v | ||||||||
} | ||||||||
|
@@ -131,7 +160,7 @@ func (svc *Service) Read() *Method { | |||||||
|
||||||||
// List returns a method annotated with x-databricks-crud:update | ||||||||
func (svc *Service) Update() *Method { | ||||||||
for _, v := range svc.methods { | ||||||||
for _, v := range svc.Methods() { | ||||||||
if v.Operation.Crud == "update" { | ||||||||
return v | ||||||||
} | ||||||||
|
@@ -141,7 +170,7 @@ func (svc *Service) Update() *Method { | |||||||
|
||||||||
// List returns a method annotated with x-databricks-crud:delete | ||||||||
func (svc *Service) Delete() *Method { | ||||||||
for _, v := range svc.methods { | ||||||||
for _, v := range svc.Methods() { | ||||||||
if v.Operation.Crud == "delete" { | ||||||||
return v | ||||||||
} | ||||||||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] The description wasn't super clear to me. Is this an accurate rewrite?