Skip to content

Commit

Permalink
mark all properties as required outputs for node
Browse files Browse the repository at this point in the history
  • Loading branch information
blampe committed Jul 1, 2024
1 parent d475788 commit 7578482
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/codegen/packagegenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package codegen

import (
"bytes"
"encoding/json"
"fmt"
"io"

Expand Down Expand Up @@ -169,9 +171,27 @@ func (pg *PackageGenerator) GetTypes() map[string]pschema.ComplexTypeSpec {
}
typ.Required = append(typ.Required, "apiVersion", "kind", "metadata")

propNames := []string{}
for name := range typ.Properties {
propNames = append(propNames, name)
}
if typ.Language == nil {
typ.Language = make(map[string]pschema.RawMessage)
}
typ.Language["nodejs"] = rawMessage(map[string][]string{"requiredOutputs": propNames, "requiredInputs": typ.Required})

types[resourceToken] = typ
}
}
}
return types
}

func rawMessage(v any) pschema.RawMessage {
var out bytes.Buffer
encoder := json.NewEncoder(&out)
encoder.SetEscapeHTML(false)
err := encoder.Encode(v)
contract.AssertNoErrorf(err, "unexpected error while encoding JSON")
return out.Bytes()
}
1 change: 1 addition & 0 deletions pkg/codegen/packagegenerator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ func TestReadPackagesFromSource(t *testing.T) {
// rollout.Properties["status"]
assert.True(t, ok)
assert.NotContains(t, rollout.Required, "status")
assert.Subset(t, rollout.Language["nodejs"], []byte(`"status"`))
}

0 comments on commit 7578482

Please sign in to comment.