Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
maastha committed Oct 11, 2024
1 parent c904b4f commit 346915a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions tools/codegen/codespec/api_to_provider_spec_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func pathParamsToAttributes(createOp, readOp *high.Operation) Attributes {
}

paramName := param.Name
s.Schema.Description = param.Description
parameterAttribute, err := s.buildResourceAttr(paramName, ComputedOptional)
if err != nil {
log.Printf("[WARN] Path param %s could not be mapped: %s", paramName, err)
Expand Down
4 changes: 2 additions & 2 deletions tools/codegen/codespec/api_to_provider_spec_mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
const (
testFieldDesc = "Test field description"
testResourceDesc = "Configures the project level settings for the Test Resource feature."
testPathParamDesc = "GroupId path param test description"
testPathParamDesc = "Path param test description"
)

type convertToSpecTestCase struct {
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestConvertToProviderSpec(t *testing.T) {
Name: "group_id",
ComputedOptionalRequired: codespec.Required,
String: &codespec.StringAttribute{},
// Description: &testPathParamDesc,
Description: conversion.StringPtr(testPathParamDesc),
},
codespec.Attribute{
Name: "num_double_default_attr",
Expand Down
11 changes: 4 additions & 7 deletions tools/codegen/codespec/terraform_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"regexp"
"strings"
"unicode/utf8"
)

var (
Expand All @@ -20,12 +19,10 @@ func terraformAttrName(attrName string) string {
removedUnsupported := unsupportedCharacters.ReplaceAllString(attrName, "")

insertedUnderscores := camelCase.ReplaceAllStringFunc(removedUnsupported, func(s string) string {
firstRune, size := utf8.DecodeRuneInString(s)
if firstRune == utf8.RuneError && size <= 1 {
return s
}

return fmt.Sprintf("%s_%s", string(firstRune), strings.ToLower(s[size:]))
firstChar := s[0]
restOfString := s[1:]
return fmt.Sprintf("%c_%s", firstChar, strings.ToLower(restOfString))
})

return strings.ToLower(insertedUnderscores)
}
2 changes: 1 addition & 1 deletion tools/codegen/codespec/testdata/api-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ components:
parameters:
groupId:
description: >-
GroupId path param test description
Path param test description
in: path
name: groupId
required: true
Expand Down

0 comments on commit 346915a

Please sign in to comment.