Skip to content

Commit f51c213

Browse files
authored
Merge pull request #2 from OpenAPITools/master
merge from source
2 parents 8cf9ddb + 7d6063d commit f51c213

File tree

71 files changed

+227
-382
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+227
-382
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.openapitools.codegen.languages;
1818

19-
import com.google.common.collect.Sets;
2019
import io.swagger.v3.core.util.Json;
2120
import io.swagger.v3.oas.models.media.*;
2221
import io.swagger.v3.oas.models.media.ArraySchema;
@@ -880,7 +879,7 @@ private String ensureQuotes(String in) {
880879

881880
public String toExampleValue(Schema schema, Object objExample) {
882881
String modelName = getModelName(schema);
883-
return toExampleValueRecursive(modelName, schema, objExample, 1, "", 0, Sets.newHashSet());
882+
return toExampleValueRecursive(modelName, schema, objExample, 1, "", 0);
884883
}
885884

886885
private Boolean simpleStringSchema(Schema schema) {
@@ -926,12 +925,9 @@ private MappedModel getDiscriminatorMappedModel(CodegenDiscriminator disc) {
926925
* ModelName( line 0
927926
* some_property='some_property_example' line 1
928927
* ) line 2
929-
* @param seenSchemas This set contains all the schemas passed into the recursive function. It is used to check
930-
* if a schema was already passed into the function and breaks the infinite recursive loop. The
931-
* only schemas that are not added are ones that contain $ref != null
932928
* @return the string example
933929
*/
934-
private String toExampleValueRecursive(String modelName, Schema schema, Object objExample, int indentationLevel, String prefix, Integer exampleLine, Set<Schema> seenSchemas) {
930+
private String toExampleValueRecursive(String modelName, Schema schema, Object objExample, int indentationLevel, String prefix, Integer exampleLine) {
935931
final String indentionConst = " ";
936932
String currentIndentation = "";
937933
String closingIndentation = "";
@@ -955,27 +951,6 @@ private String toExampleValueRecursive(String modelName, Schema schema, Object o
955951
if (objExample != null) {
956952
example = objExample.toString();
957953
}
958-
// checks if the current schema has already been passed in. If so, breaks the current recursive pass
959-
if (seenSchemas.contains(schema)){
960-
if (modelName != null) {
961-
return fullPrefix + modelName + closeChars;
962-
} else {
963-
// this is a recursive schema
964-
// need to add a reasonable example to avoid
965-
// infinite recursion
966-
if(ModelUtils.isNullable(schema)) {
967-
// if the schema is nullable, then 'None' is a valid value
968-
return fullPrefix + "None" + closeChars;
969-
} else if(ModelUtils.isArraySchema(schema)) {
970-
// the schema is an array, add an empty array
971-
return fullPrefix + "[]" + closeChars;
972-
} else {
973-
// the schema is an object, make an empty object
974-
return fullPrefix + "{}" + closeChars;
975-
}
976-
}
977-
}
978-
979954
if (null != schema.get$ref()) {
980955
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
981956
String ref = ModelUtils.getSimpleRef(schema.get$ref());
@@ -985,7 +960,7 @@ private String toExampleValueRecursive(String modelName, Schema schema, Object o
985960
return fullPrefix + "None" + closeChars;
986961
}
987962
String refModelName = getModelName(schema);
988-
return toExampleValueRecursive(refModelName, refSchema, objExample, indentationLevel, prefix, exampleLine, seenSchemas);
963+
return toExampleValueRecursive(refModelName, refSchema, objExample, indentationLevel, prefix, exampleLine);
989964
} else if (ModelUtils.isNullType(schema) || isAnyTypeSchema(schema)) {
990965
// The 'null' type is allowed in OAS 3.1 and above. It is not supported by OAS 3.0.x,
991966
// though this tooling supports it.
@@ -1083,8 +1058,7 @@ private String toExampleValueRecursive(String modelName, Schema schema, Object o
10831058
ArraySchema arrayschema = (ArraySchema) schema;
10841059
Schema itemSchema = arrayschema.getItems();
10851060
String itemModelName = getModelName(itemSchema);
1086-
seenSchemas.add(schema);
1087-
example = fullPrefix + "[" + "\n" + toExampleValueRecursive(itemModelName, itemSchema, objExample, indentationLevel + 1, "", exampleLine + 1, seenSchemas) + ",\n" + closingIndentation + "]" + closeChars;
1061+
example = fullPrefix + "[" + "\n" + toExampleValueRecursive(itemModelName, itemSchema, objExample, indentationLevel + 1, "", exampleLine + 1) + ",\n" + closingIndentation + "]" + closeChars;
10881062
return example;
10891063
} else if (ModelUtils.isMapSchema(schema)) {
10901064
if (modelName == null) {
@@ -1106,8 +1080,7 @@ private String toExampleValueRecursive(String modelName, Schema schema, Object o
11061080
addPropPrefix = ensureQuotes(key) + ": ";
11071081
}
11081082
String addPropsModelName = getModelName(addPropsSchema);
1109-
seenSchemas.add(schema);
1110-
example = fullPrefix + "\n" + toExampleValueRecursive(addPropsModelName, addPropsSchema, addPropsExample, indentationLevel + 1, addPropPrefix, exampleLine + 1, seenSchemas) + ",\n" + closingIndentation + closeChars;
1083+
example = fullPrefix + "\n" + toExampleValueRecursive(addPropsModelName, addPropsSchema, addPropsExample, indentationLevel + 1, addPropPrefix, exampleLine + 1) + ",\n" + closingIndentation + closeChars;
11111084
} else {
11121085
example = fullPrefix + closeChars;
11131086
}
@@ -1130,12 +1103,7 @@ private String toExampleValueRecursive(String modelName, Schema schema, Object o
11301103
return fullPrefix + closeChars;
11311104
}
11321105
}
1133-
// Adds schema to seenSchemas before running example model function. romoves schema after running
1134-
// the function. It also doesnt keep track of any schemas within the ObjectModel.
1135-
seenSchemas.add(schema);
1136-
String exampleForObjectModel = exampleForObjectModel(schema, fullPrefix, closeChars, null, indentationLevel, exampleLine, closingIndentation, seenSchemas);
1137-
seenSchemas.remove(schema);
1138-
return exampleForObjectModel;
1106+
return exampleForObjectModel(schema, fullPrefix, closeChars, null, indentationLevel, exampleLine, closingIndentation);
11391107
} else if (ModelUtils.isComposedSchema(schema)) {
11401108
// TODO add examples for composed schema models without discriminators
11411109

@@ -1149,12 +1117,7 @@ private String toExampleValueRecursive(String modelName, Schema schema, Object o
11491117
CodegenProperty cp = new CodegenProperty();
11501118
cp.setName(disc.getPropertyName());
11511119
cp.setExample(discPropNameValue);
1152-
// Adds schema to seenSchemas before running example model function. romoves schema after running
1153-
// the function. It also doesnt keep track of any schemas within the ObjectModel.
1154-
seenSchemas.add(modelSchema);
1155-
String exampleForObjectModel = exampleForObjectModel(modelSchema, fullPrefix, closeChars, cp, indentationLevel, exampleLine, closingIndentation, seenSchemas);
1156-
seenSchemas.remove(modelSchema);
1157-
return exampleForObjectModel;
1120+
return exampleForObjectModel(modelSchema, fullPrefix, closeChars, cp, indentationLevel, exampleLine, closingIndentation);
11581121
} else {
11591122
return fullPrefix + closeChars;
11601123
}
@@ -1167,7 +1130,7 @@ private String toExampleValueRecursive(String modelName, Schema schema, Object o
11671130
return example;
11681131
}
11691132

1170-
private String exampleForObjectModel(Schema schema, String fullPrefix, String closeChars, CodegenProperty discProp, int indentationLevel, int exampleLine, String closingIndentation, Set<Schema> seenSchemas) {
1133+
private String exampleForObjectModel(Schema schema, String fullPrefix, String closeChars, CodegenProperty discProp, int indentationLevel, int exampleLine, String closingIndentation) {
11711134
Map<String, Schema> requiredAndOptionalProps = schema.getProperties();
11721135
if (requiredAndOptionalProps == null || requiredAndOptionalProps.isEmpty()) {
11731136
return fullPrefix + closeChars;
@@ -1187,7 +1150,7 @@ private String exampleForObjectModel(Schema schema, String fullPrefix, String cl
11871150
propModelName = getModelName(propSchema);
11881151
propExample = exampleFromStringOrArraySchema(propSchema, null, propName);
11891152
}
1190-
example += toExampleValueRecursive(propModelName, propSchema, propExample, indentationLevel + 1, propName + "=", exampleLine + 1, seenSchemas) + ",\n";
1153+
example += toExampleValueRecursive(propModelName, propSchema, propExample, indentationLevel + 1, propName + "=", exampleLine + 1) + ",\n";
11911154
}
11921155
// TODO handle additionalProperties also
11931156
example += closingIndentation + closeChars;

modules/openapi-generator/src/main/resources/swift5/Models.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ protocol JSONEncodable {
1111
}
1212

1313
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum ErrorResponse : Error {
14-
case error(Int, Data?, Error)
14+
case error(Int, Data?, URLResponse?, Error)
1515
}
1616

1717
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum DownloadException : Error {

modules/openapi-generator/src/main/resources/swift5/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extension {{projectName}}API {
4848
{{#isDeprecated}}
4949
@available(*, deprecated, message: "This operation is deprecated.")
5050
{{/isDeprecated}}
51-
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func {{operationId}}({{#allParams}}{{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}apiResponseQueue: DispatchQueue = {{projectName}}API.apiResponseQueue, completion: @escaping ((_ data: {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}?,_ error: Error?) -> Void)) {
51+
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func {{operationId}}({{#allParams}}{{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}apiResponseQueue: DispatchQueue = {{projectName}}API.apiResponseQueue, completion: @escaping ((_ data: {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}?, _ error: Error?) -> Void)) {
5252
{{operationId}}WithRequestBuilder({{#allParams}}{{paramName}}: {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}).execute(apiResponseQueue) { result -> Void in
5353
switch result {
5454
{{#returnType}}

modules/openapi-generator/src/main/resources/swift5/libraries/alamofire/AlamofireImplementations.mustache

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.SessionManag
103103
self.processRequest(request: upload, managerId, apiResponseQueue, completion)
104104
case .failure(let encodingError):
105105
apiResponseQueue.async{
106-
completion(.failure(ErrorResponse.error(415, nil, encodingError)))
106+
completion(.failure(ErrorResponse.error(415, nil, nil, encodingError)))
107107
}
108108
}
109109
})
@@ -137,7 +137,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.SessionManag
137137
case let .success(value):
138138
completion(.success(Response(response: stringResponse.response!, body: value as? T)))
139139
case let .failure(error):
140-
completion(.failure(ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, error)))
140+
completion(.failure(ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.response, error)))
141141
}
142142

143143
})
@@ -179,9 +179,9 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.SessionManag
179179
completion(.success(Response(response: dataResponse.response!, body: filePath as? T)))
180180

181181
} catch let requestParserError as DownloadException {
182-
completion(.failure(ErrorResponse.error(400, dataResponse.data, requestParserError)))
182+
completion(.failure(ErrorResponse.error(400, dataResponse.data, dataResponse.response, requestParserError)))
183183
} catch let error {
184-
completion(.failure(ErrorResponse.error(400, dataResponse.data, error)))
184+
completion(.failure(ErrorResponse.error(400, dataResponse.data, dataResponse.response, error)))
185185
}
186186
return
187187
})
@@ -193,7 +193,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.SessionManag
193193
case .success:
194194
completion(.success(Response(response: voidResponse.response!, body: nil)))
195195
case let .failure(error):
196-
completion(.failure(ErrorResponse.error(voidResponse.response?.statusCode ?? 500, voidResponse.data, error)))
196+
completion(.failure(ErrorResponse.error(voidResponse.response?.statusCode ?? 500, voidResponse.data, voidResponse.response, error)))
197197
}
198198

199199
})
@@ -205,7 +205,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.SessionManag
205205
case .success:
206206
completion(.success(Response(response: dataResponse.response!, body: dataResponse.data as? T)))
207207
case let .failure(error):
208-
completion(.failure(ErrorResponse.error(dataResponse.response?.statusCode ?? 500, dataResponse.data, error)))
208+
completion(.failure(ErrorResponse.error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.response, error)))
209209
}
210210

211211
})
@@ -295,7 +295,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.SessionManag
295295
case let .success(value):
296296
completion(.success(Response(response: stringResponse.response!, body: value as? T)))
297297
case let .failure(error):
298-
completion(.failure(ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, error)))
298+
completion(.failure(ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.response, error)))
299299
}
300300

301301
})
@@ -307,7 +307,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.SessionManag
307307
case .success:
308308
completion(.success(Response(response: voidResponse.response!, body: nil)))
309309
case let .failure(error):
310-
completion(.failure(ErrorResponse.error(voidResponse.response?.statusCode ?? 500, voidResponse.data, error)))
310+
completion(.failure(ErrorResponse.error(voidResponse.response?.statusCode ?? 500, voidResponse.data, voidResponse.response, error)))
311311
}
312312

313313
})
@@ -319,7 +319,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.SessionManag
319319
case .success:
320320
completion(.success(Response(response: dataResponse.response!, body: dataResponse.data as? T)))
321321
case let .failure(error):
322-
completion(.failure(ErrorResponse.error(dataResponse.response?.statusCode ?? 500, dataResponse.data, error)))
322+
completion(.failure(ErrorResponse.error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.response, error)))
323323
}
324324

325325
})
@@ -328,17 +328,17 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.SessionManag
328328
cleanupRequest()
329329
330330
guard dataResponse.result.isSuccess else {
331-
completion(.failure(ErrorResponse.error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.result.error!)))
331+
completion(.failure(ErrorResponse.error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.response, dataResponse.result.error!)))
332332
return
333333
}
334334

335335
guard let data = dataResponse.data, !data.isEmpty else {
336-
completion(.failure(ErrorResponse.error(-1, nil, DecodableRequestBuilderError.emptyDataResponse)))
336+
completion(.failure(ErrorResponse.error(-1, nil, dataResponse.response, DecodableRequestBuilderError.emptyDataResponse)))
337337
return
338338
}
339339

340340
guard let httpResponse = dataResponse.response else {
341-
completion(.failure(ErrorResponse.error(-2, nil, DecodableRequestBuilderError.nilHTTPResponse)))
341+
completion(.failure(ErrorResponse.error(-2, nil, dataResponse.response, DecodableRequestBuilderError.nilHTTPResponse)))
342342
return
343343
}
344344

@@ -348,7 +348,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.SessionManag
348348
case let .success(decodableObj):
349349
completion(.success(Response(response: httpResponse, body: decodableObj)))
350350
case let .failure(error):
351-
completion(.failure(ErrorResponse.error(httpResponse.statusCode, data, error)))
351+
completion(.failure(ErrorResponse.error(httpResponse.statusCode, data, httpResponse, error)))
352352
}
353353

354354
})

0 commit comments

Comments
 (0)