Skip to content

Commit 3907a64

Browse files
authored
Add DisplayName to Product struct (GoogleCloudPlatform#10161)
1 parent b16ca4a commit 3907a64

File tree

3 files changed

+123
-10
lines changed

3 files changed

+123
-10
lines changed

mmv1/api/async.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type Result struct {
6666

6767
// Contains information about the result of an Operation
6868

69-
ResourceInsideResponse bool
69+
ResourceInsideResponse bool `yaml:"resource_inside_response"`
7070
}
7171

7272
// def validate

mmv1/api/product.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package api
1515

1616
import (
1717
"github.com/GoogleCloudPlatform/magic-modules/mmv1/api/product"
18+
"github.com/GoogleCloudPlatform/magic-modules/mmv1/google"
1819
"golang.org/x/exp/slices"
1920
)
2021

@@ -38,6 +39,7 @@ type Product struct {
3839
// Name string
3940

4041
// Display Name: The full name of the GCP product; eg "Cloud Bigtable"
42+
DisplayName string `yaml:"display_name"`
4143

4244
Objects []*Resource
4345

@@ -108,15 +110,15 @@ func (p *Product) Validate() {
108110
// name.downcase
109111
// end
110112

111-
// // The product full name is the "display name" in string form intended for
112-
// // users to read in documentation; "Google Compute Engine", "Cloud Bigtable"
113-
// def display_name
114-
// if @display_name.nil?
115-
// name.space_separated
116-
// else
117-
// @display_name
118-
// end
119-
// end
113+
// The product full name is the "display name" in string form intended for
114+
// users to read in documentation; "Google Compute Engine", "Cloud Bigtable"
115+
func (p Product) GetDisplayName() string {
116+
if p.DisplayName == "" {
117+
return google.SpaceSeparated(p.Name)
118+
}
119+
120+
return p.DisplayName
121+
}
120122

121123
// // Most general version that exists for the product
122124
// // If GA is present, use that, else beta, else alpha

mmv1/google/string_utils.go

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright 2024 Google Inc.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package google
15+
16+
import (
17+
"regexp"
18+
"strings"
19+
)
20+
21+
// // Helper class to process and mutate strings.
22+
// class StringUtils
23+
// // Converts string from camel case to underscore
24+
// def self.underscore(source)
25+
// source.gsub(/::/, '/')
26+
// .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
27+
// .gsub(/([a-z\d])([A-Z])/, '\1_\2')
28+
// .tr('-', '_')
29+
// .tr('.', '_')
30+
// .downcase
31+
// end
32+
33+
// // Converts from PascalCase to Space Separated
34+
// def self.space_separated(source)
35+
// tmp = source.gsub(/([A-Z]+)([A-Z][a-z])/, '\1 \2')
36+
// .gsub(/([a-z\d])([A-Z])/, '\1 \2')
37+
// .downcase
38+
// tmp[0].upcase.concat(tmp[1..])
39+
// end
40+
41+
// Converts from PascalCase to Space Separated
42+
// For example, converts "AccessApproval" to "Access Approval"
43+
func SpaceSeparated(source string) string {
44+
tmp := regexp.MustCompile(`([A-Z]+)([A-Z][a-z])`).ReplaceAllString(source, "${1} ${2}")
45+
tmp = regexp.MustCompile(`([a-z\d])([A-Z])`).ReplaceAllString(tmp, "${1} ${2}")
46+
tmp = strings.ToLower(tmp)
47+
tmp = strings.Title(tmp)
48+
return tmp
49+
}
50+
51+
// // Converts a string to space-separated capitalized words
52+
// def self.title(source)
53+
// ss = space_separated(source)
54+
// ss.gsub(/\b(?<!\w['’`()])[a-z]/, &:capitalize)
55+
// end
56+
57+
// // rubocop:disable Style/SafeNavigation // support Ruby < 2.3.0
58+
// def self.symbolize(key)
59+
// key.to_sym unless key.nil?
60+
// end
61+
// // rubocop:enable Style/SafeNavigation
62+
63+
// // Returns all the characters up until the period (.) or returns text
64+
// // unchanged if there is no period.
65+
// def self.first_sentence(text)
66+
// period_pos = text.index(/[.?!]/)
67+
// return text if period_pos.nil?
68+
69+
// text[0, period_pos + 1]
70+
// end
71+
72+
// // Returns the plural form of a word
73+
// def self.plural(source)
74+
// // policies -> policies
75+
// // indices -> indices
76+
// return source if source.end_with?('ies') || source.end_with?('es')
77+
78+
// // index -> indices
79+
// return "//{source.gsub(/ex$/, '')}ices" if source.end_with?('ex')
80+
81+
// // mesh -> meshes
82+
// return "//{source}es" if source.end_with?('esh')
83+
84+
// // key -> keys
85+
// // gateway -> gateways
86+
// return "//{source}s" if source.end_with?('ey') || source.end_with?('ay')
87+
88+
// // policy -> policies
89+
// return "//{source.gsub(/y$/, '')}ies" if source.end_with?('y')
90+
91+
// "//{source}s"
92+
// end
93+
94+
// // Slimmed down version of ActiveSupport::Inflector code
95+
// def self.camelize(term, uppercase_first_letter)
96+
// acronyms_camelize_regex = /^(?:(?=a)b(?=\b|[A-Z_])|\w)/
97+
98+
// string = term.to_s
99+
// string = if uppercase_first_letter
100+
// string.sub(/^[a-z\d]*/) { |match| match.capitalize! || match }
101+
// else
102+
// string.sub(acronyms_camelize_regex) { |match| match.downcase! || match }
103+
// end
104+
// // handle snake case
105+
// string.gsub!(/(?:_)([a-z\d]*)/i) do
106+
// word = ::Regexp.last_match(1)
107+
// word.capitalize! || word
108+
// end
109+
// string
110+
// end
111+
// end

0 commit comments

Comments
 (0)