Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new ClickHouse endpoints #78

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading