Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions docs/dist/docs/guide/cli/generator/generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,9 @@ When managed mode is enabled, EasyP automatically applies file and field options
- Objective-C: `objc_class_prefix` defaults to first letters of package parts
- C++: `cc_enable_arenas` defaults to `true`

**Overrides** allow you to set specific values for options, with support for filtering by module, path, or field.
**Overrides** allow you to set specific values for options, with support for filtering by module, protobuf package, path, or field. Without `module`, `package`, or `path`, an override applies to all files in the generation request, including dependencies and `git_repo` inputs.

**Disables** allow you to prevent managed mode from modifying specific options or files.
**Disables** allow you to prevent managed mode from modifying specific options or files. This is the recommended way to exclude external dependencies that already define their own options.

### Configuration

Expand All @@ -590,6 +590,10 @@ generate:

# Disable specific option globally
- file_option: java_package_prefix

# Disable for specific protobuf package
- package: acme.weather.v1
file_option: java_package

# Disable for specific path
- path: legacy/
Expand All @@ -608,6 +612,11 @@ generate:
- file_option: java_package_prefix
value: com.mycompany
module: github.com/mycompany/internal-protos

# Override for specific protobuf package
- file_option: go_package_prefix
value: github.com/mycompany/myproject/gen/go
package: acme.weather.v1

# Override for specific path
- file_option: csharp_namespace_prefix
Expand Down Expand Up @@ -759,6 +768,26 @@ generate:
module: github.com/mycompany/internal-protos
```

`module` matches the EasyP module source exactly: the dependency or `git_repo.url` value before `@version` (for example `github.com/mycompany/internal-protos` or `https://github.com/mycompany/internal-protos`). It is not the Go module path from `go.mod`.

`package` matches the protobuf `package` declaration exactly, for example `acme.weather.v1`.

#### Package-Specific Overrides

Apply different options to files from a specific protobuf package:

```yaml
generate:
managed:
enabled: true
override:
- file_option: go_package_prefix
value: github.com/mycompany/myproject/gen/go
- file_option: go_package
package: acme.weather.v1
value: github.com/mycompany/myproject/gen/go/acme/weather/v1
```

#### Disabling for External Dependencies

Disable managed mode for external dependencies that already have their options set:
Expand Down
33 changes: 31 additions & 2 deletions docs/dist/docs/ru-guide/cli/generator/generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,9 @@ Managed mode автоматически устанавливает file и field
- Objective-C: `objc_class_prefix` по умолчанию первые буквы частей пакета
- C++: `cc_enable_arenas` по умолчанию `true`

**Overrides** позволяют установить конкретные значения для опций с поддержкой фильтрации по модулю, пути или полю.
**Overrides** позволяют установить конкретные значения для опций с поддержкой фильтрации по модулю, protobuf package, пути или полю. Если не указаны `module`, `package` и `path`, override применяется ко всем файлам в запросе генерации, включая зависимости и `git_repo` inputs.

**Disables** позволяют предотвратить изменение managed mode определённых опций или файлов.
**Disables** позволяют предотвратить изменение managed mode определённых опций или файлов. Это рекомендуемый способ исключить внешние зависимости, у которых свои опции уже заданы.

### Конфигурация

Expand All @@ -590,6 +590,10 @@ generate:

# Отключить конкретную опцию глобально
- file_option: java_package_prefix

# Отключить для конкретного protobuf package
- package: acme.weather.v1
file_option: java_package

# Отключить для конкретного пути
- path: legacy/
Expand All @@ -608,6 +612,11 @@ generate:
- file_option: java_package_prefix
value: com.mycompany
module: github.com/mycompany/internal-protos

# Переопределить для конкретного protobuf package
- file_option: go_package_prefix
value: github.com/mycompany/myproject/gen/go
package: acme.weather.v1

# Переопределить для конкретного пути
- file_option: csharp_namespace_prefix
Expand Down Expand Up @@ -759,6 +768,26 @@ generate:
module: github.com/mycompany/internal-protos
```

`module` должен точно совпадать с источником модуля в EasyP: это значение из `deps` или `git_repo.url` до `@version` (например, `github.com/mycompany/internal-protos` или `https://github.com/mycompany/internal-protos`). Это не Go module path из `go.mod`.

`package` должен точно совпадать со значением `package` в `.proto` файле, например `acme.weather.v1`.

#### Переопределения для конкретного protobuf package

Примените отдельные опции к файлам из конкретного protobuf package:

```yaml
generate:
managed:
enabled: true
override:
- file_option: go_package_prefix
value: github.com/mycompany/myproject/gen/go
- file_option: go_package
package: acme.weather.v1
value: github.com/mycompany/myproject/gen/go/acme/weather/v1
```

#### Отключение для внешних зависимостей

Отключите managed mode для внешних зависимостей, у которых уже установлены опции:
Expand Down
2 changes: 1 addition & 1 deletion docs/dist/search/index.en.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/dist/search/index.ru.json

Large diffs are not rendered by default.

33 changes: 31 additions & 2 deletions docs/public/docs/guide/cli/generator/generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,9 @@ When managed mode is enabled, EasyP automatically applies file and field options
- Objective-C: `objc_class_prefix` defaults to first letters of package parts
- C++: `cc_enable_arenas` defaults to `true`

**Overrides** allow you to set specific values for options, with support for filtering by module, path, or field.
**Overrides** allow you to set specific values for options, with support for filtering by module, protobuf package, path, or field. Without `module`, `package`, or `path`, an override applies to all files in the generation request, including dependencies and `git_repo` inputs.

**Disables** allow you to prevent managed mode from modifying specific options or files.
**Disables** allow you to prevent managed mode from modifying specific options or files. This is the recommended way to exclude external dependencies that already define their own options.

### Configuration

Expand All @@ -590,6 +590,10 @@ generate:

# Disable specific option globally
- file_option: java_package_prefix

# Disable for specific protobuf package
- package: acme.weather.v1
file_option: java_package

# Disable for specific path
- path: legacy/
Expand All @@ -608,6 +612,11 @@ generate:
- file_option: java_package_prefix
value: com.mycompany
module: github.com/mycompany/internal-protos

# Override for specific protobuf package
- file_option: go_package_prefix
value: github.com/mycompany/myproject/gen/go
package: acme.weather.v1

# Override for specific path
- file_option: csharp_namespace_prefix
Expand Down Expand Up @@ -759,6 +768,26 @@ generate:
module: github.com/mycompany/internal-protos
```

`module` matches the EasyP module source exactly: the dependency or `git_repo.url` value before `@version` (for example `github.com/mycompany/internal-protos` or `https://github.com/mycompany/internal-protos`). It is not the Go module path from `go.mod`.

`package` matches the protobuf `package` declaration exactly, for example `acme.weather.v1`.

#### Package-Specific Overrides

Apply different options to files from a specific protobuf package:

```yaml
generate:
managed:
enabled: true
override:
- file_option: go_package_prefix
value: github.com/mycompany/myproject/gen/go
- file_option: go_package
package: acme.weather.v1
value: github.com/mycompany/myproject/gen/go/acme/weather/v1
```

#### Disabling for External Dependencies

Disable managed mode for external dependencies that already have their options set:
Expand Down
33 changes: 31 additions & 2 deletions docs/public/docs/ru-guide/cli/generator/generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,9 @@ Managed mode автоматически устанавливает file и field
- Objective-C: `objc_class_prefix` по умолчанию первые буквы частей пакета
- C++: `cc_enable_arenas` по умолчанию `true`

**Overrides** позволяют установить конкретные значения для опций с поддержкой фильтрации по модулю, пути или полю.
**Overrides** позволяют установить конкретные значения для опций с поддержкой фильтрации по модулю, protobuf package, пути или полю. Если не указаны `module`, `package` и `path`, override применяется ко всем файлам в запросе генерации, включая зависимости и `git_repo` inputs.

