Swagger codegen, custom code and new stub

Viewed 25

I am tinkering with Swagger Codegen for Python and the Petstore example. I see that the generated stubs rely on Python libraries (swagger_sever, connexion,...).

import connexion
import six

from swagger_server.models.api_response import ApiResponse  # noqa: E501
from swagger_server.models.category import Category  # noqa: E501
from swagger_server.models.pet import Pet  # noqa: E501
from swagger_server.models.tag import Tag  # noqa: E501
from swagger_server import util

def add_pet(body):  # noqa: E501
    """Add a new pet to the store

    Add a new pet to the store # noqa: E501

    :param body: Create a new pet in the store
    :type body: dict | bytes

    :rtype: Pet
    """
    if connexion.request.is_json:
        body = Pet.from_dict(connexion.request.get_json())  # noqa: E501
    return 'do some magic!'

This is fine, but how do I handle the scenario where:

  1. I generate the stubs with CodeGen
  2. I manually add my custom Python logic to implement the actual API (i.e. doing MY MAGIC),
  3. I make changes to the YAML file and need to regenerate the stub.

I imagine the question is: what's the best practice to regenerate the stub and superimpose code that was implemented in the old stub?

Hopefully my question makes sense.

0 Answers
Related