customization_passes.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package api
  2. import (
  3. "path/filepath"
  4. "strings"
  5. )
  6. // customizationPasses Executes customization logic for the API by package name.
  7. func (a *API) customizationPasses() {
  8. var svcCustomizations = map[string]func(*API){
  9. "s3": s3Customizations,
  10. "cloudfront": cloudfrontCustomizations,
  11. "dynamodbstreams": dynamodbstreamsCustomizations,
  12. }
  13. if fn := svcCustomizations[a.PackageName()]; fn != nil {
  14. fn(a)
  15. }
  16. }
  17. // s3Customizations customizes the API generation to replace values specific to S3.
  18. func s3Customizations(a *API) {
  19. var strExpires *Shape
  20. for name, s := range a.Shapes {
  21. // Remove ContentMD5 members
  22. if _, ok := s.MemberRefs["ContentMD5"]; ok {
  23. delete(s.MemberRefs, "ContentMD5")
  24. }
  25. // Expires should be a string not time.Time since the format is not
  26. // enforced by S3, and any value can be set to this field outside of the SDK.
  27. if strings.HasSuffix(name, "Output") {
  28. if ref, ok := s.MemberRefs["Expires"]; ok {
  29. if strExpires == nil {
  30. newShape := *ref.Shape
  31. strExpires = &newShape
  32. strExpires.Type = "string"
  33. strExpires.refs = []*ShapeRef{}
  34. }
  35. ref.Shape.removeRef(ref)
  36. ref.Shape = strExpires
  37. ref.Shape.refs = append(ref.Shape.refs, &s.MemberRef)
  38. }
  39. }
  40. }
  41. // Rename "Rule" to "LifecycleRule"
  42. if s, ok := a.Shapes["Rule"]; ok {
  43. s.Rename("LifecycleRule")
  44. }
  45. }
  46. // cloudfrontCustomizations customized the API generation to replace values
  47. // specific to CloudFront.
  48. func cloudfrontCustomizations(a *API) {
  49. // MaxItems members should always be integers
  50. for _, s := range a.Shapes {
  51. if ref, ok := s.MemberRefs["MaxItems"]; ok {
  52. ref.ShapeName = "Integer"
  53. ref.Shape = a.Shapes["Integer"]
  54. }
  55. }
  56. }
  57. // dynamodbstreamsCustomizations references any duplicate shapes from DynamoDB
  58. func dynamodbstreamsCustomizations(a *API) {
  59. p := strings.Replace(a.path, "streams.dynamodb", "dynamodb", -1)
  60. file := filepath.Join(p, "api-2.json")
  61. dbAPI := API{}
  62. dbAPI.Attach(file)
  63. dbAPI.Setup()
  64. for n := range a.Shapes {
  65. if _, ok := dbAPI.Shapes[n]; ok {
  66. a.Shapes[n].resolvePkg = "github.com/aws/aws-sdk-go/service/dynamodb"
  67. }
  68. }
  69. }