-
Notifications
You must be signed in to change notification settings - Fork 6k
CSharp code generator - http return code 201 causes an exception #730
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
Comments
Is it correct to say that the issue also occurs in the "csharp_restcsharp" PR #700 ? |
Yes, this is the generated code: |
See #731 for a tiny fix. |
#700 seems to remove/replace the broken code also. |
@boazsapir In the generated C# code (csharp_restsharp branch), I couldn't find any reference to
|
@wing328 - sorry for the confusion, I see now that the file ApiInvoker.cs (which had been originally created by the master code) has not been re-created when I used the csharp_restsharp code for generation, therefore the HttpStatusCode problem remained. java.lang.RuntimeException: object (reserved word) cannot be used as a model name |
I would recommend you to test against the develop_2.0 branch which contains bug fixes and enhancements that will be merged into master later toModelName (in develop_2.0 branch) aims to prevent the use of C# reserved words as class/object name Would it be possible to rename the model using a non-reserved keyword ? |
I do not have a model named 'object', the failure is because the code checks the property type against the list of reserved words: @Override
public String getSwaggerType(Property p) {
String swaggerType = super.getSwaggerType(p);
String type = null;
if(typeMapping.containsKey(swaggerType)) {
type = typeMapping.get(swaggerType);
if(languageSpecificPrimitives.contains(type))
return type;
}
else
type = swaggerType;
return toModelName(type);
} |
@boazapir you're right. I'll try to fix that in the csharp_restsharp branch. |
@boazsapir in the spec is there a parameter or a property with type set to "object" ? |
@wing328 I have parameters that have a schema which points to an object. Example:
} |
@boazsapir based on my understanding, I've not seen the use of May I know how the Swagger spec is generated ? |
@wing328 - actually, that section in the spec refers to primitives:
|
My Swagger spec is generated from php annotations. * @SWG\Definition(definition="KeyInput", type="object",
* @SWG\Property(property="metadata", type="string", description="user-defined metadata, a printable string", maxLength=1024)
* )
* @SWG\Parameter(name="Input", in="body", @SWG\Schema(ref="#/definitions/UpdateEncryptionKeyInput")), |
@webron Thanks for the clarification. I would recommend updating swagger.json for petstore with I'll update the Petstore JSON locally to see if I can repeat the issue. |
@webron thanks! @boazsapir I added If I manually update the parameter from
I could repeat the issue. Do you mind double checking to see where else you can find |
You are right, I also have it in a response: "responses": {
"200": {
"description": "Swagger JSON Specification",
"schema": {
"title": "SwaggerSchema",
"type": "object"
}
}
} When I remove this part from my spec the problem does not occur anymore |
@wing328 I have some issues that seem to be specific to the csharp_restsharp branch. How do you want me to report on them? |
@boazsapir Thanks for reporting the issue. I've fixed the bug. In addition, I've updated the package name to conform to the C# package naming convention as follows:
Please kindly give it another try. |
@boazsapir if response is an object (model). I believe the response should be defined as something like this:
|
try { If there is an error code it will appear in the StatusCode field of the response but no exception will be thrown (I guess this is the behavior of restClient). StatusCode is not checked by the generated function, the response content (which is null) is deserialized and returned to the caller. The caller cannot know what was the error code. P.S. what is the status of the problem with the reserved words? Thank you |
@boazsapir I'll look into the error code issue. For reserved word, you mentioned the response is
which is not the correct way to define a model(object) response based on my knowledge. It should look something like this:
If you add a proper |
@boazsapir Updated Here is a sample exception message:
Once again, appreciate your help to test the change. |
@boazsapir may I know if you've a chance to do a test? please let me know if you still have issue not getting the proper exception. |
@wing328 I tried the new code and the problem seems to be fixed. I will do some more tests tomorrow and let you know if there are additional problems. Regarding the reserved keyword issue, using $ref solves the problem, however according to the spec I don't see why it is not legal to have an 'inline' schema definition without a $ref. Response with a string type:
Can you elaborate on this? |
@boazsapir my understanding is that if the type is "object", you will need to provide the definition of the object that you've defined in the "definitions" section of the spec. |
@wing328 - it's valid inline as well, doesn't have to be defined under |
@webron Thanks for the clarification. @boazsapir I'll try to address this issue and keep you posted. The fix should generate the method to just return a C# Object. |
To be clear, we have not added support in codegen for in-line models, even though they're valid in the spec. It's not hard, but we'll have to add a general mechanism for handling anonymous definitions as many languages don't support them. |
Note that in Java code generation I had no problem with my inline model definition |
Submitted #775 to address the issue. The endpoint with response type set to object without $ref will return an Object (HTTP body in the form of string) |
@wing328 sorry I was travelling and could not respond. I will try to check this week whether it solves my problem |
@boazsapir enjoy your travel and let me know later if you've any feedback on the fix |
inline object works fine now |
In the CSharp generated code, when the api call returns 201 an exception is thrown although this code does not indicate any error or problem
The text was updated successfully, but these errors were encountered: