# Relying on Swagger Client Code Generator For REST API

**URL:** <https://talk.openmrs.org/t/relying-on-swagger-client-code-generator-for-rest-api/8538>\
**Category:** Development\
**Tags:** restws, rest\
**Created:** [October 28, 2016, 7:04pm UTC](https://talk.openmrs.org/t/relying-on-swagger-client-code-generator-for-rest-api/8538 "2016-10-28T19:04:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![willa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/willa/32/256_2.png) [@willa](https://talk.openmrs.org/u/willa)\
**Post date:** [October 28, 2016, 7:04pm UTC](https://talk.openmrs.org/t/relying-on-swagger-client-code-generator-for-rest-api/8538/1 "2016-10-28T19:04:16Z")

</div>

I have been experimenting with @pascal’s [openmrs.js](https://github.com/psbrandt/openmrs.js) library which generate the js code I need to interact with the REST API. So far I think it is great because it eliminates the need to manually write the required code. However the concern here is how reliable the generated API is? Is it very likely that I might write code that relies on this generator only to break when I upgrade the rest web services module to the new version?

For example, as per usage instruction. if I write this code below how likely that `getAllEncounters()` will change in the future?

```auto
var o = new OpenMRS('http://localhost:8080/openmrs');
o.login('admin', 'Admin123').then(function() {
    o.api.encounter.getAllEncounters('uuid-of-a-patient').then(function(response) {
         //do something with the response
    });
});

```

@dkayiwa, @darius, @wyclif, @raff as the maintainers of the rest webservices and other interested parties what are your thoughts on this?

Linked topic: [openmrs.js (JavaScript API Wrapper)](https://talk.openmrs.org/t/openmrs-js-javascript-api-wrapper/5355):

---

<div class="post-metadata">

**Author:** ![wyclif](https://talk.openmrs.org/user_avatar/talk.openmrs.org/wyclif/32/19607_2.png) [@wyclif](https://talk.openmrs.org/u/wyclif)\
**Post date:** [October 28, 2016, 9:06pm UTC](https://talk.openmrs.org/t/relying-on-swagger-client-code-generator-for-rest-api/8538/2 "2016-10-28T21:06:14Z")

</div>

@pascal might be in the best position to answer that

---

<div class="post-metadata">

**Author:** ![pascal](https://talk.openmrs.org/letter_avatar/pascal/32/6_22734026db12803ebb3e059622ac3534.png) [@pascal](https://talk.openmrs.org/u/pascal)\
**Post date:** [October 28, 2016, 10:56pm UTC](https://talk.openmrs.org/t/relying-on-swagger-client-code-generator-for-rest-api/8538/3 "2016-10-28T22:56:18Z")

</div>

> [@willa](#):
>
> how likely that getAllEncounters() will change in the future?

It is exactly as likely to change as the Encounter resource in the REST Module. If the API changes, your code may break. I don’t think using `openmrs.js` or not has any effect on this.

---

<div class="post-metadata">

**Author:** ![willa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/willa/32/256_2.png) [@willa](https://talk.openmrs.org/u/willa)\
**Post date:** [October 29, 2016, 6:24pm UTC](https://talk.openmrs.org/t/relying-on-swagger-client-code-generator-for-rest-api/8538/4 "2016-10-29T18:24:13Z")

</div>

Actually it is not the same thing. Look at it this way, if I write a javascript method which effectively sends a GET request to [http://localhost:8080/openmrs/ws/rest/v1/encounter](http://localhost:8080/openmrs/ws/rest/v1/encounter), that method will always work regardless of the version of REST I am using as long as the rest endpoint still exist. On the other hand if I use the code generator which gives an method `getAllEncounters()` in one version of the REST module and `getSomeEncounters()` in another my code will break even though both methods may be accessing the same REST endpoint.

---

<div class="post-metadata">

**Author:** ![pascal](https://talk.openmrs.org/letter_avatar/pascal/32/6_22734026db12803ebb3e059622ac3534.png) [@pascal](https://talk.openmrs.org/u/pascal)\
**Post date:** [October 30, 2016, 2:34am UTC](https://talk.openmrs.org/t/relying-on-swagger-client-code-generator-for-rest-api/8538/5 "2016-10-30T02:34:58Z")

</div>

The method names are generated based on the operation and resource names (see [here](https://github.com/openmrs/openmrs-module-webservices.rest/blob/master/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecificationCreator.java#L1232)). Unless that code or the resource name changes, the generated method names should not change.

---

<div class="post-metadata">

**Author:** ![willa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/willa/32/256_2.png) [@willa](https://talk.openmrs.org/u/willa)\
**Post date:** [October 30, 2016, 2:41am UTC](https://talk.openmrs.org/t/relying-on-swagger-client-code-generator-for-rest-api/8538/6 "2016-10-30T02:41:41Z")

</div>

Thanks Pascal. I guess I just needed reassurance.
