Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !10207
An error occurred while fetching the assigned milestone of the selected merge_request.

[chsarp-netcore]handle the exception to get correct error message.

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/Ghufz/meaningful_exception into master 3 years ago
  • Overview 0
  • Commits 2
  • Pipelines 0
  • Changes 43

Created by: Ghufz

Handled the exception for the response object which contains oneOf and anyOf relationship. For any type of error message received from target server it shows

"Exception has been thrown from target of an invocation." 

After Fix it throws following message which is as per the type of error received from target server.

  1. Like for Auth related Error :
The JSON string `{"code":"AuthenticationFailure","message":"Cannot perform the operation. Invalid API key. Verify the API keyID, account and retry the operation.","messageId":"iam_api_key_is_invalid","messageParams":{},"}
` cannot be deserialized into any schema defined.
  1. Target server not available
Error calling GetNtpPolicyList: No such host is known. (xyz.xyz12.com:443)
  1. Invalid query :
The JSON string `{"code":"InvalidRequest","message":"The input query 'groupby(Health)' is invalid. The $apply query option must include both 'groupby' and 'aggregate' statements.","messageId":"odata_apply_query_must_include_groupby_and_aggregate_options","messageParams":{"1":"groupby(Health)"}}` cannot be deserialized into any schema defined.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request. @wing328
Compare
  • master (base)

and
  • latest version
    01ef675a
    2 commits, 2 years ago

43 files
+ 769
- 432

    Preferences

    File browser
    Compare changes
modules/…/…/…/…‎/csharp-netcore‎
ApiClient‎.mustache‎ +8 -1
modelOneO‎f.mustache‎ +18 -10
samples/client/pets‎tore/csharp-netcore‎
OpenAPIClient-http‎client/src/…/Model‎
Mamm‎al.cs‎ +22 -14
Nullable‎Shape.cs‎ +19 -11
Pig‎.cs‎ +19 -11
Quadrila‎teral.cs‎ +19 -11
Shap‎e.cs‎ +19 -11
ShapeOr‎Null.cs‎ +19 -11
Trian‎gle.cs‎ +22 -14
OpenAPIClient-net47‎/…/Org.OpenAPITools‎
Cli‎ent‎
ApiCli‎ent.cs‎ +8 -1
Mo‎del‎
Mamm‎al.cs‎ +22 -14
Nullable‎Shape.cs‎ +19 -11
Pig‎.cs‎ +19 -11
Quadrila‎teral.cs‎ +19 -11
Shap‎e.cs‎ +19 -11
ShapeOr‎Null.cs‎ +19 -11
Trian‎gle.cs‎ +22 -14
OpenAPIClient-net5.‎0/…/Org.OpenAPITools‎
Cli‎ent‎
ApiCli‎ent.cs‎ +8 -1
Mo‎del‎
Mamm‎al.cs‎ +22 -14
Nullable‎Shape.cs‎ +19 -11
Pig‎.cs‎ +19 -11
Quadrila‎teral.cs‎ +19 -11
Shap‎e.cs‎ +19 -11
ShapeOr‎Null.cs‎ +19 -11
Trian‎gle.cs‎ +22 -14
OpenAPIClient/src‎/Org.OpenAPITools‎
Cli‎ent‎
ApiCli‎ent.cs‎ +8 -1
Mo‎del‎
Mamm‎al.cs‎ +22 -14
Nullable‎Shape.cs‎ +19 -11
Pig‎.cs‎ +19 -11
Quadrila‎teral.cs‎ +19 -11
Shap‎e.cs‎ +19 -11
ShapeOr‎Null.cs‎ +19 -11
Trian‎gle.cs‎ +22 -14
OpenAPIClientCo‎re/src/…/Client‎
ApiCli‎ent.cs‎ +8 -1
OpenAPIClientCoreAn‎dNet47/src/…/Client‎
ApiCli‎ent.cs‎ +8 -1
…/‎…/…‎
Cli‎ent‎
ApiCli‎ent.cs‎ +8 -1
Mo‎del‎
Mamm‎al.cs‎ +22 -14
Nullable‎Shape.cs‎ +19 -11
Pig‎.cs‎ +19 -11
Quadrila‎teral.cs‎ +19 -11
Shap‎e.cs‎ +19 -11
ShapeOr‎Null.cs‎ +19 -11
Trian‎gle.cs‎ +22 -14
modules/openapi-generator/src/main/resources/csharp-netcore/ApiClient.mustache
+ 8
- 1
  • View file @ 01ef675a

  • Edit in single-file editor

  • Open in Web IDE


@@ -495,7 +495,14 @@ namespace {{packageName}}.Client
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
if (typeof({{{packageName}}}.{{modelPackage}}.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
{
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
try
{
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
}
catch (Exception ex)
{
throw ex.InnerException != null ? ex.InnerException : ex;
}
}
else if (typeof(T).Name == "Stream") // for binary response
{
modules/openapi-generator/src/main/resources/csharp-netcore/modelOneOf.mustache
+ 18
- 10
  • View file @ 01ef675a

  • Edit in single-file editor

  • Open in Web IDE


@@ -107,17 +107,25 @@
{{#useOneOfDiscriminatorLookup}}
{{#discriminator}}
string discriminatorValue = JObject.Parse(jsonString)["{{{propertyBaseName}}}"].ToString();
switch (discriminatorValue)
try
{
var discriminatorObj = JObject.Parse(jsonString)["{{{propertyBaseName}}}"];
string discriminatorValue = discriminatorObj == null ?string.Empty :discriminatorObj.ToString();
switch (discriminatorValue)
{
{{#mappedModels}}
case "{{{mappingName}}}":
new{{classname}} = new {{classname}}(JsonConvert.DeserializeObject<{{{modelName}}}>(jsonString, {{classname}}.AdditionalPropertiesSerializerSettings));
return new{{classname}};
{{/mappedModels}}
default:
System.Diagnostics.Debug.WriteLine(string.Format("Failed to lookup discriminator value `{0}` for {{classname}}. Possible values:{{#mappedModels}} {{{mappingName}}}{{/mappedModels}}", discriminatorValue));
break;
}
}
catch (Exception ex)
{
{{#mappedModels}}
case "{{{mappingName}}}":
new{{classname}} = new {{classname}}(JsonConvert.DeserializeObject<{{{modelName}}}>(jsonString, {{classname}}.AdditionalPropertiesSerializerSettings));
return new{{classname}};
{{/mappedModels}}
default:
System.Diagnostics.Debug.WriteLine(string.Format("Failed to lookup discriminator value `{0}` for {{classname}}. Possible values:{{#mappedModels}} {{{mappingName}}}{{/mappedModels}}", discriminatorValue));
break;
System.Diagnostics.Debug.WriteLine(string.Format("Failed to parse the json data : `{0}` {1}", jsonString, ex.ToString()));
}
{{/discriminator}}
samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/ApiClient.cs
+ 8
- 1
  • View file @ 01ef675a

  • Edit in single-file editor

  • Open in Web IDE


@@ -494,7 +494,14 @@ namespace Org.OpenAPITools.Client
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
{
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
try
{
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
}
catch (Exception ex)
{
throw ex.InnerException != null ? ex.InnerException : ex;
}
}
else if (typeof(T).Name == "Stream") // for binary response
{
samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Model/Mammal.cs
+ 22
- 14
  • View file @ 01ef675a

  • Edit in single-file editor

  • Open in Web IDE


@@ -170,21 +170,29 @@ namespace Org.OpenAPITools.Model
return newMammal;
}
string discriminatorValue = JObject.Parse(jsonString)["className"].ToString();
switch (discriminatorValue)
try
{
case "Pig":
newMammal = new Mammal(JsonConvert.DeserializeObject<Pig>(jsonString, Mammal.AdditionalPropertiesSerializerSettings));
return newMammal;
case "whale":
newMammal = new Mammal(JsonConvert.DeserializeObject<Whale>(jsonString, Mammal.AdditionalPropertiesSerializerSettings));
return newMammal;
case "zebra":
newMammal = new Mammal(JsonConvert.DeserializeObject<Zebra>(jsonString, Mammal.AdditionalPropertiesSerializerSettings));
return newMammal;
default:
System.Diagnostics.Debug.WriteLine(string.Format("Failed to lookup discriminator value `{0}` for Mammal. Possible values: Pig whale zebra", discriminatorValue));
break;
var discriminatorObj = JObject.Parse(jsonString)["className"];
string discriminatorValue = discriminatorObj == null ?string.Empty :discriminatorObj.ToString();
switch (discriminatorValue)
{
case "Pig":
newMammal = new Mammal(JsonConvert.DeserializeObject<Pig>(jsonString, Mammal.AdditionalPropertiesSerializerSettings));
return newMammal;
case "whale":
newMammal = new Mammal(JsonConvert.DeserializeObject<Whale>(jsonString, Mammal.AdditionalPropertiesSerializerSettings));
return newMammal;
case "zebra":
newMammal = new Mammal(JsonConvert.DeserializeObject<Zebra>(jsonString, Mammal.AdditionalPropertiesSerializerSettings));
return newMammal;
default:
System.Diagnostics.Debug.WriteLine(string.Format("Failed to lookup discriminator value `{0}` for Mammal. Possible values: Pig whale zebra", discriminatorValue));
break;
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(string.Format("Failed to parse the json data : `{0}` {1}", jsonString, ex.ToString()));
}
int match = 0;
samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Model/NullableShape.cs
+ 19
- 11
  • View file @ 01ef675a

  • Edit in single-file editor

  • Open in Web IDE


@@ -153,18 +153,26 @@ namespace Org.OpenAPITools.Model
return newNullableShape;
}
string discriminatorValue = JObject.Parse(jsonString)["shapeType"].ToString();
switch (discriminatorValue)
try
{
case "Quadrilateral":
newNullableShape = new NullableShape(JsonConvert.DeserializeObject<Quadrilateral>(jsonString, NullableShape.AdditionalPropertiesSerializerSettings));
return newNullableShape;
case "Triangle":
newNullableShape = new NullableShape(JsonConvert.DeserializeObject<Triangle>(jsonString, NullableShape.AdditionalPropertiesSerializerSettings));
return newNullableShape;
default:
System.Diagnostics.Debug.WriteLine(string.Format("Failed to lookup discriminator value `{0}` for NullableShape. Possible values: Quadrilateral Triangle", discriminatorValue));
break;
var discriminatorObj = JObject.Parse(jsonString)["shapeType"];
string discriminatorValue = discriminatorObj == null ?string.Empty :discriminatorObj.ToString();
switch (discriminatorValue)
{
case "Quadrilateral":
newNullableShape = new NullableShape(JsonConvert.DeserializeObject<Quadrilateral>(jsonString, NullableShape.AdditionalPropertiesSerializerSettings));
return newNullableShape;
case "Triangle":
newNullableShape = new NullableShape(JsonConvert.DeserializeObject<Triangle>(jsonString, NullableShape.AdditionalPropertiesSerializerSettings));
return newNullableShape;
default:
System.Diagnostics.Debug.WriteLine(string.Format("Failed to lookup discriminator value `{0}` for NullableShape. Possible values: Quadrilateral Triangle", discriminatorValue));
break;
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(string.Format("Failed to parse the json data : `{0}` {1}", jsonString, ex.ToString()));
}
int match = 0;
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
3
3 participants
Administrator
William Cheng
Jim Schubert
Reference:
Source branch: github/fork/Ghufz/meaningful_exception

Menu

Explore Projects Groups Snippets