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

Support transformation schema for XML #549

Merged
merged 13 commits into from
Nov 14, 2022
Merged

Support transformation schema for XML #549

merged 13 commits into from
Nov 14, 2022

Conversation

RVRhub
Copy link
Contributor

@RVRhub RVRhub commented Nov 10, 2022

The PR introduces XML transformer.
An example of usage

Faker faker = new Faker();
System.out.println(
    new XmlTransformer.XmlTransformerBuilder<Name>().pretty(true).build()
        .generate(faker.<Name>collection().suppliers(faker::name).maxLen(1).build(),
                Schema.of(field("root",() -> Arrays.asList(field("firstName", Name::firstName), field("username", Name::username))))));

Result:

<root>
    <firstName>Danial</firstName>
    <username>arden.little</username>
</root>

Comment on lines 204 to 205
worknumbers: [(715) 228-3360 x9556, (936) 907-6813 x7053]
cellphones: [410.609.5559, 1-720-415-7634, 786-631-7588]
Copy link
Collaborator

Choose a reason for hiding this comment

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

hm...
that's not good it should generate
like

name: Katharyn
lastname: Predovic
phones:
  worknumbers: 
     - (715) 228-3360 x9556
     - (936) 907-6813 x7053
  cellphones: 
     - 410.609.5559
     - 1-720-415-7634
     - 786-631-7588

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, you are right.

@codecov-commenter
Copy link

codecov-commenter commented Nov 10, 2022

Codecov Report

Merging #549 (904850b) into main (2015bcb) will decrease coverage by 0.04%.
The diff coverage is 92.13%.

@@             Coverage Diff              @@
##               main     #549      +/-   ##
============================================
- Coverage     92.66%   92.61%   -0.05%     
- Complexity     2374     2405      +31     
============================================
  Files           248      249       +1     
  Lines          4951     5040      +89     
  Branches        530      543      +13     
============================================
+ Hits           4588     4668      +80     
- Misses          241      246       +5     
- Partials        122      126       +4     
Impacted Files Coverage Δ
src/main/java/net/datafaker/formats/Xml.java 100.00% <ø> (ø)
.../net/datafaker/transformations/XmlTransformer.java 92.13% <92.13%> (ø)
...ker/idnumbers/pt/br/IdNumberGeneratorPtBrUtil.java 92.59% <0.00%> (-3.71%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@bodiam
Copy link
Contributor

bodiam commented Nov 12, 2022

@snuyanzin can this be merged?

Comment on lines 84 to 90
Field<IN, ?> content = Arrays.stream(attrs)
.filter(inField -> !isAttribute(inField.getName())).findFirst()
.orElse(null);
applyTag(input, sb, content, tag);
} else {
applyTag(input, sb, xmlNode, tag);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could a bit simpler like

Suggested change
Field<IN, ?> content = Arrays.stream(attrs)
.filter(inField -> !isAttribute(inField.getName())).findFirst()
.orElse(null);
applyTag(input, sb, content, tag);
} else {
applyTag(input, sb, xmlNode, tag);
}
xmlNode = Arrays.stream(attrs)
.filter(inField -> !isAttribute(inField.getName())).findFirst()
.orElse(null);
}
applyTag(input, sb, xmlNode, tag);

@snuyanzin
Copy link
Collaborator

in general lgtm
thanks for your contribution @RVRhub
there is just a nit comment
could you fix it please and then we will merge it?

@bodiam
Copy link
Contributor

bodiam commented Nov 14, 2022

Thanks for this change! Time to release I think!!

@bodiam bodiam merged commit 3272c82 into datafaker-net:main Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants