Swagger-codegen: [PHP] Add support for Generation Gap pattern

Created on 6 Jun 2017  ·  5Comments  ·  Source: swagger-api/swagger-codegen

Description

Generation Gap pattern is useful for extending codes which generated.

Generation Gap pattern

Generation Gap martinfowler.com
https://martinfowler.com/dslCatalog/generationGap.html

Generation Gap is about keeping the generated and handwritten parts separate by putting them in different classes linked by inheritance.

Sample
class HandwrittenPet extends Pet
{
    // just a sample.
    // it has room for improvement.
    public function canNotBuy()
    {
        return $this->status === ‘pending’ || $this->status === ‘sold’;
    }
}

$api = new PetApi();

// I'd like to add `setReturnType()` to specify the ReturnType.
$api->setReturnType(‘\Path\To\HanwrittenPet’);

$pet = $api->getPetById(1);
var_dump($pet);
// class \Path\To\HanwrittenPet

var_dump($pet->canNotBuy());
// bool
Swagger-codegen version

2.3.0+

--

How you do you feel about it?

PHP Suggestion

All 5 comments

@ackintosh thanks for the suggestion.

cc @baartosz, @arnested @dkarlovi for feedback.

@baartosz @arnested @dkarlovi Please let me know what you think 🙏 ✨

@ackintosh thanks for suggestion. Personally I prefer to keep clients as simple as possible as its always painful to test them properly. Feature itself looks simple to implement so I don't see any reason not to do it if others find it useful.

@baartosz Thanks for your comment ! I will make a pull request for now :)

@ackintosh sorry about the delay.

I'm for that, generated code should be easily re-generated without nullifying your local additions. Seeing as doing that with only one class would require this tool to have knowledge of PHP AST, separate classes are a logical alternative. :+1:

Was this page helpful?
0 / 5 - 0 ratings