You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@aries.apache.org by Markus Rathgeb <ma...@gmail.com> on 2019/11/21 09:44:00 UTC

Re: Jax-RS Whiteboard and OpenAPI

Hi,

I'm currently struggling with the same problem.
Oliver, did you already create some JAX-RS Whiteboard OpenAPI integration?
Timonthy, did you know about another one?

I found the amdatu-web project and assume they provide an OpenAPI
generation for JAX-RS Whiteboard. I have not found time for a deeper
look into this yet, but it seems that the implementation depends on
their whiteboard implementation (at least the package imports look
like).
* https://amdatu.org/components/amdatu-web/
* https://bitbucket.org/amdatu/amdatu-web/src/master/org.amdatu.web.rest/src/org/amdatu/web/rest/

Best regards,
Markus

Am Do., 21. Nov. 2019 um 10:34 Uhr schrieb Timothy Ward
<ti...@apache.org>:
>
> Hi,
>
> To my knowledge nobody has done this in a reusable way yet, but if you're interested in doing so then adding it as a project in the integrations would be great!
>
> Tim
>
>
> > On 18 Jun 2019, at 13:07, Oliver Schweitzer <os...@me.com> wrote:
> >
> > Hi,
> >
> > I'm successfully using the Jax-RS Whiteboard in Karat 4.2, however one of the last missing puzzle pieces to complete component bliss is integration of OpenAPI (Swagger 2) - so that annotated (sub) resources get published as an API schema by a Jax-RS Resource.
> >
> > Here https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-configuration is a plethora of information on how to integrate OpenAPI into various Jax-RS setups, and if I look at it long enough I'll probably work something out for myself, but I'd like to know:
> >
> > Have some Aries Whiteboard users/devs done the integration successfully/cleanly/easily?
> > What would be the most OSGi/Declarative Service-like ways to integrate OpenAPI into the Whiteboard mechanism?
> > Would one of these ways be a candidate for  a reference implementation here https://github.com/apache/aries-jax-rs-whiteboard/tree/master/integrations ?
> >
> > Regards,
> >
> > Oliver
>

Re: Jax-RS Whiteboard and OpenAPI

Posted by Markus Rathgeb <ma...@gmail.com>.
If anyone ever needs it (I will try to further improve the code and
documentation):
https://github.com/maggu2810/jaxrswb

Am Mo., 25. Nov. 2019 um 13:28 Uhr schrieb Markus Rathgeb <ma...@gmail.com>:
>
> Hi again,
>
> as written before, the provided scanner does not work (for me) using
> different bundles / classpathes and multiple applications.
>
> Because of this I implemented yesterday the some wrapping of it myself.
>
> The implementation tries to identify ever JAX-RS resource (using
> service property filter) and its application (using object class and
> target filter with respect of the JAX-RS resource application select).
> After that it generates a map.
> The key consists of the "base path" (the path of the application) --
> so we can support as many applications as provided.
> The value consists of the classes that implement the JAX-RS resource.
>
> This map is used to fill the OpenAPI JAX-RS reader.
>
> The generated OpenAPI can be used to generate the JSON reply.
> But I don't want to rely on a special message body writer and the
> knowledge if the implementation serialize null references etc. (the
> Swagger UI does not work with every JSON serializer).
> So, I added a method that converts the "OpenAPI" into a
> "Map<String,Object>" that can be used by the most JSON serializers and
> generate a working result for the Swagger UI.
>
> The current snapshot can be found here:
> https://github.com/maggu2810/playground-osgi/tree/128d162ff8aa1a73337b00f712fcc5ffe0b1b869/bundles/jaxrs-oapi-gen/src/main/java/de/maggu2810/playground/osgi/jaxrs/oapi/gen/impl
>
> Best regards,
> Markus
>
> Am Sa., 23. Nov. 2019 um 13:29 Uhr schrieb Oliver Schweitzer
> <os...@me.com>:
> >
> > Hi Markus,
> >
> > I can't argue about that behavior, because the original code isn't mine.
> >
> > Take a look at https://github.com/swagger-api/swagger-core/blob/d17f81c7e7ba99157ec7b3ab324a16372885416c/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/integration/resources/BaseOpenApiResource.java#L72 - that's where the serialization code you linked to is originally from.
> >
> > In the version I supplied as pull request, see https://github.com/osx2000/aries-jax-rs-whiteboard/blob/master/integrations/openapi/openapi-resource/src/main/java/org/apache/aries/jax/rs/openapi/OpenApiResource.java the code duplication from the Swagger BaseOpenApiResource is replaced by inheritance
> >
> > Best regards,
> >
> > Oliver
> >
> > -----Original Message-----
> > From: Markus Rathgeb <ma...@gmail.com>
> > Sent: 23 November 2019 11:59
> > To: user@aries.apache.org
> > Subject: Re: Jax-RS Whiteboard and OpenAPI
> >
> > Hi Oliver,
> >
> > there is another thing I don't understand:
> > Why you do not run into the following "problem" I ran with your code:
> >
> > https://github.com/osx2000/finmath-service/blob/master/bundles/service/src/main/java/de/osx2000/finmath/service/OpenApiResource.java#L125
> >
> > If a "json" reply is generated you stringify the object already and place the JSON string representation of the object as entity in the response.
> > As media type JSON is chosen...
> >
> > For me the message body writer for the media type JSON is picked up by JAX-RS to encode the response's entity. The entity object (a string that already is a valid JSON string) is then again stringified as JSON...
> >
> > Why is this not been the cause for your message body writer?
> >

