You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Richard James <ri...@gmail.com> on 2018/01/19 08:57:18 UTC

Camel REST DSL Swagger Documentation - setting scheme property

Hi All,

I have created a REST API with the camel REST DSL, with spring boot. This
is all working fine. I have included swagger documentation as part of the
solution. I am trying to set the scheme property to reflect the API being
hosted on https. However this property seems to be ignored and just appears
as http in my swagger document.

This is my REST config;

restConfiguration().component("servlet")
.apiContextPath("api-doc")
.apiProperty("api.title", "Job REST API")
.apiProperty("api.contact", "Richard James")
.apiProperty("api.version", "1.0")
.dataFormatProperty("prettyPrint", "true")
.dataFormatProperty("json.in.disableFeatures",FAIL_ON_EMPTY_BEANS")
.bindingMode(RestBindingMode.json)
*.scheme("https")*
.contextPath("api/" + restApiVersion)
.enableCORS(true)
.setApiContextRouteId("JobPadCollectionAPI");

This is a snippet from the swagger document;

{
  "swagger" : "2.0",
  "info" : {
    "version" : "1",
    "title" : "Job Event and Job Completion REST API"
  },
  "host" : "0.0.0.0",
  "basePath" : "/api/v1",
  "tags" : [ {
    "name" : "jobpadcollection"
  } ],
  *"schemes" : [ "http" ],*
  "paths" : {

....

Could someone point me in the right direction in case I am configuring
this incorrectly?

Many thanks,

Richard

Re: Camel REST DSL Swagger Documentation - setting scheme property

Posted by Richard James <ri...@gmail.com>.
Thank you both for your suggestions.

I have been able to implement it the way you both suggested in order to
have the schemes property set dynamically based on whether its SSL or not.



On Sun, Jan 21, 2018 at 9:56 PM, Balazs Szeti <sz...@gmail.com>
wrote:

> Hi,
>
> I did this to set scheme for swagger doc based on the actual configuration:
> @Autowired
> ServerProperties serverProperties;
> ...
> .apiProperty("schemes", serverProperties.getSsl() != null &&
> serverProperties.getSsl().isEnabled() ? "https" : "http" )
>
>
> On Fri, Jan 19, 2018 at 4:44 PM, Darius Cooper <da...@gmail.com>
> wrote:
>
> > Have you tried:
> >   apiProperty("schemes","https")
> > I have not tried it myself, but I see it in some sample code
> >
> > On Fri, Jan 19, 2018 at 3:57 AM, Richard James <ri...@gmail.com>
> > wrote:
> >
> > > Hi All,
> > >
> > > I have created a REST API with the camel REST DSL, with spring boot.
> This
> > > is all working fine. I have included swagger documentation as part of
> the
> > > solution. I am trying to set the scheme property to reflect the API
> being
> > > hosted on https. However this property seems to be ignored and just
> > appears
> > > as http in my swagger document.
> > >
> > > This is my REST config;
> > >
> > > restConfiguration().component("servlet")
> > > .apiContextPath("api-doc")
> > > .apiProperty("api.title", "Job REST API")
> > > .apiProperty("api.contact", "Richard James")
> > > .apiProperty("api.version", "1.0")
> > > .dataFormatProperty("prettyPrint", "true")
> > > .dataFormatProperty("json.in.disableFeatures",FAIL_ON_EMPTY_BEANS")
> > > .bindingMode(RestBindingMode.json)
> > > *.scheme("https")*
> > > .contextPath("api/" + restApiVersion)
> > > .enableCORS(true)
> > > .setApiContextRouteId("JobPadCollectionAPI");
> > >
> > > This is a snippet from the swagger document;
> > >
> > > {
> > >   "swagger" : "2.0",
> > >   "info" : {
> > >     "version" : "1",
> > >     "title" : "Job Event and Job Completion REST API"
> > >   },
> > >   "host" : "0.0.0.0",
> > >   "basePath" : "/api/v1",
> > >   "tags" : [ {
> > >     "name" : "jobpadcollection"
> > >   } ],
> > >   *"schemes" : [ "http" ],*
> > >   "paths" : {
> > >
> > > ....
> > >
> > > Could someone point me in the right direction in case I am configuring
> > > this incorrectly?
> > >
> > > Many thanks,
> > >
> > > Richard
> > >
> >
>

Re: Camel REST DSL Swagger Documentation - setting scheme property

Posted by Balazs Szeti <sz...@gmail.com>.
Hi,

I did this to set scheme for swagger doc based on the actual configuration:
@Autowired
ServerProperties serverProperties;
...
.apiProperty("schemes", serverProperties.getSsl() != null &&
serverProperties.getSsl().isEnabled() ? "https" : "http" )


On Fri, Jan 19, 2018 at 4:44 PM, Darius Cooper <da...@gmail.com>
wrote:

> Have you tried:
>   apiProperty("schemes","https")
> I have not tried it myself, but I see it in some sample code
>
> On Fri, Jan 19, 2018 at 3:57 AM, Richard James <ri...@gmail.com>
> wrote:
>
> > Hi All,
> >
> > I have created a REST API with the camel REST DSL, with spring boot. This
> > is all working fine. I have included swagger documentation as part of the
> > solution. I am trying to set the scheme property to reflect the API being
> > hosted on https. However this property seems to be ignored and just
> appears
> > as http in my swagger document.
> >
> > This is my REST config;
> >
> > restConfiguration().component("servlet")
> > .apiContextPath("api-doc")
> > .apiProperty("api.title", "Job REST API")
> > .apiProperty("api.contact", "Richard James")
> > .apiProperty("api.version", "1.0")
> > .dataFormatProperty("prettyPrint", "true")
> > .dataFormatProperty("json.in.disableFeatures",FAIL_ON_EMPTY_BEANS")
> > .bindingMode(RestBindingMode.json)
> > *.scheme("https")*
> > .contextPath("api/" + restApiVersion)
> > .enableCORS(true)
> > .setApiContextRouteId("JobPadCollectionAPI");
> >
> > This is a snippet from the swagger document;
> >
> > {
> >   "swagger" : "2.0",
> >   "info" : {
> >     "version" : "1",
> >     "title" : "Job Event and Job Completion REST API"
> >   },
> >   "host" : "0.0.0.0",
> >   "basePath" : "/api/v1",
> >   "tags" : [ {
> >     "name" : "jobpadcollection"
> >   } ],
> >   *"schemes" : [ "http" ],*
> >   "paths" : {
> >
> > ....
> >
> > Could someone point me in the right direction in case I am configuring
> > this incorrectly?
> >
> > Many thanks,
> >
> > Richard
> >
>

Re: Camel REST DSL Swagger Documentation - setting scheme property

Posted by Darius Cooper <da...@gmail.com>.
Have you tried:
  apiProperty("schemes","https")
I have not tried it myself, but I see it in some sample code

On Fri, Jan 19, 2018 at 3:57 AM, Richard James <ri...@gmail.com>
wrote:

> Hi All,
>
> I have created a REST API with the camel REST DSL, with spring boot. This
> is all working fine. I have included swagger documentation as part of the
> solution. I am trying to set the scheme property to reflect the API being
> hosted on https. However this property seems to be ignored and just appears
> as http in my swagger document.
>
> This is my REST config;
>
> restConfiguration().component("servlet")
> .apiContextPath("api-doc")
> .apiProperty("api.title", "Job REST API")
> .apiProperty("api.contact", "Richard James")
> .apiProperty("api.version", "1.0")
> .dataFormatProperty("prettyPrint", "true")
> .dataFormatProperty("json.in.disableFeatures",FAIL_ON_EMPTY_BEANS")
> .bindingMode(RestBindingMode.json)
> *.scheme("https")*
> .contextPath("api/" + restApiVersion)
> .enableCORS(true)
> .setApiContextRouteId("JobPadCollectionAPI");
>
> This is a snippet from the swagger document;
>
> {
>   "swagger" : "2.0",
>   "info" : {
>     "version" : "1",
>     "title" : "Job Event and Job Completion REST API"
>   },
>   "host" : "0.0.0.0",
>   "basePath" : "/api/v1",
>   "tags" : [ {
>     "name" : "jobpadcollection"
>   } ],
>   *"schemes" : [ "http" ],*
>   "paths" : {
>
> ....
>
> Could someone point me in the right direction in case I am configuring
> this incorrectly?
>
> Many thanks,
>
> Richard
>