Skip to content
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

enum type properties can't be generated into models in Java #99

Closed
comm604 opened this issue Oct 7, 2013 · 7 comments
Closed

enum type properties can't be generated into models in Java #99

comm604 opened this issue Oct 7, 2013 · 7 comments

Comments

@comm604
Copy link

comm604 commented Oct 7, 2013

If a property is an enum, the Java generator doesn't create an Enum java file for it.

For example,


"Employee":
       {
           "id": "Employee",
           "description": "An employee",
           "required":
           [
               "name",
               "id"
           ],
           "properties":
           {
               "name":
               {
                   "type": "string",
                   "description": "Name of the employee"
               },
               "id":
               {
                   "type": "string",
                   "description": "Id of the employee"
               },
               "department":
               {
                   "$ref": "Department",
                   "description": "The department that the employee belongs to",
                   "enum":
                   [
                       "SALES",
                       "FINANCE",
                       "ENGINEERING",
                       "MARKETING"
                   ]
               }
           }
       }

With this example model, in addition to Employee.java, shouldn't it also generate a Department.java like the following?


public enum Department {
    SALES, FINANCE, ENGINEERING, MARKETING
}

@fehguy
Copy link
Contributor

fehguy commented Nov 4, 2013

Hi, this is a new feature, marking it as such. Currently the codegen does not generate enum classes.

@RobBlairInq
Copy link
Contributor

I have privately made modifications that allow this, and generate an enum inside the model class definition.
it does not use $ref, treats it like a String, but at least allows the enum items to be exposed to java.
see 1.2 swagger spec https://github.com/wordnik/swagger-core/wiki/Datatypes#complex-types for current support.

@fehguy fehguy added this to the v2.1.0-M1 milestone Dec 24, 2014
@fehguy
Copy link
Contributor

fehguy commented Feb 16, 2015

This feature has been added to the java templates in 2.1.x. See the develop_2.0 branch

@fehguy fehguy closed this as completed Feb 16, 2015
@adrobotics
Copy link

I'm having trouble finding the version where this is supposed to be working. The develop_2.0 branch doesn't generate any enum classes for me.

  • Solved
    Java enum values must be of type string and also enclosed in "
    Ex: "status": {
    "enum": [
    "10",
    "20"
    ],
    "type": "string"
    }

@nihuyaka
Copy link

Why is this closed? As of 2.1.4 Enums are still generated inside the model which is wrong.

@fehguy
Copy link
Contributor

fehguy commented Dec 15, 2015

Why? Because this ticket isn't about having external enums, it's about having enums. Making them inline is not wrong it's a style preference. I DO want to support external classes, and we're in the process of adding that support. But that's why it's closed. There's another one around external enums.

@nihuyaka
Copy link

Ah, sorry thanks.

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

5 participants