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

Add new Json schema properties #5

Merged
merged 2 commits into from
Aug 31, 2019

Conversation

imIfOu
Copy link
Contributor

@imIfOu imIfOu commented Aug 30, 2019

feat: add "default" value properties
feat: add "required" properties
feat: add resolve metadata
conf: add more rules in gitignore

z17fdidi and others added 2 commits August 30, 2019 14:29
feat: add "required" properties
feat: add resolve metadata
conf: add more rules in gitignore
@imIfOu
Copy link
Contributor Author

imIfOu commented Aug 30, 2019

Hello,

If you want more details on the use of this new properties, you can check my module.

Best regards,

Copy link
Member

@CarstenWickner CarstenWickner left a comment

Choose a reason for hiding this comment

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

Hi @FlorianDidier,

I like the idea of properly supporting the "required" and "default" attributes.
I'm not a fan of the generic "metaData" though since this kind of generic addition of attributes to a field or method is already supported via SchemaGeneratorConfigPart.withInstanceAttributeOverride().

E.g. in your module-addon project, you'd only have to:

  • replace the .withMetadata(this::resolveMetadata) call with .withInstanceAttributeOverride(this::resolveMetadata) and
  • change the resolveMetadata() method to this:
protected void resolveMetadata(ObjectNode jsonSchemaAttributesNode, MemberScope<?, ?> member) {
    this.getAnnotationFromFieldOrGetter(member, JsonSchema.class)
            .map(JsonSchema::metadata)
            .ifPresent(metaData -> Stream.of(metaData)
                    .filter(data -> !data.key().isEmpty())
                    .filter(data -> !data.value().isEmpty())
                    .forEach(data -> jsonSchemaAttributesNode.put(data.key(), data.value())));
}

That way you could theoretically also add the "required" and "default" attributes yourself already, but since those are standard attributes I like your proposed solution of supporting them specifically.

To summarise: after removing the changes related to the meta-data handling and cleaning-up some of the unnecessary style/import changes, I'm happy to merge this PR.

Thank you very much for your input. 👍

######################
# Gradle
######################
.gradle/**
Copy link
Member

Choose a reason for hiding this comment

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

There is no Gradle in this project, but I like the idea of catering for more IDEs out-of-the-box.

import java.lang.reflect.Method;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Copy link
Member

Choose a reason for hiding this comment

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

We seem to have different configurations for the order of imports. 😉
I'd rather be consistent throughout the project and not include those order changes here.

* @param format attribute value to set
* @return this instance (for chaining)
*/
public AttributeCollector setDefault(ObjectNode node, String format) {
Copy link
Member

Choose a reason for hiding this comment

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

"format" as the variable name is a bit confusing to me here. it is the "defaultValue".

@CarstenWickner CarstenWickner changed the base branch from master to additional-properties August 31, 2019 19:25
@CarstenWickner CarstenWickner merged commit 888db02 into victools:additional-properties Aug 31, 2019
@CarstenWickner
Copy link
Member

I like the general idea. I'll do the clean-ups myself and share the new PR (against the "master" branch) with you then.

CarstenWickner pushed a commit that referenced this pull request Aug 31, 2019
feat: add "default" value properties
feat: add "required" properties
feat: add resolve metadata
conf: add more rules in gitignore
@CarstenWickner
Copy link
Member

@FlorianDidier the support for the new "required" and "default" properties (together with the general support of the "pattern" property) have been released now as v3.2.0.

As per my previous comment, I removed the proposed addition of a "metaData" map, as the existing SchemaGeneratorConfigPart.withInstanceAttributeOverride() does already support that (and more).

Thank you for your contribution!

@imIfOu imIfOu deleted the valid_master branch September 2, 2019 07:25
@CarstenWickner CarstenWickner added the enhancement New feature or request label Sep 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

None yet

2 participants