-
Notifications
You must be signed in to change notification settings - Fork 6k
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
enums are not generated in Java/Android Codegen #315
Comments
faced same issue today. in definitions section i have:
result of generation is empty A class. if i wrap this in definition named B and set A as property - class B with one field (A as enum) generated correctly but IMO looks a little bit ugly. |
The enum class is generated correctly right now. public class Pet {
private Long id = null;
private Category category = null;
private String name = null;
private List<String> photoUrls = new ArrayList<String>() ;
private List<Tag> tags = new ArrayList<Tag>() ;
public enum StatusEnum {
available, pending, sold,
};
private StatusEnum status = null; That is, the enum class ( PetApi api = new PetApi();
Pet pet = new Pet();
pet.setId(new Long(9527));
pet.setName("Kitty");
pet.setStatus(Pet.StatusEnum.pending);
api.addPet(pet);
Pet pet = api.getPetById(new Long(9527));
System.out.println(pet);
System.out.println(pet.getStatus());
System.out.println(pet.getStatus().getClass());
/* OUTPUT
class Pet {
id: 9527
category: null
name: Kitty
photoUrls: []
tags: []
status: pending
}
pending
class io.swagger.client.model.Pet$StatusEnum
*/
List<Pet> pets = api.findPetsByStatus(Arrays.asList("pending"));
System.out.println(pets);
/* OUTPUT
[class Pet {
id: 9527
category: null
name: Kitty
photoUrls: []
tags: []
status: pending
}
]
*/ @sunrisejjj regarding "result of generation is empty A class", are you expecting to generate separate enum class? If you are, I would say that the current nesting enum class would be better, to distinguish different enum classes with the same property name, for example there's also a public enum StatusEnum {
placed, approved, delivered,
}; |
@xhh currently i have two different options:
that's the reason why i want to generate 'stand-alone' enum classes. |
@sunrisejjj I agree with you that in the case you described it would be better to generate standalone enum class. However, the generator is not perfect/smart enough for now to detect the sharing of same enum classes, or to distinguish cases of whether to generate inline or standalone enum classes. And for now the inline approach would be the more "practical" one, before we making the generator perfect enough for enum (if possible/necessary). Regarding changing enum values, I think that would need changing those enum values for all models (definitions) in the spec file, right? After that rerunning the codegen will just generate the new code. |
@xhh agree, yep, i understand that after change in contract new values will be generated, but it will be better if i need to change my enum just in one place instead of many (i think that it is valid case for large web-services) by the way, current approach is acceptable! it's just about improvements. :) |
Should be resolved. Please reopen if needed. |
This property was not codgen-ed:
as
private OrderEnum order = null;
But the Class - OrderEnum was not generated.
The text was updated successfully, but these errors were encountered: