Giter Club home page Giter Club logo

raml-java-tools's Introduction

raml-java-tools

This is a collection of Java tools used to work with RAML 1.0. Currently those tools are used by the raml-for-jaxrs project to:

  • Convert RAML specified object declarations into POJOs.
  • Convert POJOs to RAML 1.0 type declarations.
  • Emit a RAML API definition into an output stream.
  • Programmatically build a RAML 1.0 specification.

The other projects are experimental.

Maven artifacts

Maven artifacts are available at:

Releases are also available on Maven Central.

Contributing

If you are interested in contributing some code to this project, thanks! Please submit a Contributors Agreement acknowledging that you are transferring ownership.

To discuss this project:

  • bug/feature request: please file a github issue
  • If you're not sure: you can use the RAML forum or Slack

raml-java-tools's People

Contributors

akoenig82 avatar deduper avatar dependabot[bot] avatar galistvan avatar josehdez2 avatar jpbelang avatar jstoiko avatar kaiser1989 avatar svc-scm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raml-java-tools's Issues

Subtypes in unions aren't working correctly

This is because of subtypes are not handled correctly.

Faulty code is here

    private Shape findParentType(Shape typeDeclaration) {
        if (typeDeclaration instanceof NodeShape) {
            NodeShape otd = (NodeShape) typeDeclaration;
            return otd.inherits().size() > 0 ? otd.inherits().get(0) : otd;
        } else {
            return typeDeclaration;
        }
    }

This returns the wrong type.

Types do not support additional properties

I've seen some code JAXRS related but bare conversion to POJO does not seem to support additional properties. The following type:

types:
  salutation:
    type: object
    additionalProperties: true

Will generate the following POJO:

public interface Salutation {
}
public class SalutationImpl implements Salutation {
}

I'm also attaching a project to replicate: additionalProperties.tar.gz

equalsHashCode adds java.util.

Generated pojos have the import java.util.Objects; line. In the hashCode generated method, it uses Objects. But in the equals method, the code shows it is using java.util.Objects. This is just to clean that bit up.. remove the java.util. generated bits.

Generated java of subtypes won't compile

When using a RAML that has for instance a response envelope:

myEnvelope that has some members in it, when creating a subtype, eg: EnvelopeForParticularResource it will generate enums and other types again, creating a change in the Java signature and therefore not compiling for the subtype.

See the following example project to reproduce raml-defined-example.tar.gz

As a dirty workaround I've been able to change the type: mylib.myType for an type: !include ... which does the trick but is a far cry from ideal.

Generate equals and hashCode methods

I dont know if this is in place yet.. but because this tool generates the pojo methods, it would be beneficial that it could also generate modern day equals() and hashCode() methods (making use of Objects.equals() and Objects.hash()).

Add full constuctor to generated "impl" classes

I think it's a nice idea to add a full constructor to the implementation classes, as changes in the raml file can be missed. By using a full constructor with all fields, changes in the raml will result in compilation errors, so there can't be uninitialized fields.

raml-to-pojo-maven-plugin for a RAML with Traits

I have RAML1.0 with traits , and when I use raml-to-pojo-maven-plugin and it fails with nullpointer exception @ org.raml.ramltopojo.CreationResult.java [Line #56]

Also , note the same RAML is working with raml-to-jaxrs-maven-plugin , Is it recommended to use raml-to-jaxrs-maven-plugin for client stubs ?

equalsHashCode use instanceOf

The generated equals code uses the approach of getClass comparison. According to Josh Bloch and elsewhere, the better approach is to use instanceOf:

https://www.artima.com/intv/bloch17.html

It also allows the remove of the null check at the start of the equals method:

The generated code should be something like:

@OverRide
public boolean equals(Object o){
if (this == o) return true;
if (!(o instanceof Other)) return false;
// call super.equals to account for any parent class equals impl
if (!super.equals(o)) return false;
Other other = (Other) o;
return Objects.equals(getSomething(), other.getSomething());
}

Extending class re-implements parent methods/properties

If I have:

types:
  Base:
    type: object
    properties:
      name:
        type: string
      phone;
        type: string

  Profile:
    type: Base
    properties:
      address:
        type: string
      country:
        type: string

I would expect raml2pojo to generate two classes (or in the case of interfaces and classes, 2 of each). Base interface/impl would simply be something like:

public class Base [
  private String name;
  private String phone;

  ... methods to get/set name and phone ...
}

public class Profile extends Base {
  private String address;
  private String country;

... methods to get/set address and country ...
}

However.. what Raml2Pojo is currently doing.. is it generate the base class (and it includes json property annotations..which I left out) just fine. BUT the Profile class while it extends Base it ALSO adds ALL the properties and methods of the parent. So instead of inheriting the name/phone properties/methods from the parent, it is re-implementing them.. thus defeating the purpose for extending the parent class.

Maybe I am missing something... but I would think that RAML type inheritance should only include the properties/methods for the specifically defined RAML Type, and inherit the methods/properties from the parents.

Support pattern properties

#%RAML 1.0
title: My API With Types
types:
  Person:
    properties:
      name:
        required: true
        type: string
      age:
        required: false
        type: number
      /somepattern/: # force all additional properties to be a string
        type: string

I have to check that jackson supports this (I think it does).
I have to support the additionalProperties facet correctly. (I always set to true now).

Looks like verification of non mandatory object properties

The current buildLooksLike code verifies the document to deserialize contains all the properties (required and non-required) from the RAML object declaration. This causes the object identification (and thereby the deserialization) to fail if any of the non-required properties is missing from the response document.

By adding the following code only the mandatory properties are verified:

List<TypeDeclaration> mandatoryProperties = otd.properties().stream().filter(propertyTypeDeclaration -> propertyTypeDeclaration.required())
					.collect(Collectors.toList());

This results into code like the following (with no optional attributes in the containsAll):

    private boolean looksLikeMortgageAccount(Map<String, Object> map) {
      return map.keySet().containsAll(Arrays.asList("accountId","type")) && map.get("type").equals("MORTGAGE");
    }

Enum constant names are being stripped of their underscores.

It's just a cosmetic thing really, but quite annoying.
This issue is due to this line:

return buildJavaFriendlyName(value, NameFixer.ALL_UPPER, 0);

Shouldn't you rather create a new NameFixer for this, that prepends an underscore in it's fixOthers method? Or maybe even change the ALL_UPPER name fixer to do that?
We recently upgraded from raml-to-jaxrs-maven-plugin version 1.3.4 to 3.0.4 and back then underscores were preserved in enum constant names. Or is there a specific reason for the way it works right now?

Pojo to raml fails to convert pojo that contains enum

If you add SimpleEnum to the pojo-to-raml/src/test/java/org/raml/pojotoraml/Fun.java and run tests, it fails:

org.raml.builder.ModelBuilderException: model errors: Invalid reference 'SimpleEnum'
	at org.raml.builder.Util$2.apply(Util.java:129)
	at org.raml.builder.Util.buildModel(Util.java:62)
	at org.raml.builder.RamlDocumentBuilder.buildModel(RamlDocumentBuilder.java:108)
	at org.raml.pojotoraml.PojoToRamlImplTest.createApi(PojoToRamlImplTest.java:155)
	at org.raml.pojotoraml.PojoToRamlImplTest.simpleStuff(PojoToRamlImplTest.java:43)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

Is this expected behavior? This way I cannot convert any pojo, that contains Enum.

joptsimple library not bundled?

Getting a runtime exception in ramltopojo.Names class, joptsimple no such method found. I dont see anything about having to depend on that library, and even when I do add the maven dependency, it still fails.

java.lang.NoSuchMethodError: joptsimple.internal.Strings.join(Ljava/util/List;Ljava/lang/String;)Ljava/lang/String;

at org.raml.ramltopojo.Names.typeName(Names.java:61)
at org.raml.ramltopojo.object.ObjectTypeHandler.javaClassName(ObjectTypeHandler.java:41)
at org.raml.ramltopojo.object.ObjectTypeHandler.javaClassReference(ObjectTypeHandler.java:49)
at org.raml.ramltopojo.TypeDeclarationType.calculateTypeName(TypeDeclarationType.java:394)
at org.raml.ramltopojo.RamlToPojoImpl.buildPojos(RamlToPojoImpl.java:27)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.