-
Notifications
You must be signed in to change notification settings - Fork 3
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: generate teams operation data from openapi spec #226
feat: generate teams operation data from openapi spec #226
Conversation
cmd/resources/resources.go
Outdated
type OperationData struct { | ||
Short string | ||
Long string | ||
Use string | ||
Params []Param | ||
HTTPMethod string | ||
RequiresBody bool | ||
Path string | ||
} | ||
|
||
type Param struct { | ||
Name string | ||
In string | ||
Description string | ||
Type string | ||
Required bool | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to cmd/resources/gen_resources.go
since that's where these are added
err = json.Unmarshal(expectedFromFile, &expected) | ||
require.NoError(t, err) | ||
|
||
t.Run("succeeds with single get resource", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not running the comparison directly on each op led to flakey tests - if there's a better way to do this LMK!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not getting test failures when running go test ./cmd/resources/ -run TestGetTemplateData -count=100
after changing the test to
t.Run("succeeds with single get resource", func(t *testing.T) {
assert.Equal(t, expected, actual)
})
What failures were you seeing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...I swear I had some. But you're right, updated.
Required bool | ||
} | ||
|
||
func GetTemplateData(fileName string) (TemplateData, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't actually being called anywhere but the tests yet, but I was hacking into main.go
and passing in the file name to test it out locally. will work on actually calling this in a generate file in a follow up PR.
cmd/resources/gen_resources.go
Outdated
type ResourceData struct { | ||
Name string | ||
Description string | ||
Operations map[string]*OperationData |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's probably not strictly necessary to have these as a map[string]*OperationData
vs []*OperationData
but it was helpful for pulling out a specific op type for testing.
cmd/resources/gen_resources.go
Outdated
) | ||
|
||
type TemplateData struct { | ||
Resources map[string]*ResourceData |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make these values instead of pointers? If we need to check for nil later we could either use
resources, ok := resources[tag]
or something like
// IsZero is true if this is a zero value struct type.
func (r ResourceData) IsZero() bool {
return r.Name == "" && r.Description == "" && r.Operations == nil
}
if resource.IsZero() {
// ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup!
err = json.Unmarshal(expectedFromFile, &expected) | ||
require.NoError(t, err) | ||
|
||
t.Run("succeeds with single get resource", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not getting test failures when running go test ./cmd/resources/ -run TestGetTemplateData -count=100
after changing the test to
t.Run("succeeds with single get resource", func(t *testing.T) {
assert.Equal(t, expected, actual)
})
What failures were you seeing?
cmd/resources/gen_resources.go
Outdated
// probably won't need to keep this logging in but leaving it for debugging purposes | ||
log.Printf("No response type defined for %s", op.OperationID) | ||
} else { | ||
for propName, _ := range schema.Value.Properties { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get a lint warning that this could be simplified to for propName := range
.
Adds a function that reads and parses an OpenAPI spec into our desired resources/operations data structs - for now it works with just the teams data (added that json temporarily at
ld-teams-openapi.json
to run locally).Note: this new method isn't actually being called anywhere yet, but you can test this locally with the file above ☝️