Skip to content

Commit 894605d

Browse files
authored
Update to Omicron 0dad016 (#276)
Updates to Omicron 0dad016 and fixes a small bug with the type generation.
1 parent 845061b commit 894605d

File tree

7 files changed

+304
-540
lines changed

7 files changed

+304
-540
lines changed

.changelog/v0.4.0.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title = "Integers as pointers"
33
description = "All integers within the SDK's types are now `*int`. This is due to Go's handling of 0 as the empty value. This is specifically necessary when a field is an integer and also not required. [#274](https://github.com/oxidecomputer/oxide.go/pull/274)"
44

55
[[features]]
6-
title = "Affinity and anti-affinity groups"
6+
title = "Anti-affinity groups"
77
description = "CRUD methods. [#269](https://github.com/oxidecomputer/oxide.go/pull/269)"
88

99
[[bugs]]

VERSION_OMICRON

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8a40bb8
1+
0dad016

internal/generate/paths.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func getSuccessResponseType(o *openapi3.Operation, isGetAllPages bool) (string,
251251
if isGetAllPages {
252252

253253
if items, ok := content.Schema.Value.Properties["items"]; ok {
254-
getAllPagesType = convertToValidGoType("", items)
254+
getAllPagesType = convertToValidGoType("", "", items)
255255
} else {
256256
fmt.Printf("[WARN] TODO: skipping response for %q, since it is a get all pages response and has no `items` property:\n%#v\n", o.OperationID, content.Schema.Value.Properties)
257257
return "", "", nil
@@ -361,10 +361,11 @@ func buildPathOrQueryParams(paramType string, params map[string]*openapi3.Parame
361361
}
362362
sort.Strings(keys)
363363
for _, name := range keys {
364+
typeName := strcase.ToCamel(name)
364365
p := params[name]
365-
n := "params." + strcase.ToCamel(name)
366+
n := "params." + strcase.ToCamel(typeName)
366367

367-
switch t := convertToValidGoType(name, p.Schema); t {
368+
switch t := convertToValidGoType(name, typeName, p.Schema); t {
368369
case "string":
369370
pathParams = append(pathParams, fmt.Sprintf("%q: %s,", name, n))
370371
case "bool":

internal/generate/types.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func constructParamTypes(paths map[string]*openapi3.PathItem) []TypeTemplate {
138138
paramName := strcase.ToCamel(p.Value.Name)
139139
field := TypeFields{
140140
Name: paramName,
141-
Type: convertToValidGoType("", p.Value.Schema),
141+
Type: convertToValidGoType("", "", p.Value.Schema),
142142
}
143143

144144
if p.Value.Required {
@@ -167,7 +167,7 @@ func constructParamTypes(paths map[string]*openapi3.PathItem) []TypeTemplate {
167167

168168
field = TypeFields{
169169
Name: "Body",
170-
Type: "*" + convertToValidGoType("", r.Schema),
170+
Type: "*" + convertToValidGoType("", "", r.Schema),
171171
SerializationInfo: "`json:\"body,omitempty\" yaml:\"body,omitempty\"`",
172172
}
173173
}
@@ -507,7 +507,7 @@ func createTypeObject(schema *openapi3.Schema, name, typeName, description strin
507507
for _, k := range keys {
508508
v := schemas[k]
509509
// Check if we need to generate a type for this type.
510-
typeName := convertToValidGoType(k, v)
510+
typeName := convertToValidGoType(k, typeName, v)
511511

512512
if isLocalEnum(v) {
513513
typeName = fmt.Sprintf("%s%s", name, strcase.ToCamel(k))
@@ -664,7 +664,7 @@ func createOneOf(s *openapi3.Schema, name, typeName string) ([]TypeTemplate, []E
664664
for _, prop := range keys {
665665
p := v.Value.Properties[prop]
666666
// We want to collect all the unique properties to create our global oneOf type.
667-
propertyType := convertToValidGoType(prop, p)
667+
propertyType := convertToValidGoType(prop, typeName, p)
668668
properties = append(properties, prop+"="+propertyType)
669669
}
670670
}
@@ -715,7 +715,7 @@ func createOneOf(s *openapi3.Schema, name, typeName string) ([]TypeTemplate, []E
715715
for _, prop := range keys {
716716
p := v.Value.Properties[prop]
717717
// We want to collect all the unique properties to create our global oneOf type.
718-
propertyType := convertToValidGoType(prop, p)
718+
propertyType := convertToValidGoType(prop, typeName, p)
719719

720720
// Check if we have an enum in order to use the corresponding type instead of
721721
// "string"

internal/generate/utils.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func isPageParam(s string) bool {
106106
}
107107

108108
// convertToValidGoType converts a schema type to a valid Go type.
109-
func convertToValidGoType(property string, r *openapi3.SchemaRef) string {
109+
func convertToValidGoType(property, typeName string, r *openapi3.SchemaRef) string {
110110
// Use reference as it is the type
111111
if r.Ref != "" {
112112
return getReferenceSchema(r)
@@ -131,7 +131,7 @@ func convertToValidGoType(property string, r *openapi3.SchemaRef) string {
131131
return "TODO"
132132
}
133133

134-
return convertToValidGoType(property, r.Value.AllOf[0])
134+
return convertToValidGoType(property, "", r.Value.AllOf[0])
135135
}
136136

137137
var schemaType string
@@ -155,8 +155,9 @@ func convertToValidGoType(property string, r *openapi3.SchemaRef) string {
155155
// TODO: handle if it is not a reference.
156156
schemaType = "[]string"
157157
} else if r.Value.Type.Is("object") {
158-
// Most likely this is a local object, we will handle it.
159-
schemaType = strcase.ToCamel(property)
158+
// This is a local object, we make sure there are no duplicates
159+
// by concactenating the type name and the property name.
160+
schemaType = typeName + strcase.ToCamel(property)
160161
} else {
161162
fmt.Printf("[WARN] TODO: handle type %q for %q, marking as interface{} for now\n", r.Value.Type, property)
162163
schemaType = "interface{}"

0 commit comments

Comments
 (0)