Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace reflector configuration with Options struct and helper methods #9

Open
samlown opened this issue Feb 21, 2022 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@samlown
Copy link
Contributor

samlown commented Feb 21, 2022

The current Reflector struct should be replaced with a set of option functions provided at run time. This a more idiomatic approach and results in an immutable configuration for each reflection invocation.

The objective is to end up with something like this:

s := jsonschema.Reflect(TestUser{}, jsonschema.WithBaseSchemaID("https://example.com/schemas"))

Shared options can be assigned to an array:

opts = []jsonschema.Option{
  jsonschema.WithBaseSchemaID("https://example.com/schemas"),
  jsonschema.AllowAdditionalProperties(),
}
s := jsonschema.Reflect(TestUser{}, opts...)
@samlown samlown added the enhancement New feature or request label Feb 25, 2022
@charbonnierg
Copy link

charbonnierg commented Oct 31, 2023

Hi @samlown

I saw this PR and decided to give it a try. I've got a branch with options as described in this issue: main...charbonnierg:jsonschema:main.

One thing that I changed compared to your example is that I renamed AllowAdditionalProperties into WithAdditionalPropertiesAllowed because I prefer having all options starting with With, it makes life easier when using an IDE IMO 😅.

Would you like me to open a pull request ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants