mulesoft-labs / raml-for-jax-rs

This project is all about two way transformation of JAX-RS-annotated Java code to RAML API description and back.
Other
295 stars 181 forks source link

java.time APIs and RAML Types #294

Closed giacgbj closed 6 years ago

giacgbj commented 7 years ago

Is there a way to use java.time APIs (e.g. LocalDateTime, LocalDate and LocalTime, ecc.) with RAML Types like datetime, date-only, time-only, ecc.?

chrisjamesconnor commented 6 years ago

Hi - wondered if there was any answer to this? Other than doing some JavaPoet type work on our own ?

jpbelang commented 6 years ago

Right now, it's java poet stuff. Which is a bit of a pain.

However, i'm working on a raml-to-pojo (which would be used by ramlforjaxrs) that would swap them out wholesale.

chrisjamesconnor commented 6 years ago

Excellent - I am currently working on specifying an approach for our applications. Would I be better waiting on this to bottom out (ie for you to finish this work).

I am currently using annotationTypes to map className properties so that we generate java.time.Local date (creating a ramltojaxrs.raml) file in the process.

This seems to work well for our use cases at this early stage. We are also using a similar technique to generate Lombok builder annotations (using your @depricated example as inspiration!). This allows us to generate builders on our generates Impl classes which is very useful with the layers of our apps.

Will this be maintained moving forward? Do you have another view regarding this approach?

jpbelang commented 6 years ago

Ooooooh. Lombok. That's a great idea. Unfortunately, the RAML type have changed the way of writing plugins a bit.

As to changing the type, you can now (in release/2.2.0) change the type being used. You could check out this annotation:

#%RAML 1.0
title: Hello World API
version: v1
baseUri: https://api.github.com
mediaType: application/json
uses:
  ramltopojo: ramltopojo.raml
/search:
    description: The search resource
    uriParameters:
        id:
            type: date
            (ramltopojo.types):
              plugins:
                - name: core.changeType
                  arguments: [ java.time.LocalDate ]
muthulingapandian commented 6 years ago

Hi Belanger,

Where can i find the ramltopojo.raml? Please help.

Regards, Muthu

jpbelang commented 6 years ago

An file is here:

https://github.com/mulesoft-labs/raml-for-jax-rs/blob/release/3.0.0/raml-to-jaxrs/examples/maven-examples/raml-defined-example/src/main/resources/ramltopojo.raml

muthulingapandian commented 6 years ago

Thanks Belanger

Basically, ours is third-party RAML and not supposed to update it. So I tried another approach by adding MapperConfiguration in pom.xml as attached,

jsonMapperConfiguration.txt But it is not working and generates date types in default java.uitl.Date. I am using raml-to-jaxrs-maven-plugin version 2.1.0. The plugin is internally using "jsonschema2pojo-core" module which supports this configuration. Can you please help on this?

Thank you

Regards, Muthu

kevinduffey commented 6 years ago

Bit late.. but cant you write an overaly or extension raml to the raml you are not allowed to change.. so that you CAN modify it for your annotation use without affecting the base raml?