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

refactor: Remove ParsedGoType from codegen.proto, pass in opts as JSON #2918

Closed
wants to merge 12 commits into from

Conversation

andrewmbenton
Copy link
Collaborator

@andrewmbenton andrewmbenton commented Oct 26, 2023

The ParsedGoType configuration only applies to Go, so we remove it from the codegen plugin proto and instead pass the configuration as JSON to be unmarshaled by the codegen/golang package like other options.

The `ParsedGoType` configuration only applies to Go, so we remove it from the codegen plugin proto and instead pass the configuration as JSON to be unmarshaled by the codegen/golang package like other options.

Eventually we will need to push all of the validation of overrides from internal/config into the codegen/golang package, but that's a fair bit of work so I didn't push it here.

Aside from the proto change, which is obviously important, the other meaningful change is to generate.go on line 421, and the function implementation in shim.go. The types in opts/override.go are just recreations of what the plugin proto types were.
QuerySetOverrides []Override `json:"overrides,omitempty"`
QuerySetRename json.RawMessage `json:"rename,omitempty"` // Unused, TODO merge with req.Settings.Rename

Overrides []GoOverride `json:"-"`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We consolidate all overrides here and only use overrides parsed from JSON options and overrides coming in from req.Settings.Overrides within ParseOpts() below to build this slice.

@@ -59,11 +58,10 @@ func mergeImports(imps ...fileImports) [][]ImportSpec {
}

type importer struct {
Settings *plugin.Settings
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

having all overrides in Options lets us drop this field

internal/cmd/shim.go Outdated Show resolved Hide resolved
Comment on lines -17 to -51
},
"go": {
"emit_interface": false,
"emit_json_tags": false,
"emit_db_tags": false,
"emit_prepared_queries": false,
"emit_exact_table_names": false,
"emit_empty_slices": false,
"emit_exported_queries": false,
"emit_result_struct_pointers": false,
"emit_params_struct_pointers": false,
"emit_methods_with_db_argument": false,
"json_tags_case_style": "",
"package": "",
"out": "",
"sql_package": "",
"sql_driver": "",
"output_db_file_name": "",
"output_models_file_name": "",
"output_querier_file_name": "",
"output_copyfrom_file_name": "",
"output_files_suffix": "",
"emit_enum_valid_method": false,
"emit_all_enum_values": false,
"inflection_exclude_table_names": [],
"emit_pointers_for_null_types": false,
"query_parameter_limit": 1,
"output_batch_file_name": "",
"json_tags_id_uppercase": false,
"omit_unused_structs": false
},
"json": {
"out": "",
"indent": "",
"filename": ""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is cleanup from previous change in #2822

@andrewmbenton andrewmbenton changed the title refactor: Remove Overrides from Settings in codegen.proto, pass in JSON opts refactor: Remove ParsedGoType from codegen.proto, pass in opts as JSON Oct 27, 2023
Comment on lines +1 to +2
# package override
error generating code: bad syntax for struct tag pair
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because struct tags get parsed in the codegen plugin now

internal/cmd/shim.go Outdated Show resolved Hide resolved
internal/cmd/shim.go Outdated Show resolved Hide resolved
internal/codegen/golang/opts/options.go Outdated Show resolved Hide resolved
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