OpenAPITools / OpenAPITools/openapi-generator
Perl client code not using auth settings
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
openapi-generator 4.2.0
Description
I'm just experimenting with the perl client sources . So far it works, however I had to modify the code, which, I think, shouldn't be necessary. The problem was, to pass auth settings to Role.pm. Role.pm has an attribute cfg which takes all the params passed to the parameter $tokens. it then builds a WWW::OpenAPIClient::Configuration object and calls accept_tokens ($tokens). However, _cfg isn't used further, so it just has no usage at all. After changing in _build_af the line WWW::OpenAPIClient::ApiFactory->new(%args) to WWW::OpenAPIClient::ApiFactory->new($self->_cfg); now did the trick for me.
My code looks like this:
use strict;
package WWW::Chili;
use Moose;
with 'WWW::OpenAPIClient::Role';
1;
package main;
use WWW::Chili;
use Data::Printer;
use feature qw /say/;
my $api_key= 'XE49hk8oGl+Qmm001X9oec+bCsifomL9nk4pacr59kWSY6mtwZOvQSt0Otb4W8UH9f0Qrk0Wzv1JTgSt+KXKYw==';
my $api = WWW::Chili->new(
{
tokens=> { api_key => { token => $api_key}}
}
);
say "config ", np $api->api_factory->{api_client}{config}{api_key};
Result:
./chili_sample.pl
config \ {}
Changing _build_af in Role.pm to
#return WWW::OpenAPIClient::ApiFactory->new(%args);
return WWW::OpenAPIClient::ApiFactory->new($self->_cfg);
gives :
./chili_sample.pl
config \ {
api_key "XE49hk8oGl+Qmm001X9oec+bCsifomL9nk4pacr59kWSY6mtwZOvQSt0Otb4W8UH9f0Qrk0Wzv1JTgSt+KXKYw=="
}
Suggest a fix
Well, I'm not sure what the intended purpose of _cfg really is, so it is difficult to make a suggestion.
I like the idea of the role and flattening the apis to one, so I don't have to care about, which api to use for a method. The problem I was facing with when starting to use the generator is, the my spec doesn't describe the auth method and I didn't find a way, how to do it easily with openapi.
The api-key has to be generated with an extra call (rest_api_generate_api_key) and then added to the header ( api-key : $api_key). This means, I have to create a object instance of WWW::Chili without auth settings, call the api generate api_key method on this and then either create a new instance with settings or set set attributes in config by directly writing to {api_factory}->{api_client}->{config}{api_key} which is not very beautiful. Any idea ?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the generated Perl Role.pm, focusing on _build_af and how cfg is passed to ApiFactory. Reproduce the example with the provided sample Perl code and inspect whether the api_key reaches the api_client configuration. Done means auth settings supplied through cfg are available in the generated client's configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- perl
- Domain
- api, authentication
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100