Skip to content

Commit

Permalink
Update OpenAPI-related files
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Phoen committed Oct 5, 2023
1 parent 7f7145f commit b6aa350
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/cli/loaders/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/grafana/cog/internal/openapi"
)

func openapiLoader(opts Options) ([]*ast.File, error) {
allSchemas := make([]*ast.File, 0, len(opts.OpenAPIEntrypoints))
func openapiLoader(opts Options) ([]*ast.Schema, error) {
allSchemas := make([]*ast.Schema, 0, len(opts.OpenAPIEntrypoints))
for _, entrypoint := range opts.OpenAPIEntrypoints {
pkg := filepath.Base(filepath.Dir(entrypoint))
schemaAst, err := openapi.GenerateAST(entrypoint, openapi.Config{
Expand Down
8 changes: 4 additions & 4 deletions internal/openapi/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type Config struct {
}

type generator struct {
file *ast.File
file *ast.Schema
}

func GenerateAST(filePath string, cfg Config) (*ast.File, error) {
func GenerateAST(filePath string, cfg Config) (*ast.Schema, error) {
loader := openapi3.NewLoader()
oapi, err := loader.LoadFromFile(filePath)
if err != nil {
Expand All @@ -42,7 +42,7 @@ func GenerateAST(filePath string, cfg Config) (*ast.File, error) {
}

g := &generator{
file: &ast.File{Package: cfg.Package},
file: &ast.Schema{Package: cfg.Package},
}

if oapi.Components == nil {
Expand All @@ -63,7 +63,7 @@ func (g *generator) declareDefinition(schemas openapi3.Schemas) error {
return err
}

g.file.Definitions = append(g.file.Definitions, ast.Object{
g.file.Objects = append(g.file.Objects, ast.Object{
Name: name,
Comments: schemaComments(schemaRef.Value),
Type: def,
Expand Down
12 changes: 6 additions & 6 deletions internal/openapi/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func TestDataTypes(t *testing.T) {
f, err := GenerateAST(testFolder+"datatypes.json", Config{Package: "datatypes"})
require.NoError(t, err)

require.Len(t, f.Definitions, 1)
require.Len(t, f.Objects, 1)

def := f.Definitions[0]
def := f.Objects[0]
assert.Equal(t, def.Name, "DataTypes")
assert.Equal(t, def.Type.Kind, ast.KindStruct)

Expand Down Expand Up @@ -74,9 +74,9 @@ func TestEnums(t *testing.T) {
f, err := GenerateAST(testFolder+"enums.json", Config{Package: "enums"})
require.NoError(t, err)

require.Len(t, f.Definitions, 1)
require.Len(t, f.Objects, 1)

def := f.Definitions[0]
def := f.Objects[0]
assert.Equal(t, def.Name, "Enums")
assert.Equal(t, def.Type.Kind, ast.KindStruct)

Expand Down Expand Up @@ -145,7 +145,7 @@ func TestArrays(t *testing.T) {
f, err := GenerateAST(testFolder+"arrays.json", Config{Package: "arrays"})
require.NoError(t, err)

require.Len(t, f.Definitions, 2)
require.Len(t, f.Objects, 2)
def := f.LocateDefinition("Arrays")
assert.Equal(t, def.Type.Kind, ast.KindStruct)

Expand Down Expand Up @@ -183,7 +183,7 @@ func TestRefs(t *testing.T) {
f, err := GenerateAST(testFolder+"refs.json", Config{Package: "refs"})
require.NoError(t, err)

require.Len(t, f.Definitions, 2)
require.Len(t, f.Objects, 2)
def := f.LocateDefinition("Refs")
assert.Equal(t, def.Type.Kind, ast.KindStruct)

Expand Down

0 comments on commit b6aa350

Please sign in to comment.