**Disables** позволяют предотвратить изменение managed mode определённых опций или файлов.
**Disables** позволяют предотвратить изменение managed mode определённых опций или файлов. Это рекомендуемый способ исключить внешние зависимости, у которых свои опции уже заданы.

### Конфигурация

Expand All @@ -590,6 +590,10 @@ generate:

# Отключить конкретную опцию глобально
- file_option: java_package_prefix

# Отключить для конкретного protobuf package
- package: acme.weather.v1
file_option: java_package

# Отключить для конкретного пути
- path: legacy/
Expand All @@ -608,6 +612,11 @@ generate:
- file_option: java_package_prefix
value: com.mycompany
module: github.com/mycompany/internal-protos

# Переопределить для конкретного protobuf package
- file_option: go_package_prefix
value: github.com/mycompany/myproject/gen/go
package: acme.weather.v1

# Переопределить для конкретного пути
- file_option: csharp_namespace_prefix
Expand Down Expand Up @@ -759,6 +768,26 @@ generate:
module: github.com/mycompany/internal-protos
```

`module` должен точно совпадать с источником модуля в EasyP: это значение из `deps` или `git_repo.url` до `@version` (например, `github.com/mycompany/internal-protos` или `https://github.com/mycompany/internal-protos`). Это не Go module path из `go.mod`.

`package` должен точно совпадать со значением `package` в `.proto` файле, например `acme.weather.v1`.

#### Переопределения для конкретного protobuf package

Примените отдельные опции к файлам из конкретного protobuf package:

```yaml
generate:
managed:
enabled: true
override:
- file_option: go_package_prefix
value: github.com/mycompany/myproject/gen/go
- file_option: go_package
package: acme.weather.v1
value: github.com/mycompany/myproject/gen/go/acme/weather/v1
```

#### Отключение для внешних зависимостей

