Skip to content

Commit

Permalink
feat: add new ClickHouse endpoints (#78)
Browse files Browse the repository at this point in the history
Co-authored-by: Murad Biashimov <[email protected]>
  • Loading branch information
rriski and byashimov authored Jun 14, 2024
1 parent 18ba72e commit f366a68
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 8 deletions.
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ BillingGroup:
- BillingGroupProjectsAssign
- BillingGroupUpdate
ClickHouse:
- ServiceClickHouseCurrentQueries
- ServiceClickHouseDatabaseCreate
- ServiceClickHouseDatabaseDelete
- ServiceClickHouseDatabaseList
- ServiceClickHouseQuery
- ServiceClickHouseQueryStats
- ServiceClickHouseTieredStorageSummary
Cloud:
Expand Down
26 changes: 21 additions & 5 deletions generator/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ const (
SchemaTypeBoolean = "boolean"
// SchemaTypeTime represents a time schema type.
SchemaTypeTime = "time"
// SchemaTypeAny internal type for anyOf
SchemaTypeAny = "any"
)

// Schema represents a parsed OpenAPI schema.
Expand Down Expand Up @@ -234,6 +236,12 @@ func (s *Schema) init(doc *Doc, scope map[string]*Schema, name string) {
}

if s.isArray() {
// a workaround for invalid schema
// fixme: on the backend
if s.Items == nil {
s.Items = &Schema{Type: SchemaTypeAny}
}

s.Items.parent = s
s.Items.required = true // a workaround to not have slices with pointers
s.Items.init(doc, scope, toSingle(name))
Expand Down Expand Up @@ -287,6 +295,10 @@ func (s *Schema) isArray() bool {
return s.Type == SchemaTypeArray
}

func (s *Schema) isNestedArray() bool {
return s.isArray() && s.Items.isArray()
}

func (s *Schema) isScalar() bool {
switch s.Type {
case SchemaTypeString, SchemaTypeInteger, SchemaTypeNumber, SchemaTypeBoolean, SchemaTypeTime:
Expand Down Expand Up @@ -342,11 +354,12 @@ func getScalarType(s *Schema) *jen.Statement {

// getType returns go type with/wo a pointer
func getType(s *Schema) *jen.Statement {
if s.isEnum() {
switch {
case s.Type == SchemaTypeAny:
return jen.Any()
case s.isEnum():
return jen.Id(s.CamelName)
}

if s.isScalar() {
case s.isScalar():
scalar := getScalarType(s)
if !s.required && s.Type != SchemaTypeString {
return jen.Op("*").Add(scalar)
Expand All @@ -363,7 +376,10 @@ func getType(s *Schema) *jen.Statement {
}

// No pointers for complex objects
if s.Items.isObject() || s.Items.isArray() {
switch {
case s.isNestedArray():
// but not nested array
case s.Items.isObject() || s.Items.isArray():
return a.Id(s.Items.CamelName)
}

Expand Down
74 changes: 71 additions & 3 deletions handler/clickhouse/clickhouse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f366a68

Please sign in to comment.