phiz71 / vertx-swagger

Swagger integration in Eclipse Vert.X world. A dynamic Vert.X router, configured with a swagger file and a swagger-codegen plugin to generate a server stub.
Apache License 2.0
86 stars 35 forks source link

Code generator generates conflicting SERVICE_IDs in certain cases #104

Closed AbriTj closed 2 years ago

AbriTj commented 6 years ago

Hi,

Thank you for the creating this code generator for Vertx!

I have ran into an issue while generating code with it were it generates conflicting SERVICE_IDs.

Using this API definition the code generator will generate a DefaultApiVerticle with the following SERVICE_IDs:

... final static String CREATEPAYMENT_SERVICE_ID = "createPayment"; final static String CREATEPAYMENT_SERVICE_ID = "createPayment"; final static String CREATEPAYMENT_SERVICE_ID = "createPayment"; ...

I believe these are for the following paths from the API definition:

/payments/policy/{paymentId} /payments/traffic/{paymentId} /payments/{paymentId}

Can the generator be updated to generate unique service IDs in these cases or is there an issue with the API definition or perhaps a workaround?

Kind regards

phiz71 commented 6 years ago

Hi,

SERVICE_IDs are generated from each path OperationId field. According to your ApiDefinition, /payments/policy/{paymentId}, /payments/traffic/{paymentId} and /payments/{paymentId} have the same operationId.

If you can modify the API definition, you should change these operationId as according to the swagger specs they must be unique. If not, you can modify the MainApiVerticle class :

Replace

    Router swaggerRouter = SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, vertx.eventBus(), new OperationIdServiceIdResolver());

by

    Router swaggerRouter = SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, vertx.eventBus());

As a consequence, DefaultIdResolver will be use. And this resolver compute unique ServiceId based on path.

Hope it helps you. Regards

AbriTj commented 6 years ago

Thank you! This works perfectly!