Re: Jax-RS Whiteboard and OpenAPI

Posted by Markus Rathgeb <ma...@gmail.com>.
Hi again,

as written before, the provided scanner does not work (for me) using
different bundles / classpathes and multiple applications.

Because of this I implemented yesterday the some wrapping of it myself.

The implementation tries to identify ever JAX-RS resource (using
service property filter) and its application (using object class and
target filter with respect of the JAX-RS resource application select).
After that it generates a map.
The key consists of the "base path" (the path of the application) --
so we can support as many applications as provided.
The value consists of the classes that implement the JAX-RS resource.

This map is used to fill the OpenAPI JAX-RS reader.

The generated OpenAPI can be used to generate the JSON reply.
But I don't want to rely on a special message body writer and the
knowledge if the implementation serialize null references etc. (the
Swagger UI does not work with every JSON serializer).
So, I added a method that converts the "OpenAPI" into a
"Map<String,Object>" that can be used by the most JSON serializers and
generate a working result for the Swagger UI.

The current snapshot can be found here:
https://github.com/maggu2810/playground-osgi/tree/128d162ff8aa1a73337b00f712fcc5ffe0b1b869/bundles/jaxrs-oapi-gen/src/main/java/de/maggu2810/playground/osgi/jaxrs/oapi/gen/impl

Best regards,
Markus

Am Sa., 23. Nov. 2019 um 13:29 Uhr schrieb Oliver Schweitzer
<os...@me.com>:
>
> Hi Markus,
>
> I can't argue about that behavior, because the original code isn't mine.
>
> Take a look at https://github.com/swagger-api/swagger-core/blob/d17f81c7e7ba99157ec7b3ab324a16372885416c/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/integration/resources/BaseOpenApiResource.java#L72 - that's where the serialization code you linked to is originally from.
>
> In the version I supplied as pull request, see https://github.com/osx2000/aries-jax-rs-whiteboard/blob/master/integrations/openapi/openapi-resource/src/main/java/org/apache/aries/jax/rs/openapi/OpenApiResource.java the code duplication from the Swagger BaseOpenApiResource is replaced by inheritance
>
> Best regards,
>
> Oliver
>
> -----Original Message-----
> From: Markus Rathgeb <ma...@gmail.com>
> Sent: 23 November 2019 11:59
> To: user@aries.apache.org
> Subject: Re: Jax-RS Whiteboard and OpenAPI
>
> Hi Oliver,
>
> there is another thing I don't understand:
> Why you do not run into the following "problem" I ran with your code:
>
> https://github.com/osx2000/finmath-service/blob/master/bundles/service/src/main/java/de/osx2000/finmath/service/OpenApiResource.java#L125
>
> If a "json" reply is generated you stringify the object already and place the JSON string representation of the object as entity in the response.
> As media type JSON is chosen...
>
> For me the message body writer for the media type JSON is picked up by JAX-RS to encode the response's entity. The entity object (a string that already is a valid JSON string) is then again stringified as JSON...
>
> Why is this not been the cause for your message body writer?
>

RE: Jax-RS Whiteboard and OpenAPI

Posted by Oliver Schweitzer <os...@me.com>.
Hi Markus,

I can't argue about that behavior, because the original code isn't mine.

Take a look at https://github.com/swagger-api/swagger-core/blob/d17f81c7e7ba99157ec7b3ab324a16372885416c/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/integration/resources/BaseOpenApiResource.java#L72 - that's where the serialization code you linked to is originally from. 

In the version I supplied as pull request, see https://github.com/osx2000/aries-jax-rs-whiteboard/blob/master/integrations/openapi/openapi-resource/src/main/java/org/apache/aries/jax/rs/openapi/OpenApiResource.java the code duplication from the Swagger BaseOpenApiResource is replaced by inheritance 

Best regards,

Oliver

-----Original Message-----
From: Markus Rathgeb <ma...@gmail.com> 
Sent: 23 November 2019 11:59
To: user@aries.apache.org
Subject: Re: Jax-RS Whiteboard and OpenAPI

Hi Oliver,

there is another thing I don't understand:
Why you do not run into the following "problem" I ran with your code:

https://github.com/osx2000/finmath-service/blob/master/bundles/service/src/main/java/de/osx2000/finmath/service/OpenApiResource.java#L125

If a "json" reply is generated you stringify the object already and place the JSON string representation of the object as entity in the response.
As media type JSON is chosen...

For me the message body writer for the media type JSON is picked up by JAX-RS to encode the response's entity. The entity object (a string that already is a valid JSON string) is then again stringified as JSON...

Why is this not been the cause for your message body writer?


Re: Jax-RS Whiteboard and OpenAPI

Posted by Markus Rathgeb <ma...@gmail.com>.
Hi Oliver,

there is another thing I don't understand:
Why you do not run into the following "problem" I ran with your code:

https://github.com/osx2000/finmath-service/blob/master/bundles/service/src/main/java/de/osx2000/finmath/service/OpenApiResource.java#L125

If a "json" reply is generated you stringify the object already and
place the JSON string representation of the object as entity in the
response.
As media type JSON is chosen...

For me the message body writer for the media type JSON is picked up by
JAX-RS to encode the response's entity. The entity object (a string
that already is a valid JSON string) is then again stringified as
JSON...

Why is this not been the cause for your message body writer?

Re: Jax-RS Whiteboard and OpenAPI

Posted by Markus Rathgeb <ma...@gmail.com>.
Hi Oliver,

thank you for your reply.
This is similar to what I did. But for me it is not fully working.

There are at least two mechanisms that approach identifies the classes
it should scan.

(1) Using configuration, class path scanner (class graph), ...
See: https://github.com/swagger-api/swagger-core/blob/d17f81c7e7ba99157ec7b3ab324a16372885416c/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/integration/JaxrsAnnotationScanner.java#L54

This does not work in my case, because no static configuration is used
(can be set up programmatically on demand).
The classpath does not provide the respective classes because of
OSGi's classpath separation.
Additionally because of that scanning, classes that are available on
the classpath but are not part of the current application are used,
too.

(2) It tries to get the classes from the application.
See: https://github.com/swagger-api/swagger-core/blob/d17f81c7e7ba99157ec7b3ab324a16372885416c/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/integration/JaxrsApplicationAndAnnotationScanner.java#L13

If I use the context injected application, the returned classes are empty.

What I did to get the classes respected:
Add a reference with a target filter to the component that gets all
JAX-RS resources of the specific application injected.
Create a new application that wrappes the injected one and that
"getClass()" method additionally returns the references it got by DS.

For me it seems that we need to use a custom "JaxrsOpenApiScanner"
implementation that respects only the resources of a specific
application.
We also need to respect the path of the application (nested
applications) dynamically to ensure the resources' path are
sub-paths...

Am Do., 21. Nov. 2019 um 16:14 Uhr schrieb Raymond Auge
<ra...@liferay.com>:
>
> Hey Oliver,
>
> Could you send a PR to Aries JAXRS whiteboard project? We'd love to add this as a module in the integration group.
>
> - Ray
>
> On Thu, Nov 21, 2019 at 7:47 AM Oliver Schweitzer <os...@me.com> wrote:
>>
>> Hi,
>>
>> Yes, I got it to work - this class
>>
>> https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/integration/resources/BaseOpenApiResource.java
>>
>> provided by the swagger-core project was almost enough, I just had to add some DS and Whiteboard annotations and configuration.
>>
>> Take a look at the proof of concept here
>>
>> https://github.com/osx2000/finmath-service/blob/master/bundles/service/src/main/java/de/osx2000/finmath/service/OpenApiResource.java
>>
>> The project where I actually annotate other resources with OpenAPI isn’t in GitHub, don’t hesitate to ask if you have further questions.
>>
>> Best regards,
>>
>> Oliver
>>
>>
>> > On 21. Nov 2019, at 10:44, Markus Rathgeb <ma...@gmail.com> wrote:
>> >
>> > Hi,
>> >
>> > I'm currently struggling with the same problem.
>> > Oliver, did you already create some JAX-RS Whiteboard OpenAPI integration?
>> > Timonthy, did you know about another one?
>> >
>> > I found the amdatu-web project and assume they provide an OpenAPI
>> > generation for JAX-RS Whiteboard. I have not found time for a deeper
>> > look into this yet, but it seems that the implementation depends on
>> > their whiteboard implementation (at least the package imports look
>> > like).
>> > * https://amdatu.org/components/amdatu-web/
>> > * https://bitbucket.org/amdatu/amdatu-web/src/master/org.amdatu.web.rest/src/org/amdatu/web/rest/
>> >
>> > Best regards,
>> > Markus
>> >
>> > Am Do., 21. Nov. 2019 um 10:34 Uhr schrieb Timothy Ward
>> > <ti...@apache.org>:
>> >>
>> >> Hi,
>> >>
>> >> To my knowledge nobody has done this in a reusable way yet, but if you're interested in doing so then adding it as a project in the integrations would be great!
>> >>
>> >> Tim
>> >>
>> >>
>> >>> On 18 Jun 2019, at 13:07, Oliver Schweitzer <os...@me.com> wrote:
>> >>>
>> >>> Hi,
>> >>>
>> >>> I'm successfully using the Jax-RS Whiteboard in Karat 4.2, however one of the last missing puzzle pieces to complete component bliss is integration of OpenAPI (Swagger 2) - so that annotated (sub) resources get published as an API schema by a Jax-RS Resource.
>> >>>
>> >>> Here https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-configuration is a plethora of information on how to integrate OpenAPI into various Jax-RS setups, and if I look at it long enough I'll probably work something out for myself, but I'd like to know:
>> >>>
>> >>> Have some Aries Whiteboard users/devs done the integration successfully/cleanly/easily?
>> >>> What would be the most OSGi/Declarative Service-like ways to integrate OpenAPI into the Whiteboard mechanism?
>> >>> Would one of these ways be a candidate for  a reference implementation here https://github.com/apache/aries-jax-rs-whiteboard/tree/master/integrations ?
>> >>>
>> >>> Regards,
>> >>>
>> >>> Oliver
>> >>
>>
>
>
> --
> Raymond Augé (@rotty3000)
> Senior Software Architect Liferay, Inc. (@Liferay)

Re: Jax-RS Whiteboard and OpenAPI

Posted by Raymond Auge <ra...@liferay.com>.
Hey Oliver,

Could you send a PR to Aries JAXRS whiteboard project? We'd love to add
this as a module in the integration group.

- Ray

On Thu, Nov 21, 2019 at 7:47 AM Oliver Schweitzer <os...@me.com>
wrote:

> Hi,
>
> Yes, I got it to work - this class
>
>
> https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/integration/resources/BaseOpenApiResource.java
>
> provided by the swagger-core project was almost enough, I just had to add
> some DS and Whiteboard annotations and configuration.
>
> Take a look at the proof of concept here
>
>
> https://github.com/osx2000/finmath-service/blob/master/bundles/service/src/main/java/de/osx2000/finmath/service/OpenApiResource.java
>
> The project where I actually annotate other resources with OpenAPI isn’t
> in GitHub, don’t hesitate to ask if you have further questions.
>
> Best regards,
>
> Oliver
>
>
> > On 21. Nov 2019, at 10:44, Markus Rathgeb <ma...@gmail.com> wrote:
> >
> > Hi,
> >
> > I'm currently struggling with the same problem.
> > Oliver, did you already create some JAX-RS Whiteboard OpenAPI
> integration?
> > Timonthy, did you know about another one?
> >
> > I found the amdatu-web project and assume they provide an OpenAPI
> > generation for JAX-RS Whiteboard. I have not found time for a deeper
> > look into this yet, but it seems that the implementation depends on
> > their whiteboard implementation (at least the package imports look
> > like).
> > * https://amdatu.org/components/amdatu-web/
> > *
> https://bitbucket.org/amdatu/amdatu-web/src/master/org.amdatu.web.rest/src/org/amdatu/web/rest/
> >
> > Best regards,
> > Markus
> >
> > Am Do., 21. Nov. 2019 um 10:34 Uhr schrieb Timothy Ward
> > <ti...@apache.org>:
> >>
> >> Hi,
> >>
> >> To my knowledge nobody has done this in a reusable way yet, but if
> you're interested in doing so then adding it as a project in the
> integrations would be great!
> >>
> >> Tim
> >>
> >>
> >>> On 18 Jun 2019, at 13:07, Oliver Schweitzer <os...@me.com>
> wrote:
> >>>
> >>> Hi,
> >>>
> >>> I'm successfully using the Jax-RS Whiteboard in Karat 4.2, however one
> of the last missing puzzle pieces to complete component bliss is
> integration of OpenAPI (Swagger 2) - so that annotated (sub) resources get
> published as an API schema by a Jax-RS Resource.
> >>>
> >>> Here
> https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-configuration
> is a plethora of information on how to integrate OpenAPI into various
> Jax-RS setups, and if I look at it long enough I'll probably work something
> out for myself, but I'd like to know:
> >>>
> >>> Have some Aries Whiteboard users/devs done the integration
> successfully/cleanly/easily?
> >>> What would be the most OSGi/Declarative Service-like ways to integrate
> OpenAPI into the Whiteboard mechanism?
> >>> Would one of these ways be a candidate for  a reference implementation
> here
> https://github.com/apache/aries-jax-rs-whiteboard/tree/master/integrations
> ?
> >>>
> >>> Regards,
> >>>
> >>> Oliver
> >>
>
>

