feat: generate teams operation data from openapi spec#226
Conversation
| 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.
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.
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.
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.
...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.
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.
| type ResourceData struct { | ||
| Name string | ||
| Description string | ||
| Operations map[string]*OperationData |
There was a problem hiding this comment.
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.
| ) | ||
|
|
||
| type TemplateData struct { | ||
| Resources map[string]*ResourceData |
There was a problem hiding this comment.
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() {
// ...
| 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.
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?
| // 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.
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.jsonto run locally).Note: this new method isn't actually being called anywhere yet, but you can test this locally with the file above ☝️