Skip to content

typegen: add schema generation#22

Open
zmitry wants to merge 1 commit into
starius:masterfrom
zmitry:schema-gen
Open

typegen: add schema generation#22
zmitry wants to merge 1 commit into
starius:masterfrom
zmitry:schema-gen

Conversation

@zmitry

@zmitry zmitry commented Jun 6, 2021

Copy link
Copy Markdown
Contributor

No description provided.

@starius starius left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few notes.

"ref": "ExampleDirection"
},
"items": {
"elements": {}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running go generate ./example results in modification in this file:

@@ -35,7 +35,9 @@ ExampleEchoRequest: {
       "ref": "ExampleDirection"
     },
     "items": {
-      "elements": {}
+      "elements": {
+        "ref": "ExampleCustomType2"
+      }
     },
     "maps": {
       "values": {

Comment thread typegen/schema.printer.go
},
}).Parse(GlobalSchemaTemplate)
panicIf(err)
tmpl.Execute(writer, map[string]interface{}{

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

golangci-lint: Error return value of tmpl.Execute is not checked

Comment thread typegen/schema.printer.go
}
switch {
case k == reflect.Ptr:
t = indirect(t)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

golangci-lint: this value of t is never used

Comment thread example/gen/main.go
Comment on lines +23 to +25
_ = os.RemoveAll(filepath.Join(options.OutDir, "schema.ts"))
schemaFile, _ := os.OpenFile(filepath.Join(options.OutDir, "schema.ts"), os.O_WRONLY|os.O_CREATE, 0755)
_ = typegen.PrintJDT(parser, schemaFile)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check errors, please.

Comment thread ts_client.go
}
return ""
}
func SerializeCustomSchema(t reflect.Type) string {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this function used? I don't see any usage in api2 itself.

Comment thread typegen/schema.printer.go
return nil
}

func ToSchema(schema *JSONTypeDefSchema) (*jdt.Schema, error) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this function used? I don't see any usage in api2 itself.

Comment thread typegen/schema.printer.go
type JSONTypeDefSchema struct {
Definitions map[string]JSONTypeDefSchema `json:"definitions,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
Nullable bool `json:"nullable,omitempty"`

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, bool type should not have omitempty.

Comment thread typegen/schema.printer.go
Metadata map[string]interface{} `json:"metadata,omitempty"`
Nullable bool `json:"nullable,omitempty"`
Ref *string `json:"ref,omitempty"`
Type jdt.Type `json:"type,omitempty"`

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, jdt.Type (string) type should not have omitempty.

Comment thread typegen/schema.printer.go
Elements *JSONTypeDefSchema `json:"elements,omitempty"`
Properties map[string]JSONTypeDefSchema `json:"properties,omitempty"`
OptionalProperties map[string]JSONTypeDefSchema `json:"optionalProperties,omitempty"`
AdditionalProperties bool `json:"additionalProperties,omitempty"`

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, bool type should not have omitempty.

Comment thread typegen/schema.printer.go
OptionalProperties map[string]JSONTypeDefSchema `json:"optionalProperties,omitempty"`
AdditionalProperties bool `json:"additionalProperties,omitempty"`
Values *JSONTypeDefSchema `json:"values,omitempty"`
Discriminator string `json:"discriminator,omitempty"`

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, string type should not have omitempty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants