Skip to content

CSharp code generator - Class for array property is generated without any data member #729

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

Closed
boazsapir opened this issue May 7, 2015 · 12 comments

Comments

@boazsapir
Copy link

I have a property defined as an array:
* @swg\Definition(definition="Tokens", type="array", @swg\Items(type="string", maxLength=64, maxItems=32), description="a list of tokens")
* @swg\Property(property="tokens", ref="#/definitions/Tokens")

In the generated CSharp code, the corresponding class is created empty without any data members and it does not inherit from any other class (in the Java generated code, for instance, it extends ArrayList).

namespace io.swagger.Model {
[DataContract]
public class Tokens {

public override string ToString()  {
  var sb = new StringBuilder();
  sb.Append("class Tokens {\n");

  sb.Append("}\n");
  return sb.ToString();
}

}

}

@boazsapir boazsapir changed the title Class for array property is generated without any data member CSharp code generator - Class for array property is generated without any data member May 7, 2015
@wing328
Copy link
Contributor

wing328 commented May 7, 2015

Is it correct to say that the issue also occurs in the "csharp_restcsharp" PR #700 ?

@boazsapir
Copy link
Author

Yes, I am testing now on the #700 code (note the [DataContract] annotation in the generqted code)

@wing328
Copy link
Contributor

wing328 commented May 7, 2015

OK. I'll spend some time to look into the issue tomorrow.

@wing328
Copy link
Contributor

wing328 commented May 8, 2015

Are you trying to define a property, which is an array of model ? If that's the case, I think you need to set the type to "array". Using the Pet object in http://petstore.swagger.io/v2/swagger.json as an example, it has a property named tags, which is an array of Tag.

tags: {
  type: "array",
  items: {
    $ref: "#/definitions/Tag"
  }
},

If my guess is not correct, please kindly share with us the Swagger spec for repeating the issue.

@boazsapir
Copy link
Author

I do use the "array" type but still the generated class does not inherit any base class.

Here is my swagger spec:

   "Tokens": {
        "description": "a list of  tokens",
        "type": "array",
        "items": {
            "type": "string",
            "maxLength": 64,
            "maxItems": 32
        }
    },

@webron
Copy link
Contributor

webron commented May 9, 2015

@boazsapir - that's an array of strings, not an array of a model.

@boazsapir
Copy link
Author

@webron do I have to change it to an array of model or is it a bug that it does not work for array of strings?

@wing328
Copy link
Contributor

wing328 commented May 9, 2015

@boazsapir Array of strings should also work. For Pet object in the petstore example, the property "photoUrls" is an array of strings:

photoUrls: {
  type: "array",
  xml: {
  name: "photoUrl",
    wrapped: true
  },
  items: {
    type: "string"
  }
},

which works fine with the CSharp codegen.

Do you have the full Swagger spec that you can share with us to look into the issue (assuming the spec can share publicly)?

@boazsapir
Copy link
Author

Sorry I cannot publicly share the full spec. I will try to isolate the reason why the behavior in my case is different than in the petstore example

@wing328
Copy link
Contributor

wing328 commented May 13, 2015

@boazsapir understood. Did you encounter the same issue using Ruby, PHP client codegen?

@boazsapir
Copy link
Author

I did not try those clients, only Java and CSharp. Had no problem with Java

@fehguy
Copy link
Contributor

fehguy commented Oct 25, 2015

Please reopen if you're still having an issue with this.

@fehguy fehguy closed this as completed Oct 25, 2015
@fehguy fehguy modified the milestone: v2.1.4 Oct 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants