3

I am using openapi-generator to generate server stub python code. Everything works fine, however, every time I make a change in the OpenAPI specs (the yaml file), the code generator overwrites the whole code, even the one customized (the controller). I would like to develop an incremental workflow, where if I make a change in the specs, the generator modifies the code handling that part of the code only.

It would be great if I get to the point where I can enforce the specs and also have an incremental workflow.

I am using openapi-generator version 3.3.4.

I tried to modify the controller and remove # noqa: E501, but it still overwrites the code every time I generate the stub from the specs.

How can I isolate the controller implementation by the generated interface, since the generated code is not OOP?

  • v4.1.3 (https://twitter.com/oas_generator/status/1180123829626003456) has been released. Please upgrade to the latest stable version. – William Cheng Oct 17 '19 at 02:50

4 Answers4

2

To over come this problem I put my end point implementations into files in a openapi_server/implementation/ module and then I implemented a patching system in my build process.

I generate the server stub and then apply a patch to the server endpoint stubs in openapi_server/controller.

The patch includes adding various imports to endpoint implementation functions, replaces the return 'do some magic!' lines with a calls to their end point implementations and even removes the # noqa: E501 comments where I don't want them.

With this system in place my openapi-generator can overwrite the openapi_server/controller directory each time it runs, and in the end I still end up with these files in a state that calls the implementations I need and any other tweaks I wanted have been applied.

Clayton Mills
  • 86
  • 1
  • 9
1

Best solution i found, worked perfectly

Use two branch : One with raw server stub, One with server stub filled with your code.

Generate new server stub versions only on the raw branch an merge it to other branch wich contains previous server stub filled with your code.

My workflow :

Each time i need to modify the server stub i checkout the raw server stub branch => then modify the openAPi file => then generate the server stub => then commit => then checkout the dev branch => then merge raw server stub branch into my dev branch.

For now it works well :). Hope it helps.

Gus tutu
  • 31
  • 6
0

An easy workaround is to add openapi_server/controllers in the .openapi-generator-ignore file so that they are not overwritten every time you update your API contract.

You'll have to manually create these files yourself though

davidlj95
  • 124
  • 7
0

I tried to modify the controller and remove # noqa: E501, but it still overwrites the code every time I generate the stub from the specs.

You may want to use customized templates with the -t option.

William Cheng
  • 10,137
  • 5
  • 54
  • 79