-- 
*Raymond Augé* <http://www.liferay.com/web/raymond.auge/profile>
 (@rotty3000)
Senior Software Architect *Liferay, Inc.* <http://www.liferay.com>
 (@Liferay)

Re: Jax-RS Whiteboard and OpenAPI

Posted by Oliver Schweitzer <os...@me.com>.
Hi,

Yes, I got it to work - this class 

https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/integration/resources/BaseOpenApiResource.java

provided by the swagger-core project was almost enough, I just had to add some DS and Whiteboard annotations and configuration. 

Take a look at the proof of concept here

https://github.com/osx2000/finmath-service/blob/master/bundles/service/src/main/java/de/osx2000/finmath/service/OpenApiResource.java

The project where I actually annotate other resources with OpenAPI isn’t in GitHub, don’t hesitate to ask if you have further questions.

Best regards,

Oliver


> On 21. Nov 2019, at 10:44, Markus Rathgeb <ma...@gmail.com> wrote:
> 
> Hi,
> 
> I'm currently struggling with the same problem.
> Oliver, did you already create some JAX-RS Whiteboard OpenAPI integration?
> Timonthy, did you know about another one?
> 
> I found the amdatu-web project and assume they provide an OpenAPI
> generation for JAX-RS Whiteboard. I have not found time for a deeper
> look into this yet, but it seems that the implementation depends on
> their whiteboard implementation (at least the package imports look
> like).
> * https://amdatu.org/components/amdatu-web/
> * https://bitbucket.org/amdatu/amdatu-web/src/master/org.amdatu.web.rest/src/org/amdatu/web/rest/
> 
> Best regards,
> Markus
> 
> Am Do., 21. Nov. 2019 um 10:34 Uhr schrieb Timothy Ward
> <ti...@apache.org>:
>> 
>> Hi,
>> 
>> To my knowledge nobody has done this in a reusable way yet, but if you're interested in doing so then adding it as a project in the integrations would be great!
>> 
>> Tim
>> 
>> 
>>> On 18 Jun 2019, at 13:07, Oliver Schweitzer <os...@me.com> wrote:
>>> 
>>> Hi,
>>> 
>>> I'm successfully using the Jax-RS Whiteboard in Karat 4.2, however one of the last missing puzzle pieces to complete component bliss is integration of OpenAPI (Swagger 2) - so that annotated (sub) resources get published as an API schema by a Jax-RS Resource.
>>> 
>>> Here https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-configuration is a plethora of information on how to integrate OpenAPI into various Jax-RS setups, and if I look at it long enough I'll probably work something out for myself, but I'd like to know:
>>> 
>>> Have some Aries Whiteboard users/devs done the integration successfully/cleanly/easily?
>>> What would be the most OSGi/Declarative Service-like ways to integrate OpenAPI into the Whiteboard mechanism?
>>> Would one of these ways be a candidate for  a reference implementation here https://github.com/apache/aries-jax-rs-whiteboard/tree/master/integrations ?
>>> 
>>> Regards,
>>> 
>>> Oliver
>>