swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.05k stars 6.03k forks source link

How to generate definition of enum witrh java ? #2474

Closed mmaryo closed 8 years ago

mmaryo commented 8 years ago

Hi

I use Spring boot, swagger-maven-plugin and springfox-swagger2 with last versions

I just want to have enums in my definitions

public class OrderDto { private String id; private OrderTypeEnum type;

Currently :

"OrderDto" : {
  "type" : "object",
  "properties" : {
    "id" : {
      "type" : "string"
    },
    "type" : {
      "type" : "string",
      "enum" : [ "A", "B" ]
    },

But I want someting like this :

"OrderDto" : {
  "type" : "object",
  "properties" : {
    "id" : {
      "type" : "string"
    },
    "type" : {
      "type" : "string",
      "items" : {
        "$ref" : "#/definitions/OrderTypeEnum"
      }
    },

Have you an idea ?

fehguy commented 8 years ago

Yea, that's not really valid. Try using http://editor.swagger.io which will give you some interactive feedback on the validity of your spec. What you listed first is correct.

mmaryo commented 8 years ago

I use swagger.json to generate javascript API Client and Models classes

If I have 2 classes use OrderTypeEnum, it will generate ClassAOrderTypeEnum ClassBOrderTypeEnum

It's not good

fehguy commented 8 years ago

Please read the README. If you don't like the generation, you can choose how to handle it. You can even disable enums and use strings, it's in the options.

mmaryo commented 8 years ago

ok thanks for your replay