Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Flask code with new code generated by Swagger

I recently started using Swagger to generate flask templates: http://editor.swagger.io/#/

My workflow is flawed, and I am wondering where I am going wrong. I:

  1. Use the UI to write the API V1 .yaml
  2. Generate the code using the UI editor, which downloads a stubbed out zip
  3. Write the functions that were stubbed out

This part of the process is fine. However, let's say we want to add a new endpoint or change an existing endpoint. Now what? I:

  1. reload the swagger editor
  2. edit the yaml
  3. generate the code, which downloads a new zip and blows away the old code
  4. take the newly generated code and do a "self-merge" where I copy over the new stub into the old code and copy over the new yaml into the old

It seems there is a gap between the initial generation of the flask template and ongoing maintenance. What am I doing wrong?

like image 318
Tommy Avatar asked Mar 21 '16 14:03

Tommy


1 Answers

Yeah, there isn't really a good workflow for that yet AFAICS.

One thing you can do is check the original generated code into git on a branch called "generated" or similar. Then merge that to master and start working on it. If, at a later point, you extend your swagger definition, you can generate the code again, switch to the generated branch, overwrite the existing code with the newly generated code, commit and merge to master again. If all you had were some additional endpoints, this should even work without any merge conflicts.

It would of course be nicer if the swagger tools had a concept of which code they generated and be able to update generated code, but until then this should be a bearable workaround.

like image 106
Daniel Bachler Avatar answered Nov 20 '22 09:11

Daniel Bachler