mulesoft-labs / raml-jaxrs-codegen

Tools to enable RAML-first development in JAX-RS projects
Other
40 stars 44 forks source link

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

Open santeriv opened 10 years ago

santeriv commented 10 years ago

See for reference 8006afd59e3d31ff4111abc134a7120a73f616ed

#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 commented 10 years ago

updated commit refs

villuv commented 10 years ago

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 commented 10 years ago

On 02/03/14 15:54, Villu Vaimets wrote:

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 _noentity - Trying for post method, array of the same model bean, inline schema. Interface refers to anonymous model class, but the class is not generated _namedschema - 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.

— Reply to this email directly or view it on GitHub https://github.com/mulesoft/raml-jaxrs-codegen/issues/4#issuecomment-33961370.

I think the ? in get? and post? may cause the trouble?

   get?:
      responses:
        200:
          description: "OK"
        404:
          description: "Not found"
    post?:
      responses:
        201:
          description: "Created"

Renzo Kottmann PhD Max Planck Institute for Marine Microbiology Microbial Genomics Group Celsiusstr. 1 28359 Bremen Germany Phone: +49 421 2028 974 Mail: rkottman@mpi-bremen.de

villuv commented 10 years ago

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 commented 10 years ago

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 https://github.com/joelittlejohn/jsonschema2pojo/issues/137 Could this be a remedy does this help for this problem, what do you think?

ddossot commented 10 years ago

@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 commented 10 years ago

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 commented 10 years ago

@ddossot 0.4.1 jsonschema2pojo-core is released

ddossot commented 10 years ago

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 commented 10 years ago

@ddossot @svacas Is this the change needed https://github.com/mulesoft/raml-jaxrs-codegen/commit/869149ddd6cf529aecfc60040b0d3ab88e3f36f8 ?

ddossot commented 10 years ago

@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: https://github.com/ddossot/raml-jaxrs-codegen/commit/175c60e163f8ab076e61e3fe51e705284d5c290d

svacas commented 10 years ago

@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 commented 10 years ago

@svacas could you please cherrypick https://github.com/mulesoft/raml-jaxrs-codegen/commit/8006afd59e3d31ff4111abc134a7120a73f616ed and try if now the test pass and are generated models not empty?

svacas commented 10 years ago

@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 commented 10 years ago

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 https://github.com/raml-org/raml-java-parser/pull/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 commented 10 years ago

@ddossot @svacas I've also tried to apply https://github.com/raml-org/raml-java-parser/pull/23 - on top of tag 0.8.3 using oracle sdk 1.6 - and try the fix https://github.com/ddossot/raml-jaxrs-codegen/commit/175c60e163f8ab076e61e3fe51e705284d5c290d 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 commented 10 years ago

But what about my fork? Is the current issue still present with it?

On 2014-03-29 5:01 PM, "Santeri Vesalainen" notifications@github.com wrote:

@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@175c60eafter 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.

— Reply to this email directly or view it on GitHub.

svacas commented 10 years ago

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.