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 rules to generate java code from json schema #94

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

shahzaibj
Copy link
Contributor

@shahzaibj shahzaibj commented May 28, 2021

Adding a new module that contains a rule factory to generate java code from json schemas. This is primarily needed for our upcoming broker project. See PR here: https://github.com/AzureAD/ad-accounts-for-android/pull/1573

That project is using jsonschema2pojo for doing code generation and in this module we have added some rules that will let us customize the code generation per our reads. Please read more details in this document here.

This package is published and consumed that way as a buildscript dependency. We only need to publish this package to the internal maven. It is already published here

@shahzaibj shahzaibj self-assigned this May 28, 2021
@shahzaibj shahzaibj changed the title [WIP] add json rules Add rules to generate java code from json schema Jun 2, 2021
@shahzaibj shahzaibj marked this pull request as ready for review June 2, 2021 23:04
@shahzaibj shahzaibj requested a review from a team as a code owner June 2, 2021 23:04
@rpdome
Copy link
Member

rpdome commented Jun 7, 2021

do we need to onboard android-complete to the governance tool? (either that, or find another way to get a 3rd party library approval).

from components.java

pom {
name = 'common4j'
Copy link
Member

Choose a reason for hiding this comment

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

common4j?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy paste 😁 I'll fix it

}

java {
sourceCompatibility = JavaVersion.VERSION_1_7
Copy link
Member

Choose a reason for hiding this comment

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

not related to this PR, but we probably want to make this a variable (in the versioning file, to be consumed by everyone) at some point - if possible.

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....I've also done some work here in the plugin as well...to accept any Java version as opposed to just toggling between 7 & 8

It is in-progress here: #95 (mostly complete...just need to add javadocs before I make it live)

* Map data type if the type of the field in schema was defined as an "object" AND the field did not
* have any properties on it. Otherwise, this rule will just delegate the operation to its parent.
*/
public class AuthClientJsonSchemaTypeRule extends TypeRule {
Copy link
Member

Choose a reason for hiding this comment

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

I think putting some example here might help. it's pretty hard to see the whole picture tbh.

Copy link
Member

Choose a reason for hiding this comment

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

Or... maybe write tests/ add samples with a 'generic' json that this plugin supports. (i.e. this seems to be looking for "properties", but wouldn't support any other nested tags)

* A {@link RuleFactory} that provides a custom implementation of the {@link org.jsonschema2pojo.rules.TypeRule}
* and also provides an additional {@link MapRule} as well.
*/
public class AuthClientJsonSchemaRuleFactory extends RuleFactory {
Copy link
Member

@rpdome rpdome Jun 7, 2021

Choose a reason for hiding this comment

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

nit, add a brief comment on what is typerule, and objectrule.

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.

2 participants