cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
397 stars 132 forks source link

Support toggle of generating $Response methods #201

Open deniszholob opened 2 years ago

deniszholob commented 2 years ago

It should be easy to access the original HttpResponse, for example, to read headers. This is achieved by generating a variant suffixed with $Response for each generated method;

Could there be a toggle in the settings to either generate that or not. I guess right now its a matter of creating a custom template... would be nice to just put in a settings switch though

luisfpg commented 2 years ago

This could be easily done with a configuration option. However, I'm not sure it is a good idea. First, the $Response methods are the actual implementation. The other one delegates to the $Response. But this could be fixed by making them private. Then there's another issue: Suppose you write a system with no $Response variants and you're happy. The next day, there's a requirement to read a single response header. Then, if it is a simple toggle in the configuration, you'll have no option but to enable it globally, and all services will have those methods again. So I'm not really convinced it would be good to allow such configuration.

deniszholob commented 2 years ago

Sure thats a good point, but then thats up to the user? And in that case maybe have a regex pattern to enable it for certain files? It would save on the generated files being way bigger than they need to be; both in terms of file size and cleanliness/ability to quickly glance through them

luisfpg commented 2 years ago

in terms of size, I don't think it would change too much, because one method just delegates to the other. Having a configuration option could then be something like:

{ 
    "publicResponseMethods": false
}

The default would be true to keep backwards compatibility and having by default the ability to access response headers.

Alternatively, the setting could be a list with the operationIds, which should per spec be globally unique:

{ 
    "publicResponseMethods": [
        "operationId1",
        "operationId2"
    ]
}

However, I don't have time currently for working on this project. If you'd like to contribute it as a PR, it would surely be appreciated.

Lonli-Lokli commented 2 years ago

@deniszholob Your request is subset of my feature request https://github.com/cyclosproject/ng-openapi-gen/issues/114

Unfortunately I was not able to solve it during my spare time :(