Skip to content

Commit 8e242cf

Browse files
committed
optionally include descriptions in schema
1 parent 80d0264 commit 8e242cf

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

codegen/collector/executor.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,20 @@ func (o *OpenApiProtocExecutor) Execute(protoFile string, toFile string, imports
108108
directoryPath := filepath.Join(o.OutputDir, directoryName)
109109
_ = os.Mkdir(directoryPath, os.ModePerm)
110110

111-
cmd.Args = append(cmd.Args,
112-
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",
113-
o.EnumAsIntOrString,
114-
strings.Join(o.MessagesWithEmptySchema, "+"),
115-
o.DisableKubeMarkers,
116-
directoryPath),
111+
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",
112+
o.EnumAsIntOrString,
113+
strings.Join(o.MessagesWithEmptySchema, "+"),
114+
o.DisableKubeMarkers,
117115
)
118116

117+
if !o.IncludeDescriptionsInSchema {
118+
args += ",include_description=false"
119+
}
120+
121+
args = fmt.Sprintf("%s:%s", args, directoryPath)
122+
123+
cmd.Args = append(cmd.Args, args)
124+
119125
cmd.Args = append(cmd.Args,
120126
"-o",
121127
toFile,

codegen/proto/schemagen/generator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const (
88
)
99

1010
type ValidationSchemaOptions struct {
11+
// Whether to include descriptions in validation schemas
12+
IncludeDescriptionsInSchema bool
13+
1114
// Whether to assign Enum fields the `x-kubernetes-int-or-string` property
1215
// which allows the value to either be an integer or a string
1316
// If this is false, only string values are allowed

codegen/proto/schemagen/protoc.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ func (p *protocGenerator) GetJSONSchemas(protoFiles []string, imports []string,
4040

4141
// The Executor used to compile protos
4242
protocExecutor := &collector.OpenApiProtocExecutor{
43-
OutputDir: tmpOutputDir,
44-
EnumAsIntOrString: p.validationSchemaOptions.EnumAsIntOrString,
45-
MessagesWithEmptySchema: p.validationSchemaOptions.MessagesWithEmptySchema,
46-
DisableKubeMarkers: p.validationSchemaOptions.DisableKubeMarkers,
43+
OutputDir: tmpOutputDir,
44+
EnumAsIntOrString: p.validationSchemaOptions.EnumAsIntOrString,
45+
MessagesWithEmptySchema: p.validationSchemaOptions.MessagesWithEmptySchema,
46+
DisableKubeMarkers: p.validationSchemaOptions.DisableKubeMarkers,
47+
IncludeDescriptionsInSchema: p.validationSchemaOptions.IncludeDescriptionsInSchema,
4748
}
4849

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

0 commit comments

Comments
 (0)