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 0f19e96 commit 4caffe8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/openapi/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Config struct {
}

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

func GenerateAST(filePath string, cfg Config) (*ast.Schema, error) {
Expand All @@ -43,21 +43,21 @@ func GenerateAST(filePath string, cfg Config) (*ast.Schema, error) {
}

g := &generator{
file: &ast.Schema{
schema: &ast.Schema{
Package: cfg.Package,
Metadata: cfg.SchemaMetadata,
},
}

if oapi.Components == nil {
return g.file, nil
return g.schema, nil
}

if err := g.declareDefinition(oapi.Components.Schemas); err != nil {
return nil, err
}

return g.file, nil
return g.schema, nil
}

func (g *generator) declareDefinition(schemas openapi3.Schemas) error {
Expand All @@ -67,10 +67,14 @@ func (g *generator) declareDefinition(schemas openapi3.Schemas) error {
return err
}

g.file.Objects = append(g.file.Objects, ast.Object{
g.schema.Objects = append(g.schema.Objects, ast.Object{
Name: name,
Comments: schemaComments(schemaRef.Value),
Type: def,
SelfRef: ast.RefType{
ReferredPkg: g.schema.Package,
ReferredType: name,
},
})
}

Expand Down

0 comments on commit 4caffe8

Please sign in to comment.