У меня возникли некоторые сомнения относительно модели, созданной с использованием плагина 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
Программисты JAVA общаются здесь
-
Anonymous
1722285982
Anonymous
У меня возникли некоторые сомнения относительно модели, созданной с использованием плагина 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", //
Подробнее здесь: [url]https://stackoverflow.com/questions/78002627/prevent-openapi-generator-plugin-from-creating-builder-methods[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия