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

javaType : generate classes in subpackage of the target package #1089

Closed
ogerardin opened this issue Feb 18, 2020 · 6 comments
Closed

javaType : generate classes in subpackage of the target package #1089

ogerardin opened this issue Feb 18, 2020 · 6 comments

Comments

@ogerardin
Copy link

Suppose I generate my classes in target package com.example.

If I specify a javaType property of Foo, it will be generated as com.example.Foo, as expected.
However if I specify a javaType property of bar.Foo (with a dot), it will be generated as bar.Foo (i.e. in package bar).

To me it would make more sense to generate it in package com.example.bar.Foo, i.e. a subpackage of the target package. As it is now, if I want to generate classes in subpackages of the target package, I have to repeat the fully qualified package name in every javaType property. And of course if I want to change it I will have to change in all the places it is referenced...

If we want to preserve this behavior for compatibility and still allow generating classes in subpackages, I suggest we introduce the convention that if the javaType begins with a dot, it's considered relative to the target package.

For example:

  • javaType=bar.Foo -> generates class bar.Foo (same as current behavior)
  • javaType=.bar.Foo -> generates class com.example.bar.Foo

What do you think?

@ogerardin
Copy link
Author

I realize this has already been suggested here: #195 (comment)
but I can't figure out the status of this request. I'm using the Maven plugin v1.0.2 and it totally ignores if my javaType begins with a dot (it just strips it).

@ogerardin
Copy link
Author

#195 (comment) has been marked as closed by #1054, which was merged into master on Dec 12, 2019, while release 1.0.2 is from Jan 27, 2020.

Yet I get the same behavior whether I specify javaType=bar.Foo or javaType=.bar.Foo

What am I missing?

@ogerardin
Copy link
Author

(sorry for the monologue...)
So apparently the commit only handles the case where the javaType is not a qualified name (i.e. does not contain a dot) but it does not handle the case where it begins with a dot.
So my issue still stands :)

@dewthefifth
Copy link
Collaborator

dewthefifth commented Feb 19, 2020

What prevents you from declaring your javaType to be com.example.bar.Foo?

I guess this is just an enhancement request?

@ogerardin
Copy link
Author

ogerardin commented Feb 20, 2020

What prevents you from declaring your javaType to be com.example.bar.Foo?

Nothing, and that would work, but I shouldn't have to use com.example in the schema because it's a generation-time parameter. I want to be able to put the generated classes in subpackages of the target package, without knowing what it will be.

@joelittlejohn
Copy link
Owner

joelittlejohn commented Feb 20, 2020

Thanks @ogerardin. I have reopened #195.

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

No branches or pull requests

3 participants