laBuse
laBuse

Reputation: 21

Swagger OpenApi / Can't see my enum attrubue

i'm actually learn spring boot and i started use swagger for test my controller, My problem is this :

My contructor lokk like this :

 @Override
    public String toString() {
        return "Card{" +
                "name='" + name + '\'' +
                ", picture='" + picture + '\'' +
                ", powerLvl=" + powerLvl +
                ", description='" + description + '\'' +
                ", location='" + location + '\'' +
                ", ability=" + ability +
                ", row=" + rowName +
                ", type=" + type +
                '}';
    }

So i have 3 enum look like this :

public enum Ability {


    BERSERKER( "Berserker"),
    COMMANDER( "Commander"),
    DECOY( "Decoy"),
    MEDIC( "Medic"),
    MORALE_BOOST( "Morale boost"),
    MARDROEME("mardroeme"),
    MUSTER( "muster"),
    SCORCH( "scorch"),
    SPY( "spy"),
    TIGHT_BOND( "tightBond"),
    SUMMON_AVENGER( "summonAvenger");

And i don't understand how, in swagger interface let me choice an enum choice when i create a card.

My post for create a card in swagger look like this :

{
  "id": 0,
  "name": "eee",
  "picture": "eee",
  "powerLvl": 10,
  "description": "ee",
  "location": "ee"
}

why i don't have my enum and how can i do.

thank you for your time.

I search a lot and i try to modifie my json but not working.


Afer the your response i try to add this :

package com.example.gwent_projet.entity;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(name = "Ability card values", description = "Ability card values") public enum Ability {

BERSERKER( "Berserker"),
COMMANDER( "Commander"),
DECOY( "Decoy"),
MEDIC( "Medic"),
MORALE_BOOST( "Morale boost"),
MARDROEME("mardroeme"),
MUSTER( "muster"),
SCORCH( "scorch"),
SPY( "spy"),
TIGHT_BOND( "tightBond"),
SUMMON_AVENGER( "summonAvenger");


private final String abilityName;

private Ability(String abilityName) {
    this.abilityName = abilityName;
}

public String getShortName() {
    return abilityName;
}

}

but in my swagger interface i don't see a change for my card creation : Swagger result

I don't understand, i'm sorry.

Upvotes: 2

Views: 1656

Answers (1)

Mihail
Mihail

Reputation: 390

You need to annotate your enum with Schema annotation like this:

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(name = "Activity flag values", description = "Activity flag values")
public enum ActivityFlag {
    ACTIVE,
    INACTIVE,
    ALL
}

In UI it will be a dropdown:

Enum in swaggger

Upvotes: 2

Related Questions