-
Notifications
You must be signed in to change notification settings - Fork 56
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
Scanner SubTypesScanner was not configured #102
Comments
Hi Clem, I will try to reproduce your problem and come up with a solution. Regards, Jan |
Hi Clem, I have found and solved the issue. It was related to the setting of the proper classpath. I will make a branch with the fix and discuss with Carsten about releasing. Regards, Jan |
Hey coool! Another thing/feature: Have you thought about include- and exclude (Regex/glob) pattern for further filtering? |
|
Issue still not fixed :(
|
Mmmmm...not good. It worked for me. :-) I will investigate and get back to you. |
Clem, I retried with the official release 4.12.1 and in my project I am able to generate schema's for a package. Would it possible to share your setup, so I can examine it? Jan |
Hey Jan, <plugin>
<groupId>com.github.victools</groupId>
<artifactId>jsonschema-maven-plugin</artifactId>
<version>${victool-json-schema-generator-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- <packageNames>
<packageName>model.dto</packageName>
</packageNames>-->
<classNames>
<className>model.entity.group.Group</className>
<className>model.entity.user.User</className>
</classNames>
<schemaVersion>DRAFT_2019_09</schemaVersion>
<schemaFileName>{0}.json</schemaFileName>
<schemaFilePath>${schema.json.folder}</schemaFilePath>
<options>
<enabled>
<option>DEFINITIONS_FOR_ALL_OBJECTS</option>
<option>NULLABLE_FIELDS_BY_DEFAULT</option>
<option>FORBIDDEN_ADDITIONAL_PROPERTIES_BY_DEFAULT</option>
<option>ADDITIONAL_FIXED_TYPES</option>
<option>DEFINITIONS_FOR_ALL_OBJECTS</option>
<option>PLAIN_DEFINITION_KEYS</option>
<option>ALLOF_CLEANUP_AT_THE_END</option>
</enabled>
</options>
<modules>
<module>
<name>Jackson</name>
<options>
<option>FLATTENED_ENUMS_FROM_JSONVALUE</option>
</options>
</module>
<module>
<name>JavaxValidation</name>
</module>
<module>
<name>Swagger15</name>
</module>
</modules>
</configuration>
<dependencies>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${javax-validation.version}</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger.annotations.version}</version>
</dependency>
</dependencies>
</plugin> U need something else? |
Thanks for the content. I will have a look at it. |
Hi Clem, I discovered that the Reflections library gives the error you mentioned in case it can not find any classes on the specified path. Can it be that you do not have any class files in the model.dto package? It is difficult to understand the error message. I will investigate whether it can be made friendlier. Regards, Jan |
There are files in that path. |
How can i support you? |
This might just be a timing issue then. |
Might be possible but to be honest i dont believe in that assumption. <classNames>
<className>model.entity.user.User</className>
</classNames> |
Fair enough. Might still be a classloader issue when we look-up packages, that it somehow ignores generated class files. @clemi2408 if you have the capacity, it'd be great to have a minimal sample project somewhere to allow us to reproduce this locally while playing around with potential solutions. |
A reproduction set will definitly help. The classloader that is used to
load individual classes is also used for loading packages.
So we should investigate further to find the difference.
Besides the reproduction set it would be good if you could try to use the
class mechanism to one of your classes in model.dto
i.e:
<classNames>
<className>model.dto.OneOfYourClasses</className>
</classNames>
This way we know whether it is a generic classloader thing, i.e. model.dto
is not in the classpath, or that it is specifically related to the package
loading.
Regards,
Jan
Op vr 5 jun. 2020 16:02 schreef Carsten Wickner <notifications@github.com>:
… Fair enough. Might still be a classloader issue when we look-up packages,
that it somehow ignores generated class files.
@clemi2408 <https://github.com/clemi2408> if you have the capacity, it'd
be great to have a minimal sample project somewhere to allow us to
reproduce this locally while playing around with potential solutions.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#102 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABPRADAOC4TYBC4LK5JGBIDRVD3GJANCNFSM4NNEICFQ>
.
[image: image.gif]
|
Hi guys, Input:
Output:
Its WIP |
Hi Clem, Thank you for providing the reproduction repo. I am looking for the model.dto package that you mention in the pom. But I can not find it in the target folder, and neither are there any class files for the model.dto package. In the commented java code you write: Can you please clarify where the model.dto classes are? Thank you! Jan |
Aha...When I remove the This means it is an ordering issue. The json schema generator is invoked before the model.dto classes are generated. This is where we must look for the solution. Either generate the model.dto classes earlier, or the schema later. Jan |
i didnt get your point to be honest. its working, so it cant be a matter of order... |
Hi, It does not for me when you run I'll drop some extra info in a sec. Regards, Jan |
yep exactly if you refer to the classes directly (User and Group) they get generated. Can you explain why this is working when using and when using i think changing to does not change anything in the overall maven build order... or? |
Clem, I am out of time now. Will investigate further at a later time. Bye for now, Jan |
I had a brief look now as well and there seem to be at least two plugins configured to the
That means, the jsonschema-maven-plugin needs to be executed twice, which can be done via separate entries under <plugin>
<groupId>com.github.victools</groupId>
<artifactId>jsonschema-maven-plugin</artifactId>
<version>${victool-json-schema-generator-maven-plugin.version}</version>
<executions>
<execution>
<id>schemas-for-existing-sources</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<classNames>
<className>model.entity.group.Group</className>
<className>model.entity.user.User</className>
</classNames>
</configuration>
</execution>
<execution>
<id>schemas-for-generated-sources</id>
<phase>process-classes</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<packageNames>
<packageName>model.dto</packageName>
</packageNames>
</configuration>
</execution>
</executions>
<configuration>
<!-- common configurations for all executions go here -->
</configuration>
</plugin> With this setup, I can see that the My assumption right now is, that the output folder for the You might have to explicitly add the appropriate folder as source folder via yet another plugin as per this StackOverflow answer. Though the following did not do the trick for me (the source folder was added, but the classes weren't picked up). Just something to further investigate I guess: <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/openapi/schema</source>
</sources>
</configuration>
</execution>
</executions>
</plugin> |
Thanks for your quick response and the detailed explanation. But the solution works like this
Its planned to have two inputs: Solution should genereate: xsd—>pojo —> schema ( as there isnt a proper way to create xsd to json schema without intermediate pojos), delete all the intermediate classes (currently they are called entity) and after that generate from json schema and via the openapi file the end result, the spring delegates and model classes. Yes i know the example does it slightly different, but it was ment to show the error i am faced! Thanks for your great help and wish you a nice weekend! |
I don’t fully follow, but it sounds like nothing needs to be changed on this side of the fence then. 😉 |
Ya the key goal is to have full open api spec to generate models, spring Delegates and so on. Openapi specs consists out of the openapi stuff and refers to json schema payloads for requests and responses. So my input in the system is an open api spec without models (only with referenced) as the first half. The second half is the json schema part. As json schema to pojo generators do not support markup like annox is doing (lombok, hibernate stuff),so i am doing the stunt to define xsd for each model class, with annotations and xml restrictions in place and generate java classes with their annotations. These classes i convert to json schema (with all the validation stuff your cool plugin supports) and use this schema in the open api spec.. I know this is a huge stunt but just reflecting the fact that the xsd to json schema conversion plugins are not cool, due to the fact that json schema has Afaik nothing like annox to enrich pojos.... I know this is not nice at all but leads to a code gen approach that goes a little more into the contract and data governance way... If you have ideas, to improve or to reduce the huge stunt, lets have a call :-) |
... but still, why is the package scanner not working? Can you provide a readme.md example how this can work? |
In regards to generating an OpenAPI specification, there is already the option via
Since you're using the Maven Plugin, the above is not available to you. As to your sample project, I'm afraid I don't have the time to dive deeper into the investigation. And I cannot tell whether @JanLabrie has still some capacity. |
Thanks for the clarification. Maybe i change the generation to a console application. |
Well, the Maven Plugin can generate JSON Schemas out of a package in the way you did it – that is already documented in its README. The challenge you are encountering here is related to the fact that the classes in the targeted package are being generated just before the schema generation. I still believe they are simply not being added correctly to the plugin's classpath then. |
There is an issue. The following proves it: The following configuration will generate the Group schema directly as class and from the package:
The output is as follows:
Observation:
Conclusion: |
It is a weird problem. Feels like a bug in reflections. But we'll have to see. When you would ask Reflections for the content of the When you would ask for the content of the parent package The latter one does have model.entity.group.Group, where the first has not. My next step would be to debug into Reflections. But need to find some time. Any other suggestions? Jan |
Pffff...I found the problem. In case a class has a baseclass that is outside the scanned area, Reflections will not take it into account. The Group class extends BasicEntity, which is not in the model.entity,Group package. It is therefore excluded. So...that is the problem. I will sleep over the solution. :-) |
Ahh...why sleep?. I made a fix, tested it on the Clem's project and it works. The solution is not elegant, but it works. We'll have to discuss something better. But in the mean time I will make a PR so we have the issue fixed. Tomorrow. Bye. Jan |
Hi @clemi2408, Release v4.12.2 contains the latest fix provided by @JanLabrie. |
Hey, just a little message to say a BIG THANK YOU. I started to had that problem on totally unrelated lib upate (not in the scanned path, etc) and I think I would have never found the problem without that thread and that message in particular. So: thank you, you saved my day :) |
Hey,
first of all your jsonschema-generator is really great thing!
I love it!
I am jusing maven to generate json schemas out of my Pojo classes.
this works like a charm when using it like this:
if i want to use it like this:
i get an exception from
Caused by: org.reflections.ReflectionsException: Scanner SubTypesScanner was not configured
Can you explain how to configure the SubTypesScanner via maven?
Regards and Dankeschön
Clem
The text was updated successfully, but these errors were encountered: