Skip to content

Commit

Permalink
Merge pull request #5 from OpenAPITools/master
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:OpenAPITools/openapi-generator into fix_apiignore_and_pageable
  • Loading branch information
morphlne authored Mar 11, 2021
2 parents 0d1c88f + 604e141 commit 8c23ee3
Show file tree
Hide file tree
Showing 62 changed files with 706 additions and 574 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,11 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("settingsGradle.mustache", "", "settings.gradle"));
}

supportingFiles.add(new SupportingFile("application.mustache", resourceFolder, "application.yaml"));
supportingFiles.add(new SupportingFile("springBootApplication.mustache",
if (!this.interfaceOnly) {
supportingFiles.add(new SupportingFile("application.mustache", resourceFolder, "application.yaml"));
supportingFiles.add(new SupportingFile("springBootApplication.mustache",
sanitizeDirectory(sourceFolder + File.separator + basePackage), "Application.kt"));
}
}

// spring uses the jackson lib, and we disallow configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ namespace {{packageName}}.Client
}
#else
if (parameter.Value.Count > 1)
{ // array
{ // array
foreach (var value in parameter.Value)
{
httpValues.Add(parameter.Key + "[]", value);
}
}
else
{
httpValues.Add(parameter.Key, parameter.Value[0]);
}
}
else
{
httpValues.Add(parameter.Key, parameter.Value[0]);
}
#endif
}
var uriBuilder = new UriBuilder(string.Concat(basePath, path));
Expand Down Expand Up @@ -256,7 +256,6 @@ namespace {{packageName}}.Client
var authorizationHeaderValue = string.Format("Signature keyId=\"{0}\",algorithm=\"{1}\"",
KeyId, cryptographicScheme);


if (HttpSignatureHeader.ContainsKey(HEADER_CREATED))
{
authorizationHeaderValue += string.Format(",created={0}", HttpSignatureHeader[HEADER_CREATED]);
Expand All @@ -278,7 +277,6 @@ namespace {{packageName}}.Client
private byte[] GetStringHash(string hashName, string stringToBeHashed)
{
var hashAlgorithm = System.Security.Cryptography.HashAlgorithm.Create(hashName);
var bytes = Encoding.UTF8.GetBytes(stringToBeHashed);
var stringHash = hashAlgorithm.ComputeHash(bytes);
return stringHash;
Expand All @@ -298,7 +296,6 @@ namespace {{packageName}}.Client
{
var signedbytes = rsa.SignHash(stringToSign, HashAlgorithm, RSASignaturePadding.Pss);
return Convert.ToBase64String(signedbytes);
}
else if (SigningAlgorithm == "PKCS1-v15")
{
Expand Down Expand Up @@ -472,16 +469,22 @@ namespace {{packageName}}.Client
//-------- read PEM encryption info. lines and extract salt -----
if (!str.ReadLine().StartsWith("Proc-Type: 4,ENCRYPTED"))
{
return null;
}
String saltline = str.ReadLine();
if (!saltline.StartsWith("DEK-Info: DES-EDE3-CBC,"))
{
return null;
}
String saltstr = saltline.Substring(saltline.IndexOf(",") + 1).Trim();
byte[] salt = new byte[saltstr.Length / 2];
for (int i = 0; i < salt.Length; i++)
salt[i] = Convert.ToByte(saltstr.Substring(i * 2, 2), 16);
if (!(str.ReadLine() == ""))
{
return null;
}

//------ remaining b64 data is encrypted RSA key ----
String encryptedstr = str.ReadToEnd();
Expand All @@ -497,7 +500,9 @@ namespace {{packageName}}.Client

byte[] deskey = GetEncryptedKey(salt, keyPassPharse, 1, 2); // count=1 (for OpenSSL implementation); 2 iterations to get at least 24 bytes
if (deskey == null)
{
return null;
}

//------ Decrypt the encrypted 3des-encrypted RSA private key ------
byte[] rsakey = DecryptKey(binkey, deskey, salt); //OpenSSL uses salt value in PEM header also as 3DES IV
Expand All @@ -519,18 +524,28 @@ namespace {{packageName}}.Client
{
twobytes = binr.ReadUInt16();
if (twobytes == 0x8130) //data read as little endian order (actual data order for Sequence is 30 81)
{
binr.ReadByte(); //advance 1 byte
}
else if (twobytes == 0x8230)
{
binr.ReadInt16(); //advance 2 bytes
}
else
{
return null;
}

twobytes = binr.ReadUInt16();
if (twobytes != 0x0102) //version number
{
return null;
}
bt = binr.ReadByte();
if (bt != 0x00)
{
return null;
}

//------ all private key components are Integer sequences ----
elems = GetIntegerSize(binr);
Expand Down Expand Up @@ -575,7 +590,10 @@ namespace {{packageName}}.Client
{
return null;
}
finally { binr.Close(); }
finally
{
binr.Close();
}
}

private int GetIntegerSize(BinaryReader binr)
Expand All @@ -585,12 +603,16 @@ namespace {{packageName}}.Client
byte highbyte = 0x00;
int count = 0;
bt = binr.ReadByte();
if (bt != 0x02) //expect integer
if (bt != 0x02) //expect integer
{
return 0;
}
bt = binr.ReadByte();

if (bt == 0x81)
{
count = binr.ReadByte(); // data size in next byte
}
else if (bt == 0x82)
{
highbyte = binr.ReadByte(); // data size in next 2 bytes
Expand All @@ -603,7 +625,8 @@ namespace {{packageName}}.Client
count = bt; // we already have the data size
}
while (binr.ReadByte() == 0x00)
{ //remove high order zeros in data
{
//remove high order zeros in data
count -= 1;
}
binr.BaseStream.Seek(-1, SeekOrigin.Current);
Expand Down Expand Up @@ -636,7 +659,9 @@ namespace {{packageName}}.Client
{
// ---- Now hash consecutively for count times ------
if (j == 0)
{
result = data00; //initialize
}
else
{
Array.Copy(result, hashtarget, result.Length);
Expand Down Expand Up @@ -714,7 +739,7 @@ namespace {{packageName}}.Client
key[key.Length - 1].ToString().Contains(ecPrivateKeyFooter))
{
/*this type of key can hold many type different types of private key, but here due lack of pem header
/* this type of key can hold many type different types of private key, but here due lack of pem header
Considering this as EC key
*/
//TODO :- update the key based on oid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ name: {{pubName}}
version: {{pubVersion}}
description: {{pubDescription}}
environment:
sdk: ">=2.7.0 <3.0.0"
sdk: '>=2.7.0 <3.0.0'
dependencies:
dio: ^3.0.9
built_value: ">=7.1.0 <9.0.0"
built_collection: ">=4.3.2 <6.0.0"
built_value: '>=7.1.0 <8.0.0'
built_collection: '>=4.3.2 <5.0.0'
{{#timeMachine}}
time_machine: ^0.9.12
{{/timeMachine}}
dev_dependencies:
built_value_generator: ">=7.1.0 <9.0.0"
built_value_generator: '>=7.1.0 <8.0.0'
build_runner: ^1.7.1
test: ">=1.3.0 <1.16.0"
test: '>=1.3.0 <1.16.0'
46 changes: 36 additions & 10 deletions modules/openapi-generator/src/main/resources/dart2/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class {{{classname}}} {
{{/allParams}}

{{/hasParams}}
final path = '{{{path}}}'{{#pathParams}}
final path = r'{{{path}}}'{{#pathParams}}
.replaceAll('{' + '{{{baseName}}}' + '}', {{{paramName}}}.toString()){{/pathParams}};

Object postBody{{#bodyParam}} = {{{paramName}}}{{/bodyParam}};
Expand Down Expand Up @@ -185,21 +185,47 @@ class {{{classname}}} {
// At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
// FormatException when trying to decode an empty string.
if (response.body != null && response.statusCode != HttpStatus.noContent) {
{{#isArray}}
{{#native_serialization}}
{{#isArray}}
return (apiClient.deserialize(_decodeBodyBytes(response), '{{{returnType}}}') as List)
.cast<{{{returnBaseType}}}>()
.{{#uniqueItems}}toSet(){{/uniqueItems}}{{^uniqueItems}}toList(growable: false){{/uniqueItems}};
{{/isArray}}
{{^isArray}}
{{#isMap}}
{{/isArray}}
{{^isArray}}
{{#isMap}}
return {{{returnType}}}.from(apiClient.deserialize(_decodeBodyBytes(response), '{{{returnType}}}'));
{{/isMap}}
{{^isMap}}
{{/isMap}}
{{^isMap}}
return apiClient.deserialize(_decodeBodyBytes(response), '{{{returnType}}}') as {{{returnType}}};
{{/isMap}}
{{/isArray}}
{{/isMap}}{{/isArray}}{{/native_serialization}}{{#json_serializable}}
{{#isArray}}
{{#uniqueItems}}
return (json.decode(response.body) as List)
.map((i) => {{{returnBaseType}}}.fromJson(i))
.toSet();
{{/uniqueItems}}
{{^uniqueItems}}
return (json.decode(response.body) as List)
.map((i) => {{{returnBaseType}}}.fromJson(i))
.toList();
{{/uniqueItems}}
{{/isArray}}
{{^isArray}}
{{#isMap}}
return {{{returnType}}}.from(json.decode(response.body));
{{/isMap}}
{{^isMap}}
{{#returnTypeIsPrimitive}}
return response.body as {{{returnBaseType}}};
{{/returnTypeIsPrimitive}}
{{^returnTypeIsPrimitive}}
return {{{returnType}}}.fromJson(json.decode(response.body));
{{/returnTypeIsPrimitive}}
{{/isMap}}
{{/isArray}}
{{/json_serializable}}
}
return null;
return Future<{{{returnType}}}>.value(null);
{{/returnType}}
}
{{/operation}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,6 @@ class ApiClient {
Map<String, Authentication> get authentications =>
Map.unmodifiable(_authentications);

dynamic deserialize(String json, String targetType, {bool growable}) {
// Remove all spaces. Necessary for reg expressions as well.
targetType = targetType.replaceAll(' ', '');
return targetType == 'String'
? json
: _deserialize(jsonDecode(json), targetType, growable: true == growable);
}

String serialize(Object obj) => obj == null ? '' : json.encode(obj);

T getAuthentication<T extends Authentication>(String name) {
final authentication = _authentications[name];
return authentication is T ? authentication : null;
Expand Down Expand Up @@ -159,6 +148,7 @@ class ApiClient {
throw ApiException(HttpStatus.badRequest, 'Invalid HTTP operation: $method $path',);
}

{{#native_serialization}}
dynamic _deserialize(dynamic value, String targetType, {bool growable}) {
try {
switch (targetType) {
Expand Down Expand Up @@ -216,6 +206,18 @@ class ApiClient {
throw ApiException(HttpStatus.internalServerError, 'Could not find a suitable class for deserialization',);
}

dynamic deserialize(String json, String targetType, {bool growable}) {
// Remove all spaces. Necessary for reg expressions as well.
targetType = targetType.replaceAll(' ', '');
return targetType == 'String'
? json
: _deserialize(jsonDecode(json), targetType, growable: true == growable);
}
{{/native_serialization}}

String serialize(Object obj) => obj == null ? '' : json.encode(obj);

/// Update query and header parameters based on authentication settings.
/// @param authNames The authentications to apply
void _updateParamsForAuth(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ String parameterToString(dynamic value) {
{{#model}}
{{#isEnum}}
if (value is {{{classname}}}) {
{{#native_serialization}} return {{{classname}}}TypeTransformer().encode(value).toString();{{/native_serialization}}
{{#json_serializable}} return _${{{classname}}}EnumMap[value];{{/json_serializable}}
{{#native_serialization}} return {{{classname}}}TypeTransformer().encode(value).toString();{{/native_serialization}}{{#json_serializable}} return value.toString();{{/json_serializable}}
}
{{/isEnum}}
{{/model}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class AppModule {}
// configuring providers
import { {{apiModuleClassName}}, {{configurationClassName}}, {{configurationParametersInterfaceName}} } from '{{npmName}}';

export function apiConfigFactory (): {{configurationClassName}} => {
export function apiConfigFactory (): {{configurationClassName}} {
const params: {{configurationParametersInterfaceName}} = {
// set configuration parameters here.
}
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,7 @@
<module>samples/client/petstore/dart2/petstore</module>
<module>samples/openapi3/client/petstore/dart2/petstore_client_lib</module>
<module>samples/openapi3/client/petstore/dart2/petstore</module>
<module>samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake</module>
<module>samples/client/petstore/dart-dio/petstore_client_lib</module>
<module>samples/openapi3/client/petstore/dart-dio/petstore_client_lib</module>
<module>samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake</module>
Expand Down
Loading

0 comments on commit 8c23ee3

Please sign in to comment.