Skip to content

Loading…

Why models are not generated from 'inline' json schema #4

Open
santeriv opened this Issue · 18 comments

5 participants

@santeriv

See for reference 8006afd

#for testing the commit
git remote add santerivfork https://github.com/santeriv/raml-jaxrs-codegen.git
git fetch santerivfork
git cherry-pick -n 8006afd59e3d31ff4111abc134a7120a73f616ed
mvn clean package

Problems/?
1. Why some generated classes are empty ?
2. Why model generation is done only for referenced classes (ref <--> /offices /persons /organization ) ?
3. Why all model classes do not get generated ?

P.S. Commit contains schemaDirectory setting change (File globalStore change) which I am not so sure anymore that if it is needed with .json schema files which is partial workaround for this issue , I'll move it to other commit and update commit ids after that.

@santeriv

updated commit refs

@villuv

My poblem is most likely related to this. For a self contain test case, please check:
https://github.com/villuv/raml-codegen-test

This repo has three tags:

works - Working state, with a simple model and a get method
no_entity - Trying for post method, array of the same model bean, inline schema. Interface refers to anonymous model class, but the class is not generated
named_schema - The same, but going for named model bean for the array. Interface refers now to the correct name of the model class, but the class itself is not generated.

@renzok
@villuv

Thanks for the tip, but unfortunately this doesn't change the situation.
I now got completely rid of the resourceType definitions, so the raml file is pretty minimal now.
( https://github.com/villuv/raml-codegen-test/blob/7a93366d2bf122d52ac73f7aae8dac4a6a5a8253/src/main/resources/raml/test.raml )

Still the same behaviour...

@santeriv

I think @villuv 's problem is basically same yet even simpler. As my unit test code commit above concentrates on generated partial model java (classes) contents are missing.

@ddossot I saw a TODO related bug was fixed joelittlejohn/jsonschema2pojo#137 Could this be a remedy does this help for this problem, what do you think?

@ddossot

@santeriv is right: currently the generator can't correctly handle in-lined schemas because the actual class name generated by jsonschema2pojo is unknown of these types. The bug has been fixed in jsonschema2pojo so whenever it will be released, we will be able to improve the generator.

@villuv

We did some more testing here, and the problem is caused by having "type": "array" of the toplevel schema object, no new class name needed. Ideally code generator should generate just array of referenced type here, not a class. I have to check the code a bit to see what is going on there...

@santeriv

@ddossot 0.4.1 jsonschema2pojo-core is released

@ddossot

I've applied the code change to use the type return from jsonschema2pojo-core but, unfortunately, due to changes in the core RAML parser, I can't build the JAX-RS codegen anymore. Tests are failing when parsing a test RAML file so I can't commit my changes. I unfortunately don't have time now to investigate what have changed in the RAML parser that adversely affects the JAX-RS codegen, maybe someone else can?

@santeriv

@ddossot @svacas Is this the change needed 869149d ?

@ddossot ddossot added a commit to ddossot/raml-jaxrs-codegen that referenced this issue
@ddossot ddossot upgraded to jsonschema2pojo 0.4.1 in order to get actually generated …
…type, as an attempt to fix issue #4
175c60e
@ddossot

@santeriv This change is already in the codebase and addresses a compilation issue. The issue I'm facing happens at runtime and comes from the deep bowels of the RAML Java parser, with a very unclear description of the root cause:

java.lang.IllegalArgumentException: wrong number of arguments
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.raml.parser.builder.PojoTupleBuilder.buildValue(PojoTupleBuilder.java:95)
    at org.raml.parser.visitor.YamlDocumentBuilder.onScalar(YamlDocumentBuilder.java:209)
    at org.raml.parser.visitor.NodeVisitor.visitScalar(NodeVisitor.java:256)
    at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:222)
    at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180)
    at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151)
    at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86)
    at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218)
    at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180)
    at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151)
    at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86)
    at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218)
    at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180)
    at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151)
    at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86)
    at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218)
    at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180)
    at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151)
    at org.raml.parser.visitor.NodeVisitor.visitDocument(NodeVisitor.java:209)
    at org.raml.parser.visitor.YamlDocumentBuilder.build(YamlDocumentBuilder.java:87)
    at org.raml.parser.visitor.YamlDocumentBuilder.build(YamlDocumentBuilder.java:99)
    at org.raml.jaxrs.codegen.core.Generator.run(Generator.java:115)
    at org.raml.jaxrs.codegen.core.GeneratorTestCase.run(GeneratorTestCase.java:97)
    at org.raml.jaxrs.codegen.core.GeneratorTestCase.runForJaxrs11WithoutJsr303(GeneratorTestCase.java:64)
        ...

BTW My attempt to fix this issue is accessible in my fork: ddossot@175c60e

@svacas

@ddossot I've applied the changes in your fork locally and all tests are passing. Is there an specific RAML that is failing for you?

@santeriv

@svacas could you please cherrypick 8006afd and try if now the test pass and are generated models not empty?

@svacas

@santeriv the test is failing with this error:

java.lang.ClassNotFoundException: org.raml.jaxrs.test.model.Person
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at org.raml.jaxrs.codegen.core.GeneratorTestCase.testGenereratorWithRamlHavingSomeSchemaRefs(GeneratorTestCase.java:208)
    ...
@ddossot

I've spent more time on this issue and, IMO, it comes from the fact RAML Java parser 0.8.3 is unusable on Oracle JDK 7 due to raml-org/raml-java-parser#23 Indeed it's impossible to build tag 0.8.3 of the RAML Java parser on Oracle JDK 7 as 20 tests die due to class instantiation errors.

To fix the current issue, I've downgraded to RAML parser 0.8.2. My fork now fully works: https://github.com/ddossot/raml-jaxrs-codegen

@svacas Let me know if you want a pull request.

@santeriv

@ddossot @svacas I've also tried to apply raml-org/raml-java-parser#23 - on top of tag 0.8.3 using oracle sdk 1.6 - and try the fix ddossot@175c60e after parser tests passed ok. Now, after those fixes I ended quite in same when this bug was reported. My test above failed still as generated .java files where quite empty and some models where still missing.

@ddossot
@svacas

I've applied the raml parser fix (it's on 0.9-SNAPSHOT now) and run @santeriv test with @ddossot fork changes and still having ClassNotFoundException for Person. Classes are generated for Organization, Persons and Offices, though Organizations is the only one with fields and methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.