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

add struct util functions and default struct tags #331

Merged
merged 4 commits into from
Dec 12, 2023

Conversation

davidbloss
Copy link
Contributor

@davidbloss davidbloss commented Dec 12, 2023

Issues

Changelog

Add default:"" struct tags to:

  • MemberInput, PropertyDefinitionInput, ToolCreateInput, ToolUpdateInput, UserInput, UserIdentifierInput

Add utils.go with these functions:

  • IsResourceValidate[T any](opslevelResource T) - validates structs based on validate:"" struct tags
  • SetDefaultsFor[T any](opslevelResource *T) - sets defaults defined by default:"" struct tags
  • NewExampleOf[T any]() - generic constructor that sets defaults defined by default:"" struct tags
  • JsonOf[T any](opslevelResource T) - converts struct to JSON formatted string
  • YamlOf[T any](opslevelResource T) - converts struct to Yaml formatted string

IsResourceValidate is not yet used

  • List your changes here
  • Make a changie entry

Tophatting

task test - tests pass

@davidbloss davidbloss requested review from rocktavious and a user December 12, 2023 14:47
Copy link

codecov bot commented Dec 12, 2023

Codecov Report

Attention: 16 lines in your changes are missing coverage. Please review.

Comparison is base (6fda227) 77.10% compared to head (fa1bceb) 76.89%.
Report is 8 commits behind head on main.

Files Patch % Lines
utils.go 27.27% 15 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #331      +/-   ##
==========================================
- Coverage   77.10%   76.89%   -0.21%     
==========================================
  Files          52       52              
  Lines        3389     3406      +17     
==========================================
+ Hits         2613     2619       +6     
- Misses        568      578      +10     
- Partials      208      209       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@davidbloss davidbloss changed the title add Example,ExampleJson,ExampleYaml member funcs to some structs add struct util functions and default struct tags Dec 12, 2023
@@ -9,19 +9,15 @@ import (

func TestCreateTool(t *testing.T) {
// Arrange
toolCreateInput := autopilot.Register[ol.ToolCreateInput]("tool_create_input", ol.NewExampleOf[ol.ToolCreateInput]())
Copy link
Collaborator

Choose a reason for hiding this comment

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

OMG 🚀

utils.go Outdated
var structValidator = validator.New(validator.WithRequiredStructEnabled())

// Validates resource's `validate:""` struct tags
func IsResourceValidate[T any](opslevelResource T) error {
Copy link
Collaborator

@rocktavious rocktavious Dec 12, 2023

Choose a reason for hiding this comment

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

These function names are 😍 - Great Job! This one maybe should be IsResourceValid ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤣

Copy link
Collaborator

@rocktavious rocktavious left a comment

Choose a reason for hiding this comment

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

Amazing!

@davidbloss davidbloss merged commit 1b5c829 into main Dec 12, 2023
5 checks passed
@davidbloss davidbloss deleted the db/gen-examples-for-structs branch December 12, 2023 20:00
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