- 
                Notifications
    
You must be signed in to change notification settings  - Fork 226
 
Allow OperatorType to be a list such that one API can map to multiple operations #166
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -14,11 +14,17 @@ | |
| package config | ||
| 
     | 
||
| import ( | ||
| "encoding/json" | ||
| 
     | 
||
| awssdkmodel "github.com/aws/aws-sdk-go/private/model/api" | ||
| 
         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. please change the import section to: import (
	"encoding/json"
        awssdkmodel "github.com/aws/aws-sdk-go/private/model/api"
	"github.com/aws-controllers-k8s/code-generator/pkg/util"
)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. Sure.  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. Yes exactly :). Sometimes  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. Thank you!  | 
||
| 
     | 
||
| "github.com/aws-controllers-k8s/code-generator/pkg/util" | ||
| "github.com/aws-controllers-k8s/code-generator/pkg/util" | ||
| ) | ||
| 
     | 
||
| // StringArray is a type that can be represented in JSON as *either* a string | ||
| // *or* an array of strings | ||
| type StringArray []string | ||
| 
     | 
||
| // OperationConfig represents instructions to the ACK code generator to | ||
| // specify the overriding values for API operation parameters and its custom implementation. | ||
| type OperationConfig struct { | ||
| 
        
          
        
         | 
    @@ -37,7 +43,8 @@ type OperationConfig struct { | |
| ResourceName string `json:"resource_name"` | ||
| // Override for operation type in case of heuristic failure | ||
| // An example of this is `Put...` or `Register...` API operations not being correctly classified as `Create` op type | ||
| OperationType string `json:"operation_type"` | ||
| // OperationType []string `json:"operation_type"` | ||
| OperationType StringArray `json:"operation_type"` | ||
| // PrimaryIdentifierFieldName provides the name of the field that should be | ||
| // interpreted as the "primary" identifier field. This field will be used as | ||
| // the primary field for resource adoption. | ||
| 
          
            
          
           | 
    @@ -75,3 +82,21 @@ func (c *Config) ListOpMatchFieldNames( | |
| } | ||
| return rConfig.ListOperation.MatchFields | ||
| } | ||
| 
     | 
||
| // UnmarshalJSON parses input for a either a string or | ||
| // or a list and returns a StringArray. | ||
| func (a *StringArray) UnmarshalJSON(b []byte) error { | ||
| var multi []string | ||
| err := json.Unmarshal(b, &multi) | ||
| if err != nil { | ||
| var single string | ||
| err := json.Unmarshal(b, &single) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| *a = []string{single} | ||
| } else { | ||
| *a = multi | ||
| } | ||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -14,6 +14,7 @@ | |
| package model | ||
| 
     | 
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "io/ioutil" | ||
| 
        
          
        
         | 
    @@ -27,6 +28,7 @@ import ( | |
| ackgenconfig "github.com/aws-controllers-k8s/code-generator/pkg/generate/config" | ||
| "github.com/aws-controllers-k8s/code-generator/pkg/names" | ||
| "github.com/aws-controllers-k8s/code-generator/pkg/util" | ||
| 
     | 
||
| awssdkmodel "github.com/aws/aws-sdk-go/private/model/api" | ||
| 
         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. Tiny nit: this import should be in the second block of imports 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. let me set up the goimports and create a tiny PR for this one.  | 
||
| ) | ||
| 
     | 
||
| 
          
            
          
           | 
    @@ -206,11 +208,13 @@ func (a *SDKAPI) GetOperationMap(cfg *ackgenconfig.Config) *OperationMap { | |
| // create an index of Operations by operation types and resource name | ||
| opMap := OperationMap{} | ||
| for opID, op := range a.API.Operations { | ||
| opType, resName := getOpTypeAndResourceName(opID, cfg) | ||
| if _, found := opMap[opType]; !found { | ||
| opMap[opType] = map[string]*awssdkmodel.Operation{} | ||
| opTypeArray, resName := getOpTypeAndResourceName(opID, cfg) | ||
| for _, opType := range opTypeArray { | ||
| if _, found := opMap[opType]; !found { | ||
| opMap[opType] = map[string]*awssdkmodel.Operation{} | ||
| } | ||
| opMap[opType][resName] = op | ||
| } | ||
| opMap[opType][resName] = op | ||
| } | ||
| a.opMap = &opMap | ||
| return &opMap | ||
| 
          
            
          
           | 
    @@ -382,20 +386,26 @@ func (a *SDKAPI) SDKAPIInterfaceTypeName() string { | |
| } | ||
| 
     | 
||
| // Override the operation type and/or resource name if specified in config | ||
| func getOpTypeAndResourceName(opID string, cfg *ackgenconfig.Config) (OpType, string) { | ||
| func getOpTypeAndResourceName(opID string, cfg *ackgenconfig.Config) ([]OpType, string) { | ||
| var unmarshaledOpTypes ackgenconfig.StringArray | ||
| opType, resName := GetOpTypeAndResourceNameFromOpID(opID) | ||
| opTypes := []OpType{opType} | ||
| 
     | 
||
| if cfg != nil { | ||
| if operationConfig, exists := cfg.Operations[opID]; exists { | ||
| if operationConfig.OperationType != "" { | ||
| opType = OpTypeFromString(operationConfig.OperationType) | ||
| } | ||
| if cfg == nil { | ||
| return opTypes, resName | ||
| } | ||
| if operationConfig, exists := cfg.Operations[opID]; exists { | ||
| if operationConfig.ResourceName != "" { | ||
| resName = operationConfig.ResourceName | ||
| } | ||
| 
     | 
||
| if operationConfig.ResourceName != "" { | ||
| resName = operationConfig.ResourceName | ||
| if b, err := json.Marshal(operationConfig.OperationType); err == nil { | ||
                
       | 
||
| json.Unmarshal(b, &unmarshaledOpTypes) | ||
                
       | 
||
| for _, operationType := range unmarshaledOpTypes { | ||
| opType = OpTypeFromString(operationType) | ||
| opTypes = append(opTypes, opType) | ||
| } | ||
| } | ||
| } | ||
| 
     | 
||
| return opType, resName | ||
| return opTypes, resName | ||
| } | ||
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.
This is a standard library import, so please place above the
awssdkmodelimport line and separate with an empty newline.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.
done.