Relying on Swagger Client Code Generator For REST API

I have been experimenting with @pascal’s 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?

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):

@pascal might be in the best position to answer that

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.

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, 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.

The method names are generated based on the operation and resource names (see here). Unless that code or the resource name changes, the generated method names should not change.

Thanks Pascal. I guess I just needed reassurance.

1 Like