jsonschema-generator icon indicating copy to clipboard operation
jsonschema-generator copied to clipboard

Scanner SubTypesScanner was not configured

Open clemi2408 opened this issue 6 years ago • 39 comments

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:

<classNames>
    <className>model.entity.user.User</className>
    <className>model.entity.group.Group</className>
</classNames>

if i want to use it like this:

<packageNames>
    <packageName>mode</packageName>
</packageNames>

i get an exception from

org.reflections

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

clemi2408 avatar May 28 '20 14:05 clemi2408

Hi Clem,

I will try to reproduce your problem and come up with a solution.

Regards,

Jan

JanLabrie avatar May 28 '20 14:05 JanLabrie

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

JanLabrie avatar May 28 '20 16:05 JanLabrie

Hey coool! Thanks for that quick support! Hope the branch is merged soon and the plugin available on Central.

Another thing/feature: Have you thought about include- and exclude (Regex/glob) pattern for further filtering? Regards and thank you Clem

clemi2408 avatar May 28 '20 18:05 clemi2408

  1. @JanLabrie thanks for taking this on. I wouldn't have had time for it.
  2. @clemi2408 Jan's fix has been merged v4.12.1 has been released. It may take a few hours until it has been propagated through the various Maven repositories.
  3. We're open to additional ideas. Feel free to create a PR for Jan and me to take a look.

CarstenEnglert avatar May 28 '20 19:05 CarstenEnglert

Issue still not fixed :(

Failed to execute goal com.github.victools:jsonschema-maven-plugin:4.12.1:generate (default) on project schemafuck: Execution default of goal com.github.victools:jsonschema-maven-plugin:4.12.1:generate failed: Scanner SubTypesScanner was not configured

clemi2408 avatar May 29 '20 09:05 clemi2408

Mmmmm...not good. It worked for me. :-)

I will investigate and get back to you.

JanLabrie avatar May 29 '20 09:05 JanLabrie

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

JanLabrie avatar May 29 '20 14:05 JanLabrie

Hey Jan, sorry for the late response - had to switch out the device over the weekend :-/ Here is the part of my maven pom:

            <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? Regards Clem

clemi2408 avatar Jun 02 '20 05:06 clemi2408

Thanks for the content. I will have a look at it.

JanLabrie avatar Jun 02 '20 18:06 JanLabrie

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

JanLabrie avatar Jun 02 '20 18:06 JanLabrie

There are files in that path. But these files are in the target folder because they are generated out of xsds. If i reference them directly by class name they are resolvable. But maybe there is an issue in class path scanning in relation to the target folder?

clemi2408 avatar Jun 05 '20 09:06 clemi2408

How can i support you?

clemi2408 avatar Jun 05 '20 09:06 clemi2408

This might just be a timing issue then. Can you check in what Maven build phase the code generation occurs? If that happens only after the schema generation, you know why it’s not finding anything.

CarstenEnglert avatar Jun 05 '20 10:06 CarstenEnglert

Might be possible but to be honest i dont believe in that assumption. This is based on the fact that its working using this:

<classNames>
  <className>model.entity.user.User</className>
</classNames>

clemi2408 avatar Jun 05 '20 12:06 clemi2408

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.

CarstenEnglert avatar Jun 05 '20 14:06 CarstenEnglert

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:

model.dto.OneOfYourClasses

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 [email protected]:

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 https://github.com/victools/jsonschema-generator/issues/102#issuecomment-639503968, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPRADAOC4TYBC4LK5JGBIDRVD3GJANCNFSM4NNEICFQ . [image: image.gif]

JanLabrie avatar Jun 05 '20 14:06 JanLabrie

Hi guys, have created github repo and invited you two. Dont be scared, i try to do some stunts with that project:

Input:

  1. XSD
  2. OpenApi def (without datatypes)

Output:

  1. Json Schema
  2. Complete OpenAPI file

Its WIP regards Clem

clemi2408 avatar Jun 05 '20 14:06 clemi2408

Hi Clem,

Thank you for providing the reproduction repo. It indeed builds successfully by default, and when I enable the <packageNames> it starts failing.

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: import model.dto.UserDTO Which can not be resolved.

Can you please clarify where the model.dto classes are?

Thank you!

Jan

JanLabrie avatar Jun 05 '20 15:06 JanLabrie

hey, look, if i execute mvn compile they get stored here: Bildschirmfoto 2020-06-05 um 17 51 24

clemi2408 avatar Jun 05 '20 15:06 clemi2408

Aha...When I remove the <packageNames> element, the model.dto classes are generated.

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

JanLabrie avatar Jun 05 '20 15:06 JanLabrie