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

Add custom option (similar to hidden) that lets user specify specific required fields #76

Closed
clementdoordash opened this issue Sep 17, 2021 · 5 comments
Assignees

Comments

@clementdoordash
Copy link

clementdoordash commented Sep 17, 2021

Currently required is all or nothing for proto3 syntax. Would be really helpful to have a custom option that let's us specify if a single attirbute is required in json.

message RequiredFields {
    string not_required = 1 [(protoc.gen.jsonschema.required) = false];
    string required = 2 [(protoc.gen.jsonschema.required) = true];
    string default_not_required = 3; // by default proto3 is not required
}
@chrusty
Copy link
Owner

chrusty commented Sep 18, 2021

Hey @clementdoordash, thanks for raising this.

OK, I guess this means that you've already tried the new hidden / ignore option?

Implementing this "required" logic using another proto option shouldn't be too much of a hassle. I'll take a look and hopefully get something implemented for you to try soon.

@chrusty chrusty self-assigned this Sep 18, 2021
@chrusty
Copy link
Owner

chrusty commented Sep 18, 2021

Have a look at the new release https://github.com/chrusty/protoc-gen-jsonschema/releases/tag/1.0.5

Hopefully this does what you need!

@chrusty chrusty closed this as completed Sep 18, 2021
@clementdoordash
Copy link
Author

Yes! That's exactly it. Thank you :).

@chrusty
Copy link
Owner

chrusty commented Sep 20, 2021

I'm glad this is working as expected. Like I said, easy enough to implement.

I would like to point out that I have done this in quite a messy way, and have some work in the pipeline to tidy up how these custom options are presented and interpreted. I've also applied for an official options number in the protobuf repo.

It means that in a future release you will have to use the protoc-gen-jsonschema options.proto in a slightly different way, but it shouldn't be a huge change for you. Just a heads up.

@chrusty
Copy link
Owner

chrusty commented Sep 21, 2021

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants