diff --git a/changelog/v0.41.1/exclude-descriptions-in-schema.yaml b/changelog/v0.41.1/exclude-descriptions-in-schema.yaml new file mode 100644 index 00000000..f7f8dac7 --- /dev/null +++ b/changelog/v0.41.1/exclude-descriptions-in-schema.yaml @@ -0,0 +1,6 @@ +changelog: + - type: NEW_FEATURE + issueLink: https://github.com/solo-io/gloo-mesh-enterprise/issues/18562 + description: > + Add option to exclude descriptions in schema. + skipCI: "false" diff --git a/codegen/collector/compiler.go b/codegen/collector/compiler.go index 47f385a9..3cae3ce1 100644 --- a/codegen/collector/compiler.go +++ b/codegen/collector/compiler.go @@ -95,7 +95,7 @@ func (p *protoCompiler) CompileDescriptorsFromRoot(root string, skipDirs []strin sem = make(chan struct{}, maxProtocs) limitConcurrency = true } - for _, dir := range append([]string{root}) { + for _, dir := range []string{root} { absoluteDir, err := filepath.Abs(dir) if err != nil { return nil, err diff --git a/codegen/collector/executor.go b/codegen/collector/executor.go index 9b2b23fb..8acb41da 100644 --- a/codegen/collector/executor.go +++ b/codegen/collector/executor.go @@ -69,8 +69,8 @@ func (d *DefaultProtocExecutor) Execute(protoFile string, toFile string, imports type OpenApiProtocExecutor struct { OutputDir string - // Whether to include descriptions in validation schemas - IncludeDescriptionsInSchema bool + // Whether to include descriptions in schemas + ExcludeDescriptionsInSchema 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 @@ -108,11 +108,12 @@ func (o *OpenApiProtocExecutor) Execute(protoFile string, toFile string, imports _, fileName := filepath.Split(protoFile) directoryName := fileName[0 : len(fileName)-len(filepath.Ext(fileName))] - baseArgument := "--openapi_out=yaml=true,single_file=false,include_description=true,multiline_description=true,proto_oneof=true,int_native=true" + baseArgument := "--openapi_out=yaml=true,single_file=false,multiline_description=true,proto_oneof=true,int_native=true" baseArgument = fmt.Sprintf("%s,enum_as_int_or_string=%v", baseArgument, o.EnumAsIntOrString) baseArgument = fmt.Sprintf("%s,additional_empty_schema=%v", baseArgument, strings.Join(o.MessagesWithEmptySchema, "+")) baseArgument = fmt.Sprintf("%s,disable_kube_markers=%v", baseArgument, o.DisableKubeMarkers) baseArgument = fmt.Sprintf("%s,ignored_kube_marker_substrings=%v", baseArgument, strings.Join(o.IgnoredKubeMarkerSubstrings, "+")) + baseArgument = fmt.Sprintf("%s,include_description=%v", baseArgument, !o.ExcludeDescriptionsInSchema) // Create the directory directoryPath := filepath.Join(o.OutputDir, directoryName) diff --git a/codegen/proto/schemagen/protoc.go b/codegen/proto/schemagen/protoc.go index 458a4055..59fcf3ae 100644 --- a/codegen/proto/schemagen/protoc.go +++ b/codegen/proto/schemagen/protoc.go @@ -19,12 +19,14 @@ import ( // Implementation of JsonSchemaGenerator that uses a plugin for the protocol buffer compiler type protocGenerator struct { - validationSchemaOptions *ValidationSchemaOptions + validationSchemaOptions *ValidationSchemaOptions + excludeDescriptionsInSchema bool } -func NewProtocGenerator(validationSchemaOptions *ValidationSchemaOptions) *protocGenerator { +func NewProtocGenerator(validationSchemaOptions *ValidationSchemaOptions, excludeDescriptionsInSchema bool) *protocGenerator { return &protocGenerator{ - validationSchemaOptions: validationSchemaOptions, + validationSchemaOptions: validationSchemaOptions, + excludeDescriptionsInSchema: excludeDescriptionsInSchema, } } @@ -44,6 +46,7 @@ func (p *protocGenerator) GetJSONSchemas(protoFiles []string, imports []string, EnumAsIntOrString: p.validationSchemaOptions.EnumAsIntOrString, MessagesWithEmptySchema: p.validationSchemaOptions.MessagesWithEmptySchema, DisableKubeMarkers: p.validationSchemaOptions.DisableKubeMarkers, + ExcludeDescriptionsInSchema: p.excludeDescriptionsInSchema, IgnoredKubeMarkerSubstrings: p.validationSchemaOptions.IgnoredKubeMarkerSubstrings, } diff --git a/codegen/render/manifests_renderer.go b/codegen/render/manifests_renderer.go index 290973ed..64f40b6c 100644 --- a/codegen/render/manifests_renderer.go +++ b/codegen/render/manifests_renderer.go @@ -133,13 +133,13 @@ func (r ManifestsRenderer) RenderManifests(grps []*Group, protoOpts protoutil.Op func generateOpenApi(grp model.Group, protoDir string, protoOpts protoutil.Options, groupOptions model.GroupOptions) (model.OpenApiSchemas, error) { if groupOptions.SchemaGenerator == schemagen.ProtocGenOpenAPI { - return generateOpenApiFromProtocGen(grp, protoDir, protoOpts, groupOptions) + return generateOpenApiFromProtocGen(grp, groupOptions) } return generateOpenApiFromCue(grp, protoDir, protoOpts, groupOptions) } // Use protoc-gen-openapi for transpiling protobuf schemas to openapi v3 with k8s structural schema constraints. -func generateOpenApiFromProtocGen(grp model.Group, protoDir string, _ protoutil.Options, groupOptions model.GroupOptions) (model.OpenApiSchemas, error) { +func generateOpenApiFromProtocGen(grp model.Group, groupOptions model.GroupOptions) (model.OpenApiSchemas, error) { // Collect all protobuf definitions including transitive dependencies. var imports []string for _, fileDescriptor := range grp.Descriptors { @@ -152,7 +152,7 @@ func generateOpenApiFromProtocGen(grp model.Group, protoDir string, _ protoutil. for i, fileDescriptor := range grp.Descriptors { protoFiles[i] = fileDescriptor.ProtoFilePath } - protoGen := schemagen.NewProtocGenerator(&groupOptions.SchemaValidationOpts) + protoGen := schemagen.NewProtocGenerator(&groupOptions.SchemaValidationOpts, grp.SkipSchemaDescriptions) gvkSchemas, err := protoGen.GetJSONSchemas(protoFiles, imports, grp.GroupVersion) if err != nil { return nil, err