forked from loafle/openapi-generator-original
add option, update api doc with better error handling
This commit is contained in:
parent
8d8c86728a
commit
bfb45f4d67
@ -67,6 +67,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
|||||||
public static final String SUPPORT_STREAMING = "supportStreaming";
|
public static final String SUPPORT_STREAMING = "supportStreaming";
|
||||||
public static final String GRADLE_PROPERTIES= "gradleProperties";
|
public static final String GRADLE_PROPERTIES= "gradleProperties";
|
||||||
public static final String ERROR_OBJECT_TYPE= "errorObjectType";
|
public static final String ERROR_OBJECT_TYPE= "errorObjectType";
|
||||||
|
public static final String ERROR_OBJECT_SUBTYPE= "errorObjectSubtype";
|
||||||
|
|
||||||
public static final String PLAY_24 = "play24";
|
public static final String PLAY_24 = "play24";
|
||||||
public static final String PLAY_25 = "play25";
|
public static final String PLAY_25 = "play25";
|
||||||
@ -120,6 +121,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
|||||||
protected boolean supportStreaming = false;
|
protected boolean supportStreaming = false;
|
||||||
protected String gradleProperties;
|
protected String gradleProperties;
|
||||||
protected String errorObjectType;
|
protected String errorObjectType;
|
||||||
|
protected List<String> errorObjectSubtype;
|
||||||
protected String authFolder;
|
protected String authFolder;
|
||||||
protected String serializationLibrary = null;
|
protected String serializationLibrary = null;
|
||||||
|
|
||||||
@ -351,6 +353,11 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
|||||||
}
|
}
|
||||||
additionalProperties.put(ERROR_OBJECT_TYPE, errorObjectType);
|
additionalProperties.put(ERROR_OBJECT_TYPE, errorObjectType);
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(ERROR_OBJECT_SUBTYPE)) {
|
||||||
|
this.setErrorObjectSubtype((List<String>)additionalProperties.get(ERROR_OBJECT_SUBTYPE));
|
||||||
|
}
|
||||||
|
additionalProperties.put(ERROR_OBJECT_SUBTYPE, errorObjectSubtype);
|
||||||
|
|
||||||
final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");
|
final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");
|
||||||
final String apiFolder = (sourceFolder + '/' + apiPackage).replace(".", "/");
|
final String apiFolder = (sourceFolder + '/' + apiPackage).replace(".", "/");
|
||||||
final String modelsFolder = (sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
|
final String modelsFolder = (sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
|
||||||
@ -1042,6 +1049,10 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
|||||||
this.errorObjectType= errorObjectType;
|
this.errorObjectType= errorObjectType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setErrorObjectSubtype(final List<String> errorObjectSubtype) {
|
||||||
|
this.errorObjectSubtype= errorObjectSubtype;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialization library.
|
* Serialization library.
|
||||||
*
|
*
|
||||||
|
@ -63,11 +63,23 @@ public class Example {
|
|||||||
.execute();{{/vendorExtensions.x-group-parameters}}{{#returnType}}
|
.execute();{{/vendorExtensions.x-group-parameters}}{{#returnType}}
|
||||||
System.out.println(result);{{/returnType}}
|
System.out.println(result);{{/returnType}}
|
||||||
} catch (ApiException e) {
|
} catch (ApiException e) {
|
||||||
System.err.println("Exception when calling {{{classname}}}#{{{operationId}}}");
|
{{=< >=}}
|
||||||
System.err.println("Status code: " + e.getCode());
|
<#errorObjectSubtype>
|
||||||
System.err.println("Reason: " + e.getResponseBody());
|
<^-first>} else </-first>if (e.getErrorObject() instanceof <&.>) {
|
||||||
System.err.println("Response headers: " + e.getResponseHeaders());
|
// do something here
|
||||||
e.printStackTrace();
|
<#-last>
|
||||||
|
} else {
|
||||||
|
// something else happened
|
||||||
|
System.err.println("Exception when calling {{{classname}}}#{{{operationId}}}");
|
||||||
|
System.err.println("Status code: " + e.getCode());
|
||||||
|
System.err.println("Reason: " + e.getResponseBody());
|
||||||
|
System.err.println("Response headers: " + e.getResponseHeaders());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
</-last>
|
||||||
|
</errorObjectSubtype>
|
||||||
|
<={{ }}=>
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user