У меня возникли некоторые сомнения относительно модели, созданной с использованием плагина maven openapi-generator. Модель создана на основе следующей схемы yaml:
Контекст: openJDK 17.0.9 + maven 3.8.6
src/main/resources/schema.yaml:
openapi: 3.0.3
info:
title: Test
version: 0.0.0
paths:
/none:
get:
responses:
"200":
description: API not generated yet
components:
schemas:
operation:
type: object
properties:
settings:
$ref: "./settings.yaml#/Settings"
При компиляции проекта целевой каталог содержит следующий класс Java (target/generated-sources/openapi/src/main/java/com/test/model/)
package com.test.model;
import java.net.URI;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.openapitools.jackson.nullable.JsonNullable;
import java.time.OffsetDateTime;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.*;
import jakarta.annotation.Generated;
/**
* PGP input operations file structure
*/
@Schema(name = "operation")
@JsonTypeName("operation")
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
public class OperationDTO {
private SettingsDTO settings;
public OperationDTO() {
super();
}
/**
* Constructor with only required parameters
*/
public OperationDTO(SettingsDTO settings) {
this.settings = settings;
}
public OperationDTO settings(SettingsDTO settings) {
this.settings = settings;
return this;
}
/**
* Get settings
* @return settings
*/
@NotNull @Valid
@Schema(name = "settings", requiredMode = Schema.RequiredMode.REQUIRED)
@JsonProperty("settings")
public SettingsDTO getSettings() {
return settings;
}
public void setSettings(SettingsDTO settings) {
this.settings = settings;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
OperationDTO operation = (OperationDTO) o;
return Objects.equals(this.settings, operation.settings);
}
@Override
public int hashCode() {
return Objects.hash(settings);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class OperationDTO {\n");
sb.append(" settings: ").append(toIndentedString(settings)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
Я ожидал, что будут сгенерированы только конструкторы/геттеры/сеттеры, но в автоматически создаваемом классе модели есть еще и этот метод:
public OperationDTO settings(SettingsDTO settings) {
this.settings = settings;
return this;
}
Я не понимаю, почему эти методы, похожие на «строитель», автоматически генерируются в классе, и я не могу найти ни одного configOption в плагине Spring openapi-generator, чтобы избежать этого, ни документации объясняя, почему они создаются
Проблема в том, что схема, представленная в интерфейсе swagger-ui, выглядит следующим образом:
{
"operation":{
"tings": "string", //
Подробнее здесь: https://stackoverflow.com/questions/780 ... er-methods
Запретить плагину openapi-generator создавать методы построения ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Generator OpenAPI 7.9.0 генерирует методы с _0 в качестве суффикса. Как обойти эту проблему?
Anonymous » » в форуме JAVA - 0 Ответы
- 3 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Generator OpenAPI 7.9.0 генерирует методы с _0 в качестве суффикса. Как обойти эту проблему?
Anonymous » » в форуме JAVA - 0 Ответы
- 4 Просмотры
-
Последнее сообщение Anonymous
-
Мобильная версия