private/apigen: fix TS class generation from collection of named struct
This change fixes an issue where the TypeScript API code generator would silently fail to generate class definitions for named structs used as the element type of array or slice struct fields. This issue caused invalid TypeScript code to be generated from the frontend config struct because it contained a slice of partnered satellite structs. The TypeScript class definition of the frontend config referenced the nonexistent partnered satellite class. The satellite frontend config uses, so this issue caused the Change-Id: Idfcb6ec1bbc603a43033ee4afb5b421b7454855c
This commit is contained in:
parent
f8b59a50ff
commit
6d03b92ea6
@ -84,6 +84,7 @@ func (types *Types) All() map[reflect.Type]string {
|
||||
case reflect.Array, reflect.Slice:
|
||||
// If element type has a TypeScript name then an array of the element type will be defined
|
||||
// otherwise we have to create a compound type.
|
||||
elemTypeName := t.Elem().Name()
|
||||
if tsen := TypescriptTypeName(t.Elem()); tsen == "" {
|
||||
if altTypeName == "" {
|
||||
panic(
|
||||
@ -95,8 +96,9 @@ func (types *Types) All() map[reflect.Type]string {
|
||||
}
|
||||
all[t] = altTypeName
|
||||
uniqueNames[altTypeName] = struct{}{}
|
||||
walk(t.Elem(), compoundTypeName(altTypeName, "item"))
|
||||
elemTypeName = compoundTypeName(altTypeName, "item")
|
||||
}
|
||||
walk(t.Elem(), elemTypeName)
|
||||
case reflect.Struct:
|
||||
n := t.Name()
|
||||
if n == "" {
|
||||
|
@ -52,6 +52,7 @@ func TestTypes(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("All nested structs and slices", func(t *testing.T) {
|
||||
type Item struct{}
|
||||
types := NewTypes()
|
||||
types.Register(
|
||||
typeCustomName{
|
||||
@ -71,12 +72,13 @@ func TestTypes(t *testing.T) {
|
||||
Content string
|
||||
Valoration testTypesValoration
|
||||
}
|
||||
Items []Item
|
||||
}{}),
|
||||
name: "Response",
|
||||
})
|
||||
|
||||
allTypes := types.All()
|
||||
require.Len(t, allTypes, 9, "total number of types")
|
||||
require.Len(t, allTypes, 10, "total number of types")
|
||||
|
||||
typesNames := []string{}
|
||||
for _, name := range allTypes {
|
||||
@ -89,6 +91,7 @@ func TestTypes(t *testing.T) {
|
||||
"ResponseAddresses", "ResponseAddressesItem",
|
||||
"ResponseJob",
|
||||
"ResponseDocuments", "ResponseDocumentsItem", "testTypesValoration",
|
||||
"Item",
|
||||
}, typesNames)
|
||||
})
|
||||
|
||||
|
@ -56,7 +56,6 @@ export class MultiCaptchaConfig {
|
||||
hcaptcha: SingleCaptchaConfig;
|
||||
}
|
||||
|
||||
// TODO: This class was added manually because TypeScript generation is broken.
|
||||
export class PartneredSatellite {
|
||||
name: string;
|
||||
address: string;
|
||||
|
Loading…
Reference in New Issue
Block a user