Generate API client from URL or Controller implementation

44 views
Skip to first unread message

John Nash

unread,
Oct 8, 2015, 4:09:13 PM10/8/15
to Swagger
Hello, I am working on a project where I have implemented an API server with Jersey and I have a Controller with annotations @API... for swagger to generate the API interface and documentation. So now what I ant to do is I want to be able to generate the lcient automcatically. The problem is I don't want to use a static JSON file and the reason is that if I do I'll have to make sure the file is up to date and changes with any changes that happen on the server side. So my question is is it possible to generate client from the server endpoint e.g. http://rest-api:8080/my-path?

Or can I generate the client using the controller, for example is the controller is in separate package that can be added as a dependancy in each side can I generate JSON file or directly client code from that?

Ron Ratovsky

unread,
Oct 8, 2015, 4:14:18 PM10/8/15
to Swagger
Assuming you're using swagger-core to generate your JSON, it would be hosted at runtime. And yes, you can definitely use that to generate your client code, there should be no issue at all.
Have you had any difficulties in doing that?

On Thu, Oct 8, 2015 at 1:09 PM, John Nash <johnna...@gmail.com> wrote:
Hello, I am working on a project where I have implemented an API server with Jersey and I have a Controller with annotations @API... for swagger to generate the API interface and documentation. So now what I ant to do is I want to be able to generate the lcient automcatically. The problem is I don't want to use a static JSON file and the reason is that if I do I'll have to make sure the file is up to date and changes with any changes that happen on the server side. So my question is is it possible to generate client from the server endpoint e.g. http://rest-api:8080/my-path?

Or can I generate the client using the controller, for example is the controller is in separate package that can be added as a dependancy in each side can I generate JSON file or directly client code from that?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

John Nash

unread,
Oct 8, 2015, 4:35:10 PM10/8/15
to Swagger
OK I think I just found the answer of my own question :|

So I use the the swagger-codegen-maven-plugin to generate my code bu I was using a generated JSON file. I jsy tried to use the server URL like:

<inputSpec>http://services.office:8080/services-api/api-docs</inputSpec>

And that just worked fine, so I presume this is the right thing to do.

On another note, is it possible to generate a client code from annotated Controller class?

On Thursday, October 8, 2015 at 9:14:18 PM UTC+1, Ron wrote:
Assuming you're using swagger-core to generate your JSON, it would be hosted at runtime. And yes, you can definitely use that to generate your client code, there should be no issue at all.
Have you had any difficulties in doing that?
On Thu, Oct 8, 2015 at 1:09 PM, John Nash <johnna...@gmail.com> wrote:
Hello, I am working on a project where I have implemented an API server with Jersey and I have a Controller with annotations @API... for swagger to generate the API interface and documentation. So now what I ant to do is I want to be able to generate the lcient automcatically. The problem is I don't want to use a static JSON file and the reason is that if I do I'll have to make sure the file is up to date and changes with any changes that happen on the server side. So my question is is it possible to generate client from the server endpoint e.g. http://rest-api:8080/my-path?

Or can I generate the client using the controller, for example is the controller is in separate package that can be added as a dependancy in each side can I generate JSON file or directly client code from that?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron Ratovsky

unread,
Oct 8, 2015, 4:37:55 PM10/8/15
to Swagger
Can you elaborate what you mean by that?

On Thu, Oct 8, 2015 at 1:35 PM, John Nash <johnna...@gmail.com> wrote:
OK I think I just found the answer of my own question :|

So I use the the swagger-codegen-maven-plugin to generate my code bu I was using a generated JSON file. I jsy tried to use the server URL like:

<inputSpec>http://services.office:8080/services-api/api-docs</inputSpec>

And that just worked fine, so I presume this is the right thing to do.

On another note, is it possible to generate a client code from annotated Controller class?

On Thursday, October 8, 2015 at 9:14:18 PM UTC+1, Ron wrote:
Assuming you're using swagger-core to generate your JSON, it would be hosted at runtime. And yes, you can definitely use that to generate your client code, there should be no issue at all.
Have you had any difficulties in doing that?
On Thu, Oct 8, 2015 at 1:09 PM, John Nash <johnna...@gmail.com> wrote:
Hello, I am working on a project where I have implemented an API server with Jersey and I have a Controller with annotations @API... for swagger to generate the API interface and documentation. So now what I ant to do is I want to be able to generate the lcient automcatically. The problem is I don't want to use a static JSON file and the reason is that if I do I'll have to make sure the file is up to date and changes with any changes that happen on the server side. So my question is is it possible to generate client from the server endpoint e.g. http://rest-api:8080/my-path?

Or can I generate the client using the controller, for example is the controller is in separate package that can be added as a dependancy in each side can I generate JSON file or directly client code from that?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

John Nash

unread,
Oct 8, 2015, 4:49:01 PM10/8/15
to Swagger
Sorry, if not clear, still trying to get my hend around Swagger Generation.

So I have the following controller:

@Path("/service-api/v1/pricing/")
@Produces(MediaType.APPLICATION_JSON)
@Component
@Api(value = "pricing-service", description = "This is the pricing service.")
public class PricingController {

@Override
@GET
@Path("/product")
@ApiOperation(value = "Retrieve a product price.")
public PricingProductResponseDTO getProductPrice() {}
}

This controller currently lives on the API Server side. Swagger uses that as a public
endpoint for example to generate the documentation and the API Declaration.

So if this controller is in it's own package and lets assume I share that with my Client,
is it possible to generate my Client API implementation directly using the Controller as
a reference. I presume through some Reflection or something similar.


Ron Ratovsky

unread,
Oct 8, 2015, 4:52:31 PM10/8/15
to Swagger
If you mean whether it can be done based on the Swagger annotations added to it then I don't know of any tool that will do that as that was never the intent. The tooling around Swagger pretty much depend on the Swagger definition itself (which is language agnostic) over specific language integration.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Nash

unread,
Oct 8, 2015, 4:55:43 PM10/8/15
to Swagger
Thanks Ron that answers my question.

Looks like I am trying to do something that no one has thought of :)


Ron Ratovsky

unread,
Oct 8, 2015, 4:59:52 PM10/8/15
to Swagger
The general idea though is that you'd provide your clients with the Swagger definition itself, from which they could generate their client based on their needs.
Of course you can generate the client(s) yourself and provide that as an SDK.

On Thu, Oct 8, 2015 at 1:55 PM, John Nash <johnna...@gmail.com> wrote:
Thanks Ron that answers my question.

Looks like I am trying to do something that no one has thought of :)


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages