Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[typescript] Adding Custom Agent Support for fetch call #11400

Merged
merged 9 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import * as URLParse from "url-parse";
{{/deno}}
{{/platforms}}
import { Observable, from } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'../rxjsStub{{extensionForDeno}}'{{/useRxJS}};
import * as http from 'http';
import * as https from 'https';

{{#platforms}}
{{^deno}}
Expand Down Expand Up @@ -113,6 +115,7 @@ export class RequestContext {
private headers: { [key: string]: string } = {};
private body: RequestBody = undefined;
private url: URLParse;
private agent: http.Agent | https.Agent | undefined = undefined;

/**
* Creates the request context using a http method and request resource url
Expand Down Expand Up @@ -185,6 +188,14 @@ export class RequestContext {
public setHeaderParam(key: string, value: string): void {
this.headers[key] = value;
}

public setAgent(agent: http.Agent | https.Agent) {
this.agent = agent;
}

public getAgent(): http.Agent | https.Agent | undefined {
return this.agent;
}
}

export interface ResponseBody {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class IsomorphicFetchHttpLibrary implements HttpLibrary {
method: method,
body: body as any,
headers: request.getHeaders(),
agent: request.getAgent(),
{{#platforms}}
{{#browser}}
credentials: "same-origin"
Expand Down
183 changes: 0 additions & 183 deletions samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Foo.pm
Original file line number Diff line number Diff line change
@@ -1,183 +0,0 @@
=begin comment

OpenAPI Petstore

This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\

The version of the OpenAPI document: 1.0.0

Generated by: https://openapi-generator.tech

=end comment

=cut

#
# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
# Do not edit the class manually.
# Ref: https://openapi-generator.tech
#
package WWW::OpenAPIClient::Object::Foo;

require 5.6.0;
use strict;
use warnings;
use utf8;
use JSON qw(decode_json);
use Data::Dumper;
use Module::Runtime qw(use_module);
use Log::Any qw($log);
use Date::Parse;
use DateTime;


use base ("Class::Accessor", "Class::Data::Inheritable");

#
#
#
# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). Do not edit the class manually.
# REF: https://openapi-generator.tech
#

=begin comment

OpenAPI Petstore

This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\

The version of the OpenAPI document: 1.0.0

Generated by: https://openapi-generator.tech

=end comment

=cut

#
# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
# Do not edit the class manually.
# Ref: https://openapi-generator.tech
#
__PACKAGE__->mk_classdata('attribute_map' => {});
__PACKAGE__->mk_classdata('openapi_types' => {});
__PACKAGE__->mk_classdata('method_documentation' => {});
__PACKAGE__->mk_classdata('class_documentation' => {});

# new plain object
sub new {
my ($class, %args) = @_;

my $self = bless {}, $class;

$self->init(%args);

return $self;
}

# initialize the object
sub init
{
my ($self, %args) = @_;

foreach my $attribute (keys %{$self->attribute_map}) {
my $args_key = $self->attribute_map->{$attribute};
$self->$attribute( $args{ $args_key } );
}
}

# return perl hash
sub to_hash {
my $self = shift;
my $_hash = decode_json(JSON->new->convert_blessed->encode($self));

return $_hash;
}

# used by JSON for serialization
sub TO_JSON {
my $self = shift;
my $_data = {};
foreach my $_key (keys %{$self->attribute_map}) {
if (defined $self->{$_key}) {
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
}
}

return $_data;
}

# from Perl hashref
sub from_hash {
my ($self, $hash) = @_;

# loop through attributes and use openapi_types to deserialize the data
while ( my ($_key, $_type) = each %{$self->openapi_types} ) {
my $_json_attribute = $self->attribute_map->{$_key};
if ($_type =~ /^array\[(.+)\]$/i) { # array
my $_subclass = $1;
my @_array = ();
foreach my $_element (@{$hash->{$_json_attribute}}) {
push @_array, $self->_deserialize($_subclass, $_element);
}
$self->{$_key} = \@_array;
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
my $_subclass = $1;
my %_hash = ();
while (my($_key, $_element) = each %{$hash->{$_json_attribute}}) {
$_hash{$_key} = $self->_deserialize($_subclass, $_element);
}
$self->{$_key} = \%_hash;
} elsif (exists $hash->{$_json_attribute}) { #hash(model), primitive, datetime
$self->{$_key} = $self->_deserialize($_type, $hash->{$_json_attribute});
} else {
$log->debugf("Warning: %s (%s) does not exist in input hash\n", $_key, $_json_attribute);
}
}

return $self;
}

# deserialize non-array data
sub _deserialize {
my ($self, $type, $data) = @_;
$log->debugf("deserializing %s with %s",Dumper($data), $type);

if ($type eq 'DateTime') {
return DateTime->from_epoch(epoch => str2time($data));
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
return $data;
} else { # hash(model)
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
return $_instance->from_hash($data);
}
}


__PACKAGE__->class_documentation({description => '',
class => 'Foo',
required => [], # TODO
} );

__PACKAGE__->method_documentation({
'bar' => {
datatype => 'string',
base_name => 'bar',
description => '',
format => '',
read_only => '',
},
});

__PACKAGE__->openapi_types( {
'bar' => 'string'
} );

__PACKAGE__->attribute_map( {
'bar' => 'bar'
} );

__PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map});


1;
16 changes: 0 additions & 16 deletions samples/client/petstore/php-dt/src/App/DTO/Collection25.php
Original file line number Diff line number Diff line change
@@ -1,16 +0,0 @@
<?php
declare(strict_types=1);

namespace App\DTO;

use Articus\DataTransfer\Annotation as DTA;

/**
* @DTA\Strategy(name="ObjectList", options={"type":\App\DTO\Tag::class})
* @DTA\Validator(name="Collection", options={"validators":{
* {"name":"TypeCompliant", "options":{"type":\App\DTO\Tag::class}}
* }})
*/
class Collection25 extends \ArrayObject
{
}
Loading