Update dependencies, add character and scenario management features
- Upgrade Quarkus and OpenAPI generator versions in pom.xml. - Introduce CharacterService and ScenarioService for managing character and scenario templates. - Implement CharacterEntity and ScenarioEntity JPA entities with corresponding repositories. - Add RESTful APIs for listing and retrieving characters and scenarios. - Create JSON converter for persisting lists of strings in the database. - Update OpenAPI specification to include new endpoints for character and scenario management. - Add Liquibase migration scripts for character and scenario tables. - Configure application settings for Hibernate ORM and database generation.
This commit is contained in:
@@ -12,6 +12,9 @@ quarkus:
|
||||
url: jdbc:h2:mem:roleplay;DB_CLOSE_DELAY=-1
|
||||
username: sa
|
||||
password: ""
|
||||
hibernate-orm:
|
||||
database:
|
||||
generation: none
|
||||
liquibase:
|
||||
change-log: db/migration/changelog.xml
|
||||
migrate-at-start: true
|
||||
|
||||
@@ -4,5 +4,7 @@
|
||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
|
||||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd">
|
||||
|
||||
<include file="db/migration/v001__scenarios_and_characters.xml"/>
|
||||
</databaseChangeLog>
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<databaseChangeLog
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
|
||||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd">
|
||||
|
||||
<changeSet id="001-1-create-character-table" author="roleplay">
|
||||
<createTable tableName="rp_character">
|
||||
<column name="id" type="uuid">
|
||||
<constraints primaryKey="true" nullable="false"/>
|
||||
</column>
|
||||
<column name="name" type="varchar(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="role" type="varchar(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="backstory" type="clob"/>
|
||||
<column name="personality_traits" type="clob"/>
|
||||
<column name="speaking_style" type="varchar(1000)"/>
|
||||
<column name="goals" type="clob"/>
|
||||
</createTable>
|
||||
<comment>Stores reusable character definitions. personality_traits and goals stored as JSON text.</comment>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="001-2-create-scenario-table" author="roleplay">
|
||||
<createTable tableName="scenario">
|
||||
<column name="id" type="uuid">
|
||||
<constraints primaryKey="true" nullable="false"/>
|
||||
</column>
|
||||
<column name="name" type="varchar(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="setting" type="clob"/>
|
||||
<column name="initial_conflict" type="clob"/>
|
||||
</createTable>
|
||||
<comment>Stores scenario templates (setting and initial conflict).</comment>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="001-3-create-scenario-character-table" author="roleplay">
|
||||
<createTable tableName="scenario_character">
|
||||
<column name="id" type="uuid">
|
||||
<constraints primaryKey="true" nullable="false"/>
|
||||
</column>
|
||||
<column name="scenario_id" type="uuid">
|
||||
<constraints nullable="false" foreignKeyName="fk_scenario_character_scenario"
|
||||
references="scenario(id)"/>
|
||||
</column>
|
||||
<column name="character_id" type="uuid">
|
||||
<constraints nullable="false" foreignKeyName="fk_scenario_character_character"
|
||||
references="rp_character(id)"/>
|
||||
</column>
|
||||
<column name="is_user_character" type="boolean">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="position" type="int">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
<comment>Links scenarios to characters; position orders AI characters.</comment>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="001-4-seed-example-scenario" author="roleplay">
|
||||
<insert tableName="rp_character">
|
||||
<column name="id" value="11111111-1111-1111-1111-111111111101"/>
|
||||
<column name="name" value="The Detective"/>
|
||||
<column name="role" value="rookie detective"/>
|
||||
<column name="backstory" value="Recently joined the force, eager to prove themselves."/>
|
||||
<column name="personality_traits" value="["curious", "determined"]"/>
|
||||
<column name="goals" value="["Solve the case", "Earn respect"]"/>
|
||||
</insert>
|
||||
<insert tableName="rp_character">
|
||||
<column name="id" value="11111111-1111-1111-1111-111111111102"/>
|
||||
<column name="name" value="Captain Morgan"/>
|
||||
<column name="role" value="ship captain"/>
|
||||
<column name="backstory" value="Veteran of many voyages; hides a secret."/>
|
||||
<column name="personality_traits" value="["gruff", "wary"]"/>
|
||||
<column name="goals" value="["Protect the crew", "Keep the past buried"]"/>
|
||||
</insert>
|
||||
<insert tableName="scenario">
|
||||
<column name="id" value="22222222-2222-2222-2222-222222222201"/>
|
||||
<column name="name" value="Harbour mystery"/>
|
||||
<column name="setting" value="A fog-covered harbour at dawn, 1923"/>
|
||||
<column name="initial_conflict" value="Strange noises from the cargo hold"/>
|
||||
</insert>
|
||||
<insert tableName="scenario_character">
|
||||
<column name="id" value="33333333-3333-3333-3333-333333333301"/>
|
||||
<column name="scenario_id" value="22222222-2222-2222-2222-222222222201"/>
|
||||
<column name="character_id" value="11111111-1111-1111-1111-111111111101"/>
|
||||
<column name="is_user_character" valueBoolean="true"/>
|
||||
<column name="position" valueNumeric="0"/>
|
||||
</insert>
|
||||
<insert tableName="scenario_character">
|
||||
<column name="id" value="33333333-3333-3333-3333-333333333302"/>
|
||||
<column name="scenario_id" value="22222222-2222-2222-2222-222222222201"/>
|
||||
<column name="character_id" value="11111111-1111-1111-1111-111111111102"/>
|
||||
<column name="is_user_character" valueBoolean="false"/>
|
||||
<column name="position" valueNumeric="1"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -19,6 +19,10 @@ tags:
|
||||
description: Manage role-play sessions
|
||||
- name: turns
|
||||
description: Submit user actions within a session
|
||||
- name: scenarios
|
||||
description: List and retrieve saved scenario templates
|
||||
- name: characters
|
||||
description: List and retrieve saved character templates
|
||||
|
||||
paths:
|
||||
|
||||
@@ -43,6 +47,82 @@ paths:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
|
||||
/scenarios:
|
||||
get:
|
||||
operationId: listScenarios
|
||||
summary: List saved scenarios
|
||||
description: Returns all stored scenario templates for selection when starting a session.
|
||||
tags:
|
||||
- scenarios
|
||||
responses:
|
||||
"200":
|
||||
description: List of scenario summaries.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ScenarioListResponse'
|
||||
|
||||
/scenarios/{scenarioId}:
|
||||
get:
|
||||
operationId: getScenario
|
||||
summary: Get a scenario by id
|
||||
description: Returns the full scenario setup (setting, conflict, characters) for the given id.
|
||||
tags:
|
||||
- scenarios
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/ScenarioId'
|
||||
responses:
|
||||
"200":
|
||||
description: Scenario found and returned.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ScenarioSetup'
|
||||
"404":
|
||||
description: Scenario not found.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
|
||||
/characters:
|
||||
get:
|
||||
operationId: listCharacters
|
||||
summary: List saved characters
|
||||
description: Returns all stored character templates for selection when building a scenario.
|
||||
tags:
|
||||
- characters
|
||||
responses:
|
||||
"200":
|
||||
description: List of character definitions.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CharacterListResponse'
|
||||
|
||||
/characters/{characterId}:
|
||||
get:
|
||||
operationId: getCharacter
|
||||
summary: Get a character by id
|
||||
description: Returns the full character definition for the given id.
|
||||
tags:
|
||||
- characters
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/CharacterId'
|
||||
responses:
|
||||
"200":
|
||||
description: Character found and returned.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CharacterDefinition'
|
||||
"404":
|
||||
description: Character not found.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
|
||||
/sessions:
|
||||
post:
|
||||
operationId: createSession
|
||||
@@ -191,6 +271,22 @@ components:
|
||||
description: Unique identifier of the role-play session.
|
||||
schema:
|
||||
type: string
|
||||
ScenarioId:
|
||||
name: scenarioId
|
||||
in: path
|
||||
required: true
|
||||
description: Unique identifier of the scenario (UUID).
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
CharacterId:
|
||||
name: characterId
|
||||
in: path
|
||||
required: true
|
||||
description: Unique identifier of the character (UUID).
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
|
||||
schemas:
|
||||
|
||||
@@ -255,9 +351,56 @@ components:
|
||||
default: standard
|
||||
scenario:
|
||||
$ref: '#/components/schemas/ScenarioSetup'
|
||||
scenarioId:
|
||||
type: string
|
||||
format: uuid
|
||||
description: If set, the backend loads this scenario from the database and uses it instead of an inline scenario.
|
||||
required:
|
||||
- model
|
||||
|
||||
ScenarioSummary:
|
||||
type: object
|
||||
description: Summary of a stored scenario for list views.
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
format: uuid
|
||||
description: Unique identifier of the scenario.
|
||||
name:
|
||||
type: string
|
||||
description: Human-readable scenario name.
|
||||
setting:
|
||||
type: string
|
||||
description: Place, time, and atmosphere (optional in list).
|
||||
initialConflict:
|
||||
type: string
|
||||
description: The hook or starting conflict (optional in list).
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
|
||||
ScenarioListResponse:
|
||||
type: object
|
||||
description: Response containing all stored scenarios.
|
||||
properties:
|
||||
scenarios:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/ScenarioSummary'
|
||||
required:
|
||||
- scenarios
|
||||
|
||||
CharacterListResponse:
|
||||
type: object
|
||||
description: Response containing all stored characters.
|
||||
properties:
|
||||
characters:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/CharacterDefinition'
|
||||
required:
|
||||
- characters
|
||||
|
||||
ScenarioSetup:
|
||||
type: object
|
||||
description: |
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{{#required}}
|
||||
{{^isReadOnly}}
|
||||
@NotNull
|
||||
{{/isReadOnly}}
|
||||
{{/required}}
|
||||
{{#isContainer}}
|
||||
{{! Do not add @Valid on container; we use type-argument @Valid in the pojo (List<@Valid T>) to fix HV000271 }}
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
{{^isPrimitiveType}}
|
||||
@Valid
|
||||
{{/isPrimitiveType}}
|
||||
{{/isContainer}}
|
||||
{{>beanValidationCore}}
|
||||
@@ -0,0 +1,14 @@
|
||||
{{#required}}
|
||||
{{^isReadOnly}}
|
||||
@NotNull
|
||||
{{/isReadOnly}}
|
||||
{{/required}}
|
||||
{{#isContainer}}
|
||||
{{! Do not add @Valid on container; we use type-argument @Valid in the pojo (List<@Valid T>) to fix HV000271 }}
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
{{^isPrimitiveType}}
|
||||
@Valid
|
||||
{{/isPrimitiveType}}
|
||||
{{/isContainer}}
|
||||
{{>beanValidationCore}}
|
||||
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* {{description}}{{^description}}{{classname}}{{/description}}
|
||||
*/{{#description}}
|
||||
@ApiModel(description = "{{{.}}}"){{/description}}
|
||||
{{#jackson}}
|
||||
@JsonPropertyOrder({
|
||||
{{#vars}}
|
||||
{{classname}}.JSON_PROPERTY_{{nameInSnakeCase}}{{^-last}},{{/-last}}
|
||||
{{/vars}}
|
||||
})
|
||||
{{/jackson}}
|
||||
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtensions.x-implements}}{{#-first}}implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
{{^isContainer}}
|
||||
{{>enumClass}}
|
||||
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#mostInnerItems}}
|
||||
{{>enumClass}}
|
||||
|
||||
{{/mostInnerItems}}
|
||||
{{/isContainer}}
|
||||
{{/isEnum}}
|
||||
{{#jackson}}
|
||||
public static final String JSON_PROPERTY_{{nameInSnakeCase}} = "{{baseName}}";
|
||||
@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}})
|
||||
{{/jackson}}
|
||||
{{#gson}}
|
||||
public static final String SERIALIZED_NAME_{{nameInSnakeCase}} = "{{baseName}}";
|
||||
@SerializedName(SERIALIZED_NAME_{{nameInSnakeCase}})
|
||||
{{/gson}}
|
||||
{{#vendorExtensions.x-field-extra-annotation}}
|
||||
{{{.}}}
|
||||
{{/vendorExtensions.x-field-extra-annotation}}
|
||||
private {{>propertyType}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
|
||||
{{/vars}}
|
||||
{{#vars}}
|
||||
public {{classname}} {{name}}({{>propertyType}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
return this;
|
||||
}
|
||||
{{#isArray}}
|
||||
|
||||
public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
|
||||
if (this.{{name}} == null) {
|
||||
this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}};
|
||||
}
|
||||
this.{{name}}.add({{name}}Item);
|
||||
return this;
|
||||
}
|
||||
{{/isArray}}
|
||||
{{#isMap}}
|
||||
|
||||
public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
|
||||
if (this.{{name}} == null) {
|
||||
this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}};
|
||||
}
|
||||
this.{{name}}.put(key, {{name}}Item);
|
||||
return this;
|
||||
}
|
||||
{{/isMap}}
|
||||
|
||||
/**
|
||||
{{#description}}
|
||||
* {{.}}
|
||||
{{/description}}
|
||||
{{^description}}
|
||||
* Get {{name}}
|
||||
{{/description}}
|
||||
{{#minimum}}
|
||||
* minimum: {{.}}
|
||||
{{/minimum}}
|
||||
{{#maximum}}
|
||||
* maximum: {{.}}
|
||||
{{/maximum}}
|
||||
* @return {{name}}
|
||||
**/
|
||||
{{#vendorExtensions.x-extra-annotation}}
|
||||
{{{vendorExtensions.x-extra-annotation}}}
|
||||
{{/vendorExtensions.x-extra-annotation}}
|
||||
{{#jackson}}
|
||||
@JsonProperty(value = "{{baseName}}"{{#isReadOnly}}, access = JsonProperty.Access.READ_ONLY{{/isReadOnly}}{{#isWriteOnly}}, access = JsonProperty.Access.WRITE_ONLY{{/isWriteOnly}})
|
||||
{{/jackson}}
|
||||
@ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
{{#useBeanValidation}}{{#required}}{{^isReadOnly}}
|
||||
@NotNull
|
||||
{{/isReadOnly}}{{/required}}{{#isContainer}}{{! No @Valid on container; type has List<@Valid T> (HV000271) }}{{/isContainer}}{{^isContainer}}{{^isPrimitiveType}}
|
||||
@Valid
|
||||
{{/isPrimitiveType}}{{/isContainer}}{{>beanValidationCore}}{{/useBeanValidation}}
|
||||
public {{>propertyType}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
|
||||
{{#vendorExtensions.x-setter-extra-annotation}}{{{vendorExtensions.x-setter-extra-annotation}}}
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}public void {{setter}}({{>propertyType}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
|
||||
{{/vars}}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
{{classname}} {{classVarName}} = ({{classname}}) o;{{#hasVars}}
|
||||
return {{#parent}}super.equals(o) && {{/parent}}{{#vars}}Objects.equals(this.{{name}}, {{classVarName}}.{{name}}){{^-last}} &&
|
||||
{{/-last}}{{#-last}};{{/-last}}{{/vars}}{{/hasVars}}{{^hasVars}}{{#parent}}return super.equals(o);{{/parent}}{{^parent}}return true;{{/parent}}{{/hasVars}}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return {{^hasVars}}{{#parent}}super.hashCode(){{/parent}}{{^parent}}1{{/parent}}{{/hasVars}}{{#hasVars}}Objects.hash({{#vars}}{{#parent}}super.hashCode(), {{/parent}}{{name}}{{^-last}}, {{/-last}}{{/vars}}){{/hasVars}};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}}
|
||||
{{#vars}}sb.append(" {{name}}: ").append({{#isPassword}}"*"{{/isPassword}}{{^isPassword}}toIndentedString({{name}}){{/isPassword}}).append("\n");
|
||||
{{/vars}}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 ");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{{! Type with @Valid on type argument for containers (HV000271 fix). }}{{#isContainer}}{{#isArray}}{{#items.isPrimitiveType}}{{{datatypeWithEnum}}}{{/items.isPrimitiveType}}{{^items.isPrimitiveType}}{{#items.isEnum}}{{{datatypeWithEnum}}}{{/items.isEnum}}{{^items.isEnum}}List<@Valid {{{items.datatypeWithEnum}}}>{{/items.isEnum}}{{/items.isPrimitiveType}}{{/isArray}}{{^isArray}}{{#isMap}}{{#items.isPrimitiveType}}{{{datatypeWithEnum}}}{{/items.isPrimitiveType}}{{^items.isPrimitiveType}}{{#items.isEnum}}{{{datatypeWithEnum}}}{{/items.isEnum}}{{^items.isEnum}}Map<String, @Valid {{{items.datatypeWithEnum}}}>{{/items.isEnum}}{{/items.isPrimitiveType}}{{/isMap}}{{^isMap}}{{{datatypeWithEnum}}}{{/isMap}}{{/isMap}}{{/isArray}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}{{/isContainer}}
|
||||
@@ -0,0 +1 @@
|
||||
{{#required}}{{^isReadOnly}}@NotNull {{/isReadOnly}}{{/required}}{{#isContainer}}{{! Do not add @Valid on container; use type-argument @Valid (HV000271) }}{{/isContainer}}{{^isContainer}}{{^isPrimitiveType}}{{^isDate}}{{^isDateTime}}{{^isString}}{{^isFile}}{{^isEnumOrRef}}@Valid {{/isEnumOrRef}}{{/isFile}}{{/isString}}{{/isDateTime}}{{/isDate}}{{/isPrimitiveType}}{{/isContainer}}{{>beanValidationCore}}
|
||||
@@ -0,0 +1,289 @@
|
||||
{{#useSwaggerAnnotations}}
|
||||
import io.swagger.annotations.*;
|
||||
{{/useSwaggerAnnotations}}
|
||||
{{#useSwaggerV3Annotations}}
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
{{/useSwaggerV3Annotations}}
|
||||
import java.util.Objects;
|
||||
{{#jackson}}
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
{{#additionalProperties}}
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
{{/additionalProperties}}
|
||||
{{/jackson}}
|
||||
{{#openApiNullable}}
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
{{/openApiNullable}}
|
||||
{{#withXml}}
|
||||
import {{javaxPackage}}.xml.bind.annotation.XmlElement;
|
||||
import {{javaxPackage}}.xml.bind.annotation.XmlRootElement;
|
||||
import {{javaxPackage}}.xml.bind.annotation.XmlAccessType;
|
||||
import {{javaxPackage}}.xml.bind.annotation.XmlAccessorType;
|
||||
import {{javaxPackage}}.xml.bind.annotation.XmlType;
|
||||
import {{javaxPackage}}.xml.bind.annotation.XmlEnum;
|
||||
import {{javaxPackage}}.xml.bind.annotation.XmlEnumValue;
|
||||
{{/withXml}}
|
||||
|
||||
{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{#description}}/**
|
||||
* {{.}}
|
||||
**/{{/description}}
|
||||
{{#useSwaggerAnnotations}}{{#description}}@ApiModel(description = "{{{.}}}"){{/description}}{{/useSwaggerAnnotations}}{{#useSwaggerV3Annotations}}
|
||||
@Schema({{#title}}title="{{{.}}}", {{/title}}{{#description}}description="{{{.}}}"{{/description}}{{^description}}description=""{{/description}}){{/useSwaggerV3Annotations}}{{#useMicroProfileOpenAPIAnnotations}}
|
||||
@org.eclipse.microprofile.openapi.annotations.media.Schema({{#title}}title="{{{.}}}", {{/title}}{{#description}}description="{{{.}}}"{{/description}}{{^description}}description=""{{/description}}){{/useMicroProfileOpenAPIAnnotations}}
|
||||
{{#jackson}}
|
||||
@JsonTypeName("{{name}}")
|
||||
{{#additionalProperties}}
|
||||
@JsonFormat(shape=JsonFormat.Shape.OBJECT)
|
||||
{{/additionalProperties}}
|
||||
{{/jackson}}
|
||||
{{>generatedAnnotation}}{{>additionalModelTypeAnnotations}}{{>xmlPojoAnnotation}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtensions.x-implements}}{{#-first}}implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
{{^isContainer}}
|
||||
{{>enumClass}}{{! prevent indent}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#mostInnerItems}}
|
||||
{{>enumClass}}{{! prevent indent}}
|
||||
{{/mostInnerItems}}
|
||||
{{/isContainer}}
|
||||
{{/isEnum}}
|
||||
{{#vendorExtensions.x-field-extra-annotation}}
|
||||
{{{.}}}
|
||||
{{/vendorExtensions.x-field-extra-annotation}}
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{#isContainer}}
|
||||
private JsonNullable<{{{datatypeWithEnum}}}> {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>undefined();
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
private JsonNullable<{{{datatypeWithEnum}}}> {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>{{#defaultValue}}of({{{.}}}){{/defaultValue}}{{^defaultValue}}undefined(){{/defaultValue}};
|
||||
{{/isContainer}}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
private {{#useBeanValidation}}{{>beanValidatedType}}{{/useBeanValidation}}{{^useBeanValidation}}{{{datatypeWithEnum}}}{{/useBeanValidation}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{/vars}}
|
||||
|
||||
{{#generateBuilders}}
|
||||
{{^additionalProperties}}
|
||||
protected {{classname}}({{classname}}Builder b) {
|
||||
{{#parent}}
|
||||
super(b);
|
||||
{{/parent}}
|
||||
{{#vars}}
|
||||
this.{{name}} = b.{{name}};
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
{{/additionalProperties}}
|
||||
{{/generateBuilders}}
|
||||
public {{classname}}() {
|
||||
}
|
||||
|
||||
{{#jackson}}
|
||||
{{#generateJsonCreator}}
|
||||
{{#hasRequired}}
|
||||
@JsonCreator
|
||||
public {{classname}}(
|
||||
{{#requiredVars}}
|
||||
@JsonProperty(required = {{required}}, value = "{{baseName}}") {{>beanValidatedType}} {{name}}{{^-last}},{{/-last}}
|
||||
{{/requiredVars}}
|
||||
) {
|
||||
{{#parent}}
|
||||
super(
|
||||
{{#parentRequiredVars}}
|
||||
{{name}}{{^-last}},{{/-last}}
|
||||
{{/parentRequiredVars}}
|
||||
);
|
||||
{{/parent}}
|
||||
{{#vars}}
|
||||
{{#required}}
|
||||
this.{{name}} = {{name}};
|
||||
{{/required}}
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
{{/hasRequired}}
|
||||
{{/generateJsonCreator}}
|
||||
{{/jackson}}
|
||||
{{#vars}}
|
||||
/**
|
||||
{{#description}}
|
||||
* {{.}}
|
||||
{{/description}}
|
||||
{{#minimum}}
|
||||
* minimum: {{.}}
|
||||
{{/minimum}}
|
||||
{{#maximum}}
|
||||
* maximum: {{.}}
|
||||
{{/maximum}}
|
||||
**/
|
||||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{name}});
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{name}} = {{name}};
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
return this;
|
||||
}
|
||||
|
||||
{{#withXml}}
|
||||
@XmlElement(name="{{baseName}}"{{#required}}, required = {{required}}{{/required}})
|
||||
{{/withXml}}
|
||||
{{#vendorExtensions.x-extra-annotation}}{{{vendorExtensions.x-extra-annotation}}}{{/vendorExtensions.x-extra-annotation}}{{#useSwaggerAnnotations}}
|
||||
@ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}"){{/useSwaggerAnnotations}}{{#useSwaggerV3Annotations}}
|
||||
@Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}description = "{{{description}}}"){{/useSwaggerV3Annotations}}{{#useMicroProfileOpenAPIAnnotations}}
|
||||
@org.eclipse.microprofile.openapi.annotations.media.Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}description = "{{{description}}}"){{/useMicroProfileOpenAPIAnnotations}}
|
||||
{{#jackson}}@JsonProperty({{#required}}required = {{required}}, value = {{/required}}"{{baseName}}"){{/jackson}}
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
public JsonNullable<{{{datatypeWithEnum}}}> {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}}public {{>beanValidatedType}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
|
||||
{{#jackson}}
|
||||
@JsonProperty({{#required}}required = {{required}}, value = {{/required}}"{{baseName}}")
|
||||
{{/jackson}}
|
||||
{{#vendorExtensions.x-setter-extra-annotation}}{{{vendorExtensions.x-setter-extra-annotation}}}
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{name}});
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{name}} = {{name}};
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
}
|
||||
|
||||
{{#isArray}}
|
||||
public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
|
||||
if (this.{{name}} == null) {
|
||||
this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}};
|
||||
}
|
||||
|
||||
this.{{name}}.add({{name}}Item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public {{classname}} remove{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
|
||||
if ({{name}}Item != null && this.{{name}} != null) {
|
||||
this.{{name}}.remove({{name}}Item);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
{{/isArray}}
|
||||
{{#isMap}}
|
||||
public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
|
||||
if (this.{{name}} == null) {
|
||||
this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}};
|
||||
}
|
||||
|
||||
this.{{name}}.put(key, {{name}}Item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public {{classname}} remove{{nameInPascalCase}}Item(String key) {
|
||||
if (this.{{name}} != null) {
|
||||
this.{{name}}.remove(key);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
{{/isMap}}
|
||||
{{/vars}}
|
||||
{{>additional_properties}}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}{{#hasVars}}
|
||||
{{classname}} {{classVarName}} = ({{classname}}) o;
|
||||
return {{#vars}}{{#isByteArray}}Arrays{{/isByteArray}}{{^isByteArray}}Objects{{/isByteArray}}.equals(this.{{name}}, {{classVarName}}.{{name}}){{^-last}} &&
|
||||
{{/-last}}{{/vars}}{{#parent}} &&
|
||||
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
|
||||
return {{#parent}}super.equals(o){{/parent}}{{^parent}}true{{/parent}};{{/hasVars}}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash({{#vars}}{{^isByteArray}}{{name}}{{/isByteArray}}{{#isByteArray}}Arrays.hashCode({{name}}){{/isByteArray}}{{^-last}}, {{/-last}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}}
|
||||
{{#vars}}sb.append(" {{name}}: ").append({{#isPassword}}"*"{{/isPassword}}{{^isPassword}}toIndentedString({{name}}){{/isPassword}}).append("\n");
|
||||
{{/vars}}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 ");
|
||||
}
|
||||
|
||||
{{#generateBuilders}}{{^additionalProperties}}
|
||||
public static {{classname}}Builder builder() {
|
||||
return new {{classname}}BuilderImpl();
|
||||
}
|
||||
|
||||
private static final class {{classname}}BuilderImpl extends {{classname}}Builder<{{classname}}, {{classname}}BuilderImpl> {
|
||||
|
||||
@Override
|
||||
protected {{classname}}BuilderImpl self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public {{classname}} build() {
|
||||
return new {{classname}}(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class {{classname}}Builder > {{#parent}}extends {{{.}}}Builder {{/parent}} {
|
||||
{{#vars}}
|
||||
private {{#removeAnnotations}}{{{datatypeWithEnum}}}{{/removeAnnotations}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
{{/vars}}
|
||||
{{^parent}}
|
||||
protected abstract B self();
|
||||
|
||||
public abstract C build();
|
||||
{{/parent}}
|
||||
|
||||
{{#vars}}
|
||||
public B {{name}}({{#removeAnnotations}}{{{datatypeWithEnum}}}{{/removeAnnotations}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
return self();
|
||||
}
|
||||
{{/vars}}
|
||||
}{{/additionalProperties}}{{/generateBuilders}}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
{{#additionalEnumTypeAnnotations}}{{{.}}}
|
||||
{{/additionalEnumTypeAnnotations}}
|
||||
@@ -0,0 +1,2 @@
|
||||
{{#additionalModelTypeAnnotations}}{{{.}}}
|
||||
{{/additionalModelTypeAnnotations}}
|
||||
@@ -0,0 +1,32 @@
|
||||
{{#additionalProperties}}
|
||||
/**
|
||||
* Set the additional (undeclared) property with the specified name and value.
|
||||
* Creates the property if it does not already exist, otherwise replaces it.
|
||||
* @param key the name of the property
|
||||
* @param value the value of the property
|
||||
* @return self reference
|
||||
*/
|
||||
@JsonAnySetter
|
||||
public {{classname}} putAdditionalProperty(String key, {{{datatypeWithEnum}}} value) {
|
||||
this.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the additional (undeclared) properties.
|
||||
* @return the additional (undeclared) properties
|
||||
*/
|
||||
@JsonAnyGetter
|
||||
public Map getAdditionalProperties() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the additional (undeclared) property with the specified name.
|
||||
* @param key the name of the property
|
||||
* @return the additional (undeclared) property with the specified name
|
||||
*/
|
||||
public {{{datatypeWithEnum}}} getAdditionalProperty(String key) {
|
||||
return this.get(key);
|
||||
}
|
||||
{{/additionalProperties}}
|
||||
@@ -0,0 +1 @@
|
||||
{{#isArray}}{{baseType}}<{{#items}}{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}}{{>beanValidatedType}}{{/items}}>{{/isArray}}{{^isArray}}{{{datatypeWithEnum}}}{{/isArray}}
|
||||
@@ -0,0 +1 @@
|
||||
{{#required}}{{^isReadOnly}}@NotNull {{/isReadOnly}}{{/required}}{{#isContainer}}{{! No @Valid on container (HV000271) }}{{/isContainer}}{{^isContainer}}{{^isPrimitiveType}}{{^isDate}}{{^isDateTime}}{{^isString}}{{^isFile}}{{^isEnumOrRef}}@Valid {{/isEnumOrRef}}{{/isFile}}{{/isString}}{{/isDateTime}}{{/isDate}}{{/isPrimitiveType}}{{/isContainer}}{{>beanValidationCore}}
|
||||
@@ -0,0 +1,20 @@
|
||||
{{#pattern}} @Pattern(regexp="{{{.}}}"){{/pattern}}{{!
|
||||
minLength && maxLength set
|
||||
}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{!
|
||||
minLength set, maxLength not
|
||||
}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{!
|
||||
minLength not set, maxLength set
|
||||
}}{{^minLength}}{{#maxLength}} @Size(max={{.}}){{/maxLength}}{{/minLength}}{{!
|
||||
@Size: minItems && maxItems set
|
||||
}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{!
|
||||
@Size: minItems set, maxItems not
|
||||
}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{!
|
||||
@Size: minItems not set && maxItems set
|
||||
}}{{^minItems}}{{#maxItems}} @Size(max={{.}}){{/maxItems}}{{/minItems}}{{!
|
||||
check for integer or long / all others=decimal type with @Decimal*
|
||||
isInteger set
|
||||
}}{{#isInteger}}{{#minimum}} @Min({{.}}){{/minimum}}{{#maximum}} @Max({{.}}){{/maximum}}{{/isInteger}}{{!
|
||||
isLong set
|
||||
}}{{#isLong}}{{#minimum}} @Min({{.}}L){{/minimum}}{{#maximum}} @Max({{.}}L){{/maximum}}{{/isLong}}{{!
|
||||
Not Integer, not Long => we have a decimal value!
|
||||
}}{{^isInteger}}{{^isLong}}{{#minimum}} @DecimalMin({{#exclusiveMinimum}}value={{/exclusiveMinimum}}"{{minimum}}"{{#exclusiveMinimum}},inclusive=false{{/exclusiveMinimum}}){{/minimum}}{{#maximum}} @DecimalMax({{#exclusiveMaximum}}value={{/exclusiveMaximum}}"{{maximum}}"{{#exclusiveMaximum}},inclusive=false{{/exclusiveMaximum}}){{/maximum}}{{/isLong}}{{/isInteger}}
|
||||
@@ -0,0 +1,56 @@
|
||||
{{#withXml}}
|
||||
@XmlType(name="{{datatypeWithEnum}}")
|
||||
@XmlEnum({{dataType}}.class)
|
||||
{{/withXml}}
|
||||
{{>additionalEnumTypeAnnotations}}public enum {{datatypeWithEnum}} {
|
||||
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}{{#withXml}}@XmlEnumValue({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}){{/withXml}}{{name}}({{dataType}}.valueOf({{{value}}})){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
|
||||
|
||||
private {{dataType}} value;
|
||||
|
||||
{{datatypeWithEnum}} ({{dataType}} v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
public {{dataType}} value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
{{#jackson}}
|
||||
@JsonValue
|
||||
{{/jackson}}
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a String into {{dataType}}, as specified in the
|
||||
* See JAX RS 2.0 Specification, section 3.2, p. 12
|
||||
*/
|
||||
public static {{datatypeWithEnum}} fromString(String s) {
|
||||
for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
||||
// using Objects.toString() to be safe if value type non-object type
|
||||
// because types like 'int' etc. will be auto-boxed
|
||||
if (java.util.Objects.toString(b.value).equals(s)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected string value '" + s + "'");{{/isNullable}}
|
||||
}
|
||||
|
||||
{{#jackson}}
|
||||
@JsonCreator
|
||||
public static {{datatypeWithEnum}} fromValue({{dataType}} value) {
|
||||
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
||||
if (b.value.{{^isString}}equals{{/isString}}{{#isString}}{{#useEnumCaseInsensitive}}equalsIgnoreCase{{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}equals{{/useEnumCaseInsensitive}}{{/isString}}(value)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}return {{{name}}};{{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/enumUnknownDefaultCase}}{{/isNullable}}
|
||||
}
|
||||
{{/jackson}}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
{{#jackson}}
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
{{/jackson}}
|
||||
|
||||
/**
|
||||
* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
|
||||
*/
|
||||
{{>generatedAnnotation}}
|
||||
|
||||
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} {
|
||||
{{#gson}}
|
||||
{{#allowableValues}}{{#enumVars}}
|
||||
@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
|
||||
{{{name}}}({{{value}}}){{^-last}},
|
||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
{{/gson}}
|
||||
{{^gson}}
|
||||
{{#allowableValues}}{{#enumVars}}
|
||||
{{{name}}}({{{value}}}){{^-last}},
|
||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
{{/gson}}
|
||||
|
||||
private {{{dataType}}} value;
|
||||
|
||||
{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a String into {{dataType}}, as specified in the
|
||||
* See JAX RS 2.0 Specification, section 3.2, p. 12
|
||||
*/
|
||||
public static {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromString(String s) {
|
||||
for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
||||
// using Objects.toString() to be safe if value type non-object type
|
||||
// because types like 'int' etc. will be auto-boxed
|
||||
if (java.util.Objects.toString(b.value).equals(s)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected string value '" + s + "'");{{/isNullable}}
|
||||
}
|
||||
|
||||
@Override
|
||||
{{#jackson}}
|
||||
@JsonValue
|
||||
{{/jackson}}
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
{{#jackson}}
|
||||
@JsonCreator
|
||||
public static {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue({{{dataType}}} value) {
|
||||
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
||||
if (b.value.{{^isString}}equals{{/isString}}{{#isString}}{{#useEnumCaseInsensitive}}equalsIgnoreCase{{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}equals{{/useEnumCaseInsensitive}}{{/isString}}(value)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}return {{{name}}};{{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/enumUnknownDefaultCase}}{{/isNullable}}
|
||||
}
|
||||
{{/jackson}}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}, comments = "Generator version: {{generatorVersion}}")
|
||||
@@ -0,0 +1,21 @@
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
{{#serializableModel}}
|
||||
import java.io.Serializable;
|
||||
{{/serializableModel}}
|
||||
{{#useBeanValidation}}
|
||||
import {{javaxPackage}}.validation.constraints.*;
|
||||
import {{javaxPackage}}.validation.Valid;
|
||||
{{/useBeanValidation}}
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{#isEnum}}
|
||||
{{>enumOuterClass}}
|
||||
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}{{>pojo}}{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
@@ -0,0 +1,289 @@
|
||||
{{#useSwaggerAnnotations}}
|
||||
import io.swagger.annotations.*;
|
||||
{{/useSwaggerAnnotations}}
|
||||
{{#useSwaggerV3Annotations}}
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
{{/useSwaggerV3Annotations}}
|
||||
import java.util.Objects;
|
||||
{{#jackson}}
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
{{#additionalProperties}}
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
{{/additionalProperties}}
|
||||
{{/jackson}}
|
||||
{{#openApiNullable}}
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
{{/openApiNullable}}
|
||||
{{#withXml}}
|
||||
import {{javaxPackage}}.xml.bind.annotation.XmlElement;
|
||||
import {{javaxPackage}}.xml.bind.annotation.XmlRootElement;
|
||||
import {{javaxPackage}}.xml.bind.annotation.XmlAccessType;
|
||||
import {{javaxPackage}}.xml.bind.annotation.XmlAccessorType;
|
||||
import {{javaxPackage}}.xml.bind.annotation.XmlType;
|
||||
import {{javaxPackage}}.xml.bind.annotation.XmlEnum;
|
||||
import {{javaxPackage}}.xml.bind.annotation.XmlEnumValue;
|
||||
{{/withXml}}
|
||||
|
||||
{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{#description}}/**
|
||||
* {{.}}
|
||||
**/{{/description}}
|
||||
{{#useSwaggerAnnotations}}{{#description}}@ApiModel(description = "{{{.}}}"){{/description}}{{/useSwaggerAnnotations}}{{#useSwaggerV3Annotations}}
|
||||
@Schema({{#title}}title="{{{.}}}", {{/title}}{{#description}}description="{{{.}}}"{{/description}}{{^description}}description=""{{/description}}){{/useSwaggerV3Annotations}}{{#useMicroProfileOpenAPIAnnotations}}
|
||||
@org.eclipse.microprofile.openapi.annotations.media.Schema({{#title}}title="{{{.}}}", {{/title}}{{#description}}description="{{{.}}}"{{/description}}{{^description}}description=""{{/description}}){{/useMicroProfileOpenAPIAnnotations}}
|
||||
{{#jackson}}
|
||||
@JsonTypeName("{{name}}")
|
||||
{{#additionalProperties}}
|
||||
@JsonFormat(shape=JsonFormat.Shape.OBJECT)
|
||||
{{/additionalProperties}}
|
||||
{{/jackson}}
|
||||
{{>generatedAnnotation}}{{>additionalModelTypeAnnotations}}{{>xmlPojoAnnotation}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtensions.x-implements}}{{#-first}}implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
{{^isContainer}}
|
||||
{{>enumClass}}{{! prevent indent}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#mostInnerItems}}
|
||||
{{>enumClass}}{{! prevent indent}}
|
||||
{{/mostInnerItems}}
|
||||
{{/isContainer}}
|
||||
{{/isEnum}}
|
||||
{{#vendorExtensions.x-field-extra-annotation}}
|
||||
{{{.}}}
|
||||
{{/vendorExtensions.x-field-extra-annotation}}
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{#isContainer}}
|
||||
private JsonNullable<{{{datatypeWithEnum}}}> {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>undefined();
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
private JsonNullable<{{{datatypeWithEnum}}}> {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>{{#defaultValue}}of({{{.}}}){{/defaultValue}}{{^defaultValue}}undefined(){{/defaultValue}};
|
||||
{{/isContainer}}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
private {{#useBeanValidation}}{{>beanValidatedType}}{{/useBeanValidation}}{{^useBeanValidation}}{{{datatypeWithEnum}}}{{/useBeanValidation}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{/vars}}
|
||||
|
||||
{{#generateBuilders}}
|
||||
{{^additionalProperties}}
|
||||
protected {{classname}}({{classname}}Builder b) {
|
||||
{{#parent}}
|
||||
super(b);
|
||||
{{/parent}}
|
||||
{{#vars}}
|
||||
this.{{name}} = b.{{name}};
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
{{/additionalProperties}}
|
||||
{{/generateBuilders}}
|
||||
public {{classname}}() {
|
||||
}
|
||||
|
||||
{{#jackson}}
|
||||
{{#generateJsonCreator}}
|
||||
{{#hasRequired}}
|
||||
@JsonCreator
|
||||
public {{classname}}(
|
||||
{{#requiredVars}}
|
||||
@JsonProperty(required = {{required}}, value = "{{baseName}}") {{>beanValidatedType}} {{name}}{{^-last}},{{/-last}}
|
||||
{{/requiredVars}}
|
||||
) {
|
||||
{{#parent}}
|
||||
super(
|
||||
{{#parentRequiredVars}}
|
||||
{{name}}{{^-last}},{{/-last}}
|
||||
{{/parentRequiredVars}}
|
||||
);
|
||||
{{/parent}}
|
||||
{{#vars}}
|
||||
{{#required}}
|
||||
this.{{name}} = {{name}};
|
||||
{{/required}}
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
{{/hasRequired}}
|
||||
{{/generateJsonCreator}}
|
||||
{{/jackson}}
|
||||
{{#vars}}
|
||||
/**
|
||||
{{#description}}
|
||||
* {{.}}
|
||||
{{/description}}
|
||||
{{#minimum}}
|
||||
* minimum: {{.}}
|
||||
{{/minimum}}
|
||||
{{#maximum}}
|
||||
* maximum: {{.}}
|
||||
{{/maximum}}
|
||||
**/
|
||||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{name}});
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{name}} = {{name}};
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
return this;
|
||||
}
|
||||
|
||||
{{#withXml}}
|
||||
@XmlElement(name="{{baseName}}"{{#required}}, required = {{required}}{{/required}})
|
||||
{{/withXml}}
|
||||
{{#vendorExtensions.x-extra-annotation}}{{{vendorExtensions.x-extra-annotation}}}{{/vendorExtensions.x-extra-annotation}}{{#useSwaggerAnnotations}}
|
||||
@ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}"){{/useSwaggerAnnotations}}{{#useSwaggerV3Annotations}}
|
||||
@Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}description = "{{{description}}}"){{/useSwaggerV3Annotations}}{{#useMicroProfileOpenAPIAnnotations}}
|
||||
@org.eclipse.microprofile.openapi.annotations.media.Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}description = "{{{description}}}"){{/useMicroProfileOpenAPIAnnotations}}
|
||||
{{#jackson}}@JsonProperty({{#required}}required = {{required}}, value = {{/required}}"{{baseName}}"){{/jackson}}
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
public JsonNullable<{{{datatypeWithEnum}}}> {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}}public {{>beanValidatedType}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
|
||||
{{#jackson}}
|
||||
@JsonProperty({{#required}}required = {{required}}, value = {{/required}}"{{baseName}}")
|
||||
{{/jackson}}
|
||||
{{#vendorExtensions.x-setter-extra-annotation}}{{{vendorExtensions.x-setter-extra-annotation}}}
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
{{#vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{name}});
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
{{^vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
this.{{name}} = {{name}};
|
||||
{{/vendorExtensions.x-is-jackson-optional-nullable}}
|
||||
}
|
||||
|
||||
{{#isArray}}
|
||||
public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
|
||||
if (this.{{name}} == null) {
|
||||
this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}};
|
||||
}
|
||||
|
||||
this.{{name}}.add({{name}}Item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public {{classname}} remove{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
|
||||
if ({{name}}Item != null && this.{{name}} != null) {
|
||||
this.{{name}}.remove({{name}}Item);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
{{/isArray}}
|
||||
{{#isMap}}
|
||||
public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
|
||||
if (this.{{name}} == null) {
|
||||
this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}};
|
||||
}
|
||||
|
||||
this.{{name}}.put(key, {{name}}Item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public {{classname}} remove{{nameInPascalCase}}Item(String key) {
|
||||
if (this.{{name}} != null) {
|
||||
this.{{name}}.remove(key);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
{{/isMap}}
|
||||
{{/vars}}
|
||||
{{>additional_properties}}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}{{#hasVars}}
|
||||
{{classname}} {{classVarName}} = ({{classname}}) o;
|
||||
return {{#vars}}{{#isByteArray}}Arrays{{/isByteArray}}{{^isByteArray}}Objects{{/isByteArray}}.equals(this.{{name}}, {{classVarName}}.{{name}}){{^-last}} &&
|
||||
{{/-last}}{{/vars}}{{#parent}} &&
|
||||
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
|
||||
return {{#parent}}super.equals(o){{/parent}}{{^parent}}true{{/parent}};{{/hasVars}}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash({{#vars}}{{^isByteArray}}{{name}}{{/isByteArray}}{{#isByteArray}}Arrays.hashCode({{name}}){{/isByteArray}}{{^-last}}, {{/-last}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}}
|
||||
{{#vars}}sb.append(" {{name}}: ").append({{#isPassword}}"*"{{/isPassword}}{{^isPassword}}toIndentedString({{name}}){{/isPassword}}).append("\n");
|
||||
{{/vars}}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 ");
|
||||
}
|
||||
|
||||
{{#generateBuilders}}{{^additionalProperties}}
|
||||
public static {{classname}}Builder builder() {
|
||||
return new {{classname}}BuilderImpl();
|
||||
}
|
||||
|
||||
private static final class {{classname}}BuilderImpl extends {{classname}}Builder<{{classname}}, {{classname}}BuilderImpl> {
|
||||
|
||||
@Override
|
||||
protected {{classname}}BuilderImpl self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public {{classname}} build() {
|
||||
return new {{classname}}(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class {{classname}}Builder > {{#parent}}extends {{{.}}}Builder {{/parent}} {
|
||||
{{#vars}}
|
||||
private {{#removeAnnotations}}{{{datatypeWithEnum}}}{{/removeAnnotations}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
{{/vars}}
|
||||
{{^parent}}
|
||||
protected abstract B self();
|
||||
|
||||
public abstract C build();
|
||||
{{/parent}}
|
||||
|
||||
{{#vars}}
|
||||
public B {{name}}({{#removeAnnotations}}{{{datatypeWithEnum}}}{{/removeAnnotations}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
return self();
|
||||
}
|
||||
{{/vars}}
|
||||
}{{/additionalProperties}}{{/generateBuilders}}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{{#jackson}}
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminator.propertyBaseName}}}", visible = true)
|
||||
@JsonSubTypes({
|
||||
{{#discriminator.mappedModels}}
|
||||
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
|
||||
{{/discriminator.mappedModels}}
|
||||
})
|
||||
{{/jackson}}
|
||||
@@ -0,0 +1,8 @@
|
||||
{{#withXml}}
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
{{#hasVars}} @XmlType(name = "{{classname}}", propOrder =
|
||||
{ {{#vars}}"{{name}}"{{^-last}}, {{/-last}}{{/vars}}
|
||||
}){{/hasVars}}
|
||||
{{^hasVars}}@XmlType(name = "{{classname}}"){{/hasVars}}
|
||||
{{^parent}}@XmlRootElement(name="{{classname}}"){{/parent}}
|
||||
{{/withXml}}
|
||||
Reference in New Issue
Block a user