Отключите managed mode для внешних зависимостей, у которых уже установлены опции:
Expand Down
2 changes: 1 addition & 1 deletion docs/public/search/index.en.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/public/search/index.ru.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions internal/api/temporaly_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func convertManagedModeConfig(cfg config.ManagedMode) core.ManagedModeConfig {
Disable: lo.Map(cfg.Disable, func(r config.ManagedDisableRule, _ int) core.ManagedDisableRule {
return core.ManagedDisableRule{
Module: r.Module,
Package: r.Package,
Path: r.Path,
FileOption: core.FileOptionType(r.FileOption),
FieldOption: core.FieldOptionType(r.FieldOption),
Expand All @@ -173,6 +174,7 @@ func convertManagedModeConfig(cfg config.ManagedMode) core.ManagedModeConfig {
FieldOption: core.FieldOptionType(r.FieldOption),
Value: r.Value,
Module: r.Module,
Package: r.Package,
Path: r.Path,
Field: r.Field,
}
Expand Down
6 changes: 5 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func yamlNodeKind(kind yaml.Kind) string {
type ManagedDisableRule struct {
// Module disables managed mode for all files in the specified module.
Module string `json:"module,omitempty" yaml:"module,omitempty"`
// Package disables managed mode for all files in the specified protobuf package.
Package string `json:"package,omitempty" yaml:"package,omitempty"`
// Path disables managed mode for files matching the specified path (directory or file).
Path string `json:"path,omitempty" yaml:"path,omitempty"`
// FileOption disables a specific file option from being modified.
Expand All @@ -112,6 +114,8 @@ type ManagedOverrideRule struct {
Value any `json:"value,omitempty" yaml:"value,omitempty"`
// Module applies this override only to files in the specified module.
Module string `json:"module,omitempty" yaml:"module,omitempty"`
// Package applies this override only to files in the specified protobuf package.
Package string `json:"package,omitempty" yaml:"package,omitempty"`
// Path applies this override only to files matching the specified path.
Path string `json:"path,omitempty" yaml:"path,omitempty"`
// Field applies this override only to the specified field (fully qualified name).
Expand Down Expand Up @@ -314,7 +318,7 @@ func (m *ManagedMode) Validate() error {
// Validate validates a disable rule.
func (r *ManagedDisableRule) Validate() error {
// At least one field must be set
if r.Module == "" && r.Path == "" && r.FileOption == "" && r.FieldOption == "" && r.Field == "" {
if r.Module == "" && r.Package == "" && r.Path == "" && r.FileOption == "" && r.FieldOption == "" && r.Field == "" {
return errors.New("disable rule must have at least one field set")
}

Expand Down
41 changes: 41 additions & 0 deletions internal/config/managed_mode_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package config

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestParseConfig_ManagedModePackageSelectors(t *testing.T) {
content := `lint:
use:
- DIRECTORY_SAME_PACKAGE
generate:
inputs:
- directory: proto
plugins:
- name: go
out: .
managed:
enabled: true
disable:
- package: acme.weather.v1
file_option: java_package_prefix
override:
- file_option: go_package_prefix
package: acme.weather.v1
value: github.com/acme/gen/go
`

cfg, err := ParseConfig([]byte(content))
require.NoError(t, err)

require.Len(t, cfg.Generate.Managed.Disable, 1)
require.Equal(t, "acme.weather.v1", cfg.Generate.Managed.Disable[0].Package)
require.Equal(t, "java_package_prefix", cfg.Generate.Managed.Disable[0].FileOption)

require.Len(t, cfg.Generate.Managed.Override, 1)
require.Equal(t, "acme.weather.v1", cfg.Generate.Managed.Override[0].Package)
require.Equal(t, "go_package_prefix", cfg.Generate.Managed.Override[0].FileOption)
require.Equal(t, "github.com/acme/gen/go", cfg.Generate.Managed.Override[0].Value)
}
4 changes: 3 additions & 1 deletion internal/config/validate_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,13 @@ func buildSchema() *v.FieldSchema {
Type: v.TypeMap,
AllowedKeys: map[string]*v.FieldSchema{
"module": {Type: v.TypeString},
"package": {Type: v.TypeString},
"path": {Type: v.TypeString},
"file_option": {Type: v.TypeString},
"field_option": {Type: v.TypeString},
"field": {Type: v.TypeString},
},
AnyOf: [][]string{{"module"}, {"path"}, {"file_option"}, {"field_option"}, {"field"}},
AnyOf: [][]string{{"module"}, {"package"}, {"path"}, {"file_option"}, {"field_option"}, {"field"}},
MutuallyExclusive: []string{"file_option", "field_option"},
UnknownKeyPolicy: v.UnknownKeyWarn,
Validators: []v.ValueValidator{managedDisableValidator{}},
Expand All @@ -179,6 +180,7 @@ func buildSchema() *v.FieldSchema {
"field_option": {Type: v.TypeString},
"value": {Type: v.TypeAny, Required: true},
"module": {Type: v.TypeString},
"package": {Type: v.TypeString},
"path": {Type: v.TypeString},
"field": {Type: v.TypeString},
},
Expand Down
26 changes: 26 additions & 0 deletions internal/config/validate_raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,32 @@ breaking:
require.True(t, hasWarning, "expected warning for unknown key 'unknown_field' in breaking section, got: %v", issues)
}

func TestValidateRaw_ManagedModePackageSelectors(t *testing.T) {
content := `lint:
use:
- DIRECTORY_SAME_PACKAGE
generate:
inputs:
- directory: proto
plugins:
- name: go
out: .
managed:
enabled: true
disable:
- package: acme.weather.v1
file_option: java_package_prefix
override:
- file_option: go_package_prefix
package: acme.weather.v1
value: github.com/acme/gen/go
`

issues, err := ValidateRaw([]byte(content))
require.NoError(t, err)
require.False(t, HasErrors(issues), "package selector in managed mode should be valid, got: %v", issues)
}

func TestValidateRaw_DirectoryUnknownKey_NoDuplicate(t *testing.T) {
content := `version: v1alpha
lint:
Expand Down
Loading