Skip to content

Commit

Permalink
optionally include descriptions in schema
Browse files Browse the repository at this point in the history
  • Loading branch information
puertomontt committed Sep 11, 2024
1 parent 80d0264 commit 8e242cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
18 changes: 12 additions & 6 deletions codegen/collector/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,20 @@ func (o *OpenApiProtocExecutor) Execute(protoFile string, toFile string, imports
directoryPath := filepath.Join(o.OutputDir, directoryName)
_ = os.Mkdir(directoryPath, os.ModePerm)

cmd.Args = append(cmd.Args,
fmt.Sprintf("--openapi_out=yaml=true,single_file=false,include_description=true,multiline_description=true,enum_as_int_or_string=%v,proto_oneof=true,int_native=true,additional_empty_schema=%v,disable_kube_markers=%v:%s",
o.EnumAsIntOrString,
strings.Join(o.MessagesWithEmptySchema, "+"),
o.DisableKubeMarkers,
directoryPath),
args := fmt.Sprintf("--openapi_out=yaml=true,single_file=false,multiline_description=true,enum_as_int_or_string=%v,proto_oneof=true,int_native=true,additional_empty_schema=%v,disable_kube_markers=%v",
o.EnumAsIntOrString,
strings.Join(o.MessagesWithEmptySchema, "+"),
o.DisableKubeMarkers,
)

if !o.IncludeDescriptionsInSchema {
args += ",include_description=false"
}

args = fmt.Sprintf("%s:%s", args, directoryPath)

cmd.Args = append(cmd.Args, args)

cmd.Args = append(cmd.Args,
"-o",
toFile,
Expand Down
3 changes: 3 additions & 0 deletions codegen/proto/schemagen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const (
)

type ValidationSchemaOptions struct {
// Whether to include descriptions in validation schemas
IncludeDescriptionsInSchema bool

// Whether to assign Enum fields the `x-kubernetes-int-or-string` property
// which allows the value to either be an integer or a string
// If this is false, only string values are allowed
Expand Down
9 changes: 5 additions & 4 deletions codegen/proto/schemagen/protoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ func (p *protocGenerator) GetJSONSchemas(protoFiles []string, imports []string,

// The Executor used to compile protos
protocExecutor := &collector.OpenApiProtocExecutor{
OutputDir: tmpOutputDir,
EnumAsIntOrString: p.validationSchemaOptions.EnumAsIntOrString,
MessagesWithEmptySchema: p.validationSchemaOptions.MessagesWithEmptySchema,
DisableKubeMarkers: p.validationSchemaOptions.DisableKubeMarkers,
OutputDir: tmpOutputDir,
EnumAsIntOrString: p.validationSchemaOptions.EnumAsIntOrString,
MessagesWithEmptySchema: p.validationSchemaOptions.MessagesWithEmptySchema,
DisableKubeMarkers: p.validationSchemaOptions.DisableKubeMarkers,
IncludeDescriptionsInSchema: p.validationSchemaOptions.IncludeDescriptionsInSchema,
}

// 1. Generate the openApiSchemas for the project, writing them to a temp directory (schemaOutputDir)
Expand Down

0 comments on commit 8e242cf

Please sign in to comment.