POST license API endpoint (#3570)

* POST license API

Signed-off-by: Spike Curtis <spike@coder.com>

* Support interface{} types in generated Typescript

Signed-off-by: Spike Curtis <spike@coder.com>

* Disable linting on empty interface any

Signed-off-by: Spike Curtis <spike@coder.com>

* Code review updates

Signed-off-by: Spike Curtis <spike@coder.com>

* Enforce unique licenses

Signed-off-by: Spike Curtis <spike@coder.com>

* Renames from code review

Signed-off-by: Spike Curtis <spike@coder.com>

* Code review renames and comments

Signed-off-by: Spike Curtis <spike@coder.com>

Signed-off-by: Spike Curtis <spike@coder.com>
This commit is contained in:
Spike Curtis
2022-08-22 15:02:50 -07:00
committed by GitHub
parent 85acfdf0dc
commit b101a6f3f4
29 changed files with 666 additions and 50 deletions
+15 -1
View File
@@ -382,8 +382,14 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
return TypescriptType{}, xerrors.Errorf("map key: %w", err)
}
aboveTypeLine := keyType.AboveTypeLine
if aboveTypeLine != "" && valueType.AboveTypeLine != "" {
aboveTypeLine = aboveTypeLine + "\n"
}
aboveTypeLine = aboveTypeLine + valueType.AboveTypeLine
return TypescriptType{
ValueType: fmt.Sprintf("Record<%s, %s>", keyType.ValueType, valueType.ValueType),
ValueType: fmt.Sprintf("Record<%s, %s>", keyType.ValueType, valueType.ValueType),
AboveTypeLine: aboveTypeLine,
}, nil
case *types.Slice, *types.Array:
// Slice/Arrays are pretty much the same.
@@ -458,6 +464,14 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
}
resp.Optional = true
return resp, nil
case *types.Interface:
// only handle the empty interface for now
intf := ty
if intf.Empty() {
return TypescriptType{ValueType: "any",
AboveTypeLine: indentedComment("eslint-disable-next-line")}, nil
}
return TypescriptType{}, xerrors.New("only empty interface types are supported")
}
// These are all the other types we need to support.