Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Conversation

@zbiljic
Copy link
Contributor

@zbiljic zbiljic commented Jun 27, 2022

The change adds support option that trims enum name prefix from enum values.

This is for the case when the proto file is written according to Google Protobuf Style Guide recommendation. This suggest prefixing enum values instead of surrounding them in an enclosing message.
Example:

enum FooBar {
  FOO_BAR_UNSPECIFIED = 0;
  FOO_BAR_FIRST_VALUE = 1;
  FOO_BAR_SECOND_VALUE = 2;
}

When this new option is enabled, it will produce something like this:

"enum": [
    "UNSPECIFIED",
    "FIRST_VALUE",
    "SECOND_VALUE"
],

NOTE: There is one additional commit which is related to imports. The make fmt command changes existing imports, but I decided on a separate commit because it would seem it was not run before (maybe for some reason).

Also, when running make fmt on existing code, it changes one additional file, generated options.pb.go, which should not be modified, but it seems like goimport tool does not ignore generated files. I would suggest updating command call to something like this:

@goimports -w -local github.com/chrusty/protoc-gen-jsonschema $(shell find . -type f -name '*.go' -not -path "./internal/protos/*")

P.S.
Sorry for not opening an issue first. I figured this was small change and would be fine to just create pull request for.

@chrusty chrusty self-assigned this Jun 28, 2022
@chrusty chrusty self-requested a review June 28, 2022 19:56
Copy link
Owner

@chrusty chrusty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @zbiljic, and thanks for this PR! I appreciate the effort you've made to fit in with this weird framework i've got here of flags, options, and unit tests.

The change looks good to me, and I'll be happy to merge this in - I would just request a few extra comments around where the logic is injected in converter.go (it will make it easier for people working on this file in the future).

@zbiljic zbiljic force-pushed the feature/enums_trim_prefix branch from e7c05b9 to 011ba6f Compare June 29, 2022 10:51
@chrusty chrusty merged commit fb6570f into chrusty:master Jun 29, 2022
@chrusty
Copy link
Owner

chrusty commented Jun 29, 2022

Thank you @zbiljic - nice PR. I've merged this and made a new release.

Thanks for your interest in the project too!

@zbiljic
Copy link
Contributor Author

zbiljic commented Jun 30, 2022

Thanks for this, and this project.

I do have plans to use it actively, and might have some additional changes soon.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants