0
votes

I am using swagger doc to generate API for my app. Doc is written in yml and in some place it is going to define some props which are enum (we use mysql). This is looks like:

properties:
      type:
        enum:
          - "first"
          - "second"
          - "example"
        type: "string"
      title:
        type: "string"
    ... // And so on and on

I am expecting to get something like this:

{
  "type": "string",
  "title": "string",
}

As you can see, type field is going to be a string as was defined in config file, but I am receiving this one instead:

{
  "type": "first",
  "title": "string",
}

Swagger sets first value as a data type and it is absolutely incorrect. So the question is how to get value "string" for "type" field.

1

1 Answers

0
votes

I have been writing my swagger documentation in JSON. Below is an example of how I have my "enums" set up. Maybe you can translate it to YML to get a better idea.

"parameters":[
           {
              "name":"userID",
              "in":"path",
              "description":"TO BE DETERMINED.",
              "required":true,
              "type":"string"
           },
           {
              "name":"embedded",
              "in":"query",
              "description":"TO BE DETERMINED",
              "required":false,
              "type":"array",
              "items":{
                 "enum":[
                    "address",
                    "state"
                 ]
              },
              "collectionFormat":"csv"
           }

If you look at items you see that I don't use a type and it works fine.