Я генерирую документацию OpenAPI 3.0 из аннотированного Java-кода.Но проблема в том, что когда я добавляю аннотацию @Schema для перечисления, все значения исчезают.Я использую Thorntail 2.3.0.Final с фракцией microprofile-openapi.
Я знаю, что могу просто изменить файл .yaml, но мне нужно, чтобы мой yaml генерировался непосредственно из кода Java.
Вот мой минимальный пример на github: https://github.com/pkristja/openApiEnumSchema
Исходный код для enum:
package com.example.openapiexample.model;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
@Schema(description = "<div class=\\\"renderedMarkdown\\\"><p>Rank of developer.</p>\\n\" +\n" +
" \"<p>Valid values are:</p>\\n\" +\n" +
" \"<ul>\\n\" +\n" +
" \"<li>'JUNIOR_DEVELOPER_1': Text for junior 1.\\n\" +\n" +
" \"<li>'JUNIOR_DEVELOPER_2': Text for junior 2.\\n\" +\n" +
" \"<li>'JUNIOR_DEVELOPER_3': Text for junior 3.\\n\" +\n" +
" \"<li>'SENIOR_DEVELOPER_1': Text for senior 1.\\n\" +\n" +
" \"<li>'SENIOR_DEVELOPER_2': Text for senior 1.\\n\" +\n" +
" \"<li>'SENIOR_DEVELOPER_3': Text for senior 1.\\n\" +\n" +
" \"</ul>\\n\" +\n" +
" \"<p>Random text...\\n\" +\n" +
" \"and has to be added to this API definition as well.</p></div>",
enumeration = {"junior_developer_1", "junior_developer_2", "junior_developer_3",
"senior_developer_1", "senior_developer_2", "senior_developer_3"})
public enum Rank {
JUNIOR_DEVELOPER_1("junior_developer_1"),
JUNIOR_DEVELOPER_2("junior_developer_2"),
JUNIOR_DEVELOPER_3("junior_developer_3"),
SENIOR_DEVELOPER_1("senior_developer_1"),
SENIOR_DEVELOPER_2("senior_developer_2"),
SENIOR_DEVELOPER_3("senior_developer_3");
private String value;
Rank(String value) {
this.value = value;
}
@Override
@JsonValue
public String toString() {
return String.valueOf(value);
}
@JsonCreator
public static Rank fromValue(String text) {
for (Rank b : Rank.values()) {
if (String.valueOf(b.value).equals(text)) {
return b;
}
}
return null;
}
}
И исходный код для объекта, включая enum:
package com.example.openapiexample.model;
import lombok.Data;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
@Data
@Schema(description = "Schema for Developer object...")
public class Developer {
@Schema(required = true, description = "First name of the developer")
private String firstName;
@Schema(required = true, description = "Last name of the developer")
private String lastName;
@Schema(required = true, implementation = Rank.class)
private Rank developerRank;
}
Snippedсгенерированной документации OpenAPI 3.0:
schemas:
Developer:
description: Schema for Developer object...
required:
- developerRank
- firstName
- lastName
properties:
developerRank:
description: |-
<div class=\"renderedMarkdown\"><p>Rank of developer.</p>\n" +
"<p>Valid values are:</p>\n" +
"<ul>\n" +
"<li>'JUNIOR_DEVELOPER_1': Text for junior 1.\n" +
"<li>'JUNIOR_DEVELOPER_2': Text for junior 2.\n" +
"<li>'JUNIOR_DEVELOPER_3': Text for junior 3.\n" +
"<li>'SENIOR_DEVELOPER_1': Text for senior 1.\n" +
"<li>'SENIOR_DEVELOPER_2': Text for senior 2.\n" +
"<li>'SENIOR_DEVELOPER_3': Text for senior 3.\n" +
"</ul>\n" +
"<p>Random text...\n" +
"and has to be added to this API definition as well.</p></div>
type: string
properties:
value:
type: string
firstName:
description: First name of the developer
type: string
lastName:
description: Last name of the developer
type: string
Но если я удалю аннотацию @Schema перед перечислением в классе Developer, я получу сгенерированные значения перечисления, но без описания и требуемого значения, например:
schemas:
Developer:
description: Schema for Developer object...
required:
- firstName
- lastName
properties:
developerRank:
enum:
- JUNIOR_DEVELOPER_1
- JUNIOR_DEVELOPER_2
- JUNIOR_DEVELOPER_3
- SENIOR_DEVELOPER_1
- SENIOR_DEVELOPER_2
- SENIOR_DEVELOPER_3
type: string
firstName:
description: First name of the developer
type: string
lastName:
description: Last name of the developer
type: string
Есть ли способ получить значения enum и описание, или я что-то не так делаю?