or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

configuration.mdcore-generation.mdindex.mdmodel-system.mdutilities.mdvalidation.md

model-system.mddocs/

0

# Model System

1

2

The model system represents OpenAPI schemas, operations, parameters, and responses as Java objects for template processing and code generation. These classes provide the data structure that templates use to generate code.

3

4

## Core Model Classes

5

6

### CodegenModel

7

8

Represents an OpenAPI schema object (model/DTO class) in the generated code.

9

10

```java { .api }

11

class CodegenModel implements IJsonSchemaValidationProperties {

12

// Basic model information

13

public String name; // Schema name as in OpenAPI

14

public String schemaName; // Original schema name

15

public String classname; // Language-specific class name

16

public String title;

17

public String description;

18

public String classVarName;

19

public String modelJson;

20

public String dataType;

21

public String classFilename;

22

23

// Inheritance

24

public String parent; // Parent class name

25

public String parentSchema; // Parent schema reference

26

public List<String> interfaces; // Implemented interfaces

27

public List<String> allParents; // All parent classes in hierarchy

28

public CodegenModel parentModel; // Resolved parent model

29

public List<CodegenModel> interfaceModels; // Resolved interface models

30

public List<CodegenModel> children; // Child models

31

32

// Composition schemas (oneOf/anyOf/allOf)

33

public Set<String> anyOf;

34

public Set<String> oneOf;

35

public Set<String> allOf;

36

37

// Properties

38

public List<CodegenProperty> vars; // All properties

39

public List<CodegenProperty> requiredVars; // Required properties only

40

public List<CodegenProperty> optionalVars; // Optional properties only

41

public List<CodegenProperty> readOnlyVars; // Read-only properties

42

public List<CodegenProperty> readWriteVars; // Read-write properties

43

public Map<String, CodegenProperty> requiredVarsMap; // Required properties map

44

45

// Discriminator support

46

public CodegenDiscriminator discriminator;

47

48

// Behavioral flags

49

public boolean hasVars; // Has any properties

50

public boolean hasRequired; // Has required properties

51

public boolean hasOptional; // Has optional properties

52

public boolean hasEnums; // Contains enum properties

53

public boolean isEnum; // Is an enum model

54

public boolean isArrayModel; // Represents array type

55

public boolean isMapModel; // Represents map/dictionary type

56

}

57

```

58

59

### CodegenProperty

60

61

Represents a property within a schema (field/attribute of a model).

62

63

```java { .api }

64

class CodegenProperty implements Cloneable, IJsonSchemaValidationProperties {

65

// Basic property information

66

public String baseName; // Original property name from OpenAPI

67

public String complexType; // Full type including generics

68

public String getter; // Getter method name

69

public String setter; // Setter method name

70

public String description;

71

public String title;

72

public String unescapedDescription;

73

74

// Type information

75

public String dataType; // Language-specific data type

76

public String datatypeWithEnum; // Data type with enum suffix

77

public String dataFormat; // OpenAPI format (date, email, etc.)

78

public String name; // Language-specific property name

79

public String jsonSchema;

80

81

// Validation constraints

82

public String minimum;

83

public String maximum;

84

public boolean exclusiveMinimum;

85

public boolean exclusiveMaximum;

86

public Integer minLength;

87

public Integer maxLength;

88

public Integer minItems;

89

public Integer maxItems;

90

public String pattern;

91

public Number multipleOf;

92

93

// Behavioral flags

94

public boolean isReadOnly;

95

public boolean isWriteOnly;

96

public boolean isRequired;

97

public boolean isNullable;

98

public boolean isOptional;

99

public boolean hasMore; // For template iteration

100

public boolean isInherited; // Inherited from parent

101

public boolean isDiscriminator; // Is discriminator property

102

103

// Type flags

104

public boolean isString;

105

public boolean isNumeric;

106

public boolean isInteger;

107

public boolean isLong;

108

public boolean isNumber;

109

public boolean isFloat;

110

public boolean isDouble;

111

public boolean isDecimal;

112

public boolean isBoolean;

113

public boolean isDate;

114

public boolean isDateTime;

115

public boolean isEnum;

116

public boolean isContainer;

117

public boolean isListContainer;

118

public boolean isMapContainer;

119

public boolean isPrimitiveType;

120

public boolean isModel;

121

122

// Container properties

123

public CodegenProperty items; // For arrays

124

public CodegenProperty additionalProperties; // For maps

125

public List<CodegenProperty> vars; // For nested objects

126

127

// Default and example values

128

public String defaultValue;

129

public Object example;

130

public List<Object> examples;

131

132

// Enum values

133

public List<Object> allowableValues;

134

public Map<String, Object> allowableValuesMap;

135

}

136

```

137

138

### CodegenOperation

139

140

Represents an API operation (HTTP method + path combination).

141

142

```java { .api }

143

class CodegenOperation {

144

// Basic operation information

145

public String path; // URL path with parameters

146

public String operationId; // Unique operation identifier

147

public String httpMethod; // HTTP method (GET, POST, etc.)

148

public String nickname; // Generated method name

149

public String summary; // Operation summary

150

public String notes; // Detailed description

151

public String baseName; // Base name for method generation

152

153

// Parameters

154

public List<CodegenParameter> allParams; // All parameters

155

public List<CodegenParameter> bodyParams; // Request body parameters

156

public List<CodegenParameter> pathParams; // Path parameters

157

public List<CodegenParameter> queryParams; // Query parameters

158

public List<CodegenParameter> headerParams; // Header parameters

159

public List<CodegenParameter> formParams; // Form parameters

160

public List<CodegenParameter> cookieParams; // Cookie parameters

161

public List<CodegenParameter> requiredParams; // Required parameters

162

public List<CodegenParameter> optionalParams; // Optional parameters

163

164

// Response information

165

public List<CodegenResponse> responses; // All responses

166

public CodegenResponse defaultResponse; // Default response

167

public boolean returnTypeIsPrimitive;

168

public String returnType; // Return type name

169

public String returnContainer; // Container type (list, map)

170

171

// Behavioral flags

172

public boolean hasParams;

173

public boolean hasQueryParams;

174

public boolean hasPathParams;

175

public boolean hasBodyParam;

176

public boolean hasFormParams;

177

public boolean hasConsumes; // Has request content types

178

public boolean hasProduces; // Has response content types

179

public boolean isResponseOptional;

180

public boolean hasAuthMethods; // Requires authentication

181

182

// Content types

183

public List<Map<String, String>> consumes; // Request content types

184

public List<Map<String, String>> produces; // Response content types

185

186

// Authentication and security

187

public List<CodegenSecurity> authMethods;

188

public boolean hasMore; // For template iteration

189

190

// Vendor extensions

191

public Map<String, Object> vendorExtensions;

192

}

193

```

194

195

### CodegenParameter

196

197

Represents a parameter in an API operation.

198

199

```java { .api }

200

class CodegenParameter implements IJsonSchemaValidationProperties {

201

// Basic parameter information

202

public String baseName; // Original parameter name

203

public String paramName; // Language-specific parameter name

204

public String description;

205

public String unescapedDescription;

206

207

// Type and format information

208

public String dataType; // Language-specific data type

209

public String dataFormat; // OpenAPI format

210

public String collectionFormat; // Array parameter format

211

212

// Location flags

213

public boolean isPathParam;

214

public boolean isQueryParam;

215

public boolean isHeaderParam;

216

public boolean isBodyParam;

217

public boolean isFormParam;

218

public boolean isCookieParam;

219

220

// Type flags

221

public boolean isFile;

222

public boolean isContainer;

223

public boolean isString;

224

public boolean isNumeric;

225

public boolean isInteger;

226

public boolean isLong;

227

public boolean isPrimitiveType;

228

public boolean isModel;

229

public boolean isExplode; // OpenAPI 3.0 explode parameter

230

231

// Constraints and validation

232

public boolean isRequired;

233

public boolean isNullable;

234

public String defaultValue;

235

public Object example;

236

public String jsonSchema;

237

238

// Validation constraints (inherited from IJsonSchemaValidationProperties)

239

public String minimum;

240

public String maximum;

241

public boolean exclusiveMinimum;

242

public boolean exclusiveMaximum;

243

public Integer minLength;

244

public Integer maxLength;

245

public Integer minItems;

246

public Integer maxItems;

247

public String pattern;

248

249

// Container properties

250

public CodegenProperty items; // For array parameters

251

252

// Template iteration

253

public boolean hasMore;

254

255

// Vendor extensions

256

public Map<String, Object> vendorExtensions;

257

}

258

```

259

260

### CodegenResponse

261

262

Represents a response from an API operation.

263

264

```java { .api }

265

class CodegenResponse implements IJsonSchemaValidationProperties {

266

// Response identification

267

public String code; // HTTP status code (e.g., "200", "4XX")

268

public String message; // Response description

269

public String schema; // Response schema reference

270

271

// Type information

272

public String dataType; // Language-specific data type

273

public String baseType; // Base type without containers

274

public String containerType; // Container type (array/map)

275

public boolean returnTypeIsPrimitive;

276

277

// Type flags

278

public boolean isString;

279

public boolean isNumeric;

280

public boolean isInteger;

281

public boolean isLong;

282

public boolean isNumber;

283

public boolean isBoolean;

284

public boolean isBinary;

285

public boolean isByteArray;

286

public boolean isDate;

287

public boolean isDateTime;

288

public boolean isUuid;

289

public boolean isModel;

290

public boolean isContainer;

291

292

// Response details

293

public List<CodegenProperty> headers; // Response headers

294

public Object example;

295

public List<Object> examples;

296

public String jsonSchema;

297

298

// Behavioral flags

299

public boolean hasHeaders;

300

public boolean isDefault; // Default response (no status code)

301

public boolean isWildcard; // Wildcard status code (e.g., 2XX)

302

public boolean hasMore; // For template iteration

303

304

// Content types

305

public List<Map<String, String>> produces;

306

307

// Vendor extensions

308

public Map<String, Object> vendorExtensions;

309

}

310

```

311

312

## Template Context Objects

313

314

### ModelsMap

315

316

Container for models and their imports in template context.

317

318

```java { .api }

319

class ModelsMap extends HashMap<String, Object> {

320

public void setModels(List<ModelMap> modelMaps);

321

public List<ModelMap> getModels();

322

public void setImports(List<Map<String, String>> imports);

323

public List<Map<String, String>> getImports();

324

public List<Map<String, String>> getImportsOrEmpty();

325

}

326

```

327

328

### OperationsMap

329

330

Container for operations in template context.

331

332

```java { .api }

333

class OperationsMap extends HashMap<String, Object> {

334

public void setOperation(OperationMap objs);

335

public OperationMap getOperations();

336

public void setImports(List<Map<String, String>> imports);

337

public List<Map<String, String>> getImports();

338

}

339

```

340

341

### ModelMap

342

343

Container for individual model data in templates.

344

345

```java { .api }

346

class ModelMap extends HashMap<String, Object> {

347

// Typically contains:

348

// "model" -> CodegenModel

349

// "classname" -> String

350

// "description" -> String

351

// Additional template variables

352

}

353

```

354

355

### OperationMap

356

357

Container for individual operation data in templates.

358

359

```java { .api }

360

class OperationMap extends HashMap<String, Object> {

361

// Typically contains:

362

// "operation" -> List<CodegenOperation>

363

// "classname" -> String

364

// "package" -> String

365

// Additional template variables

366

}

367

```

368

369

## Usage Examples

370

371

### Processing Models

372

373

```java

374

public class CustomGenerator extends DefaultCodegen {

375

376

@Override

377

public CodegenModel fromModel(String name, Schema schema) {

378

CodegenModel model = super.fromModel(name, schema);

379

380

// Customize model properties

381

model.classname = "Custom" + model.classname;

382

383

// Process model properties

384

for (CodegenProperty property : model.vars) {

385

if (property.isString && property.maxLength != null) {

386

property.vendorExtensions.put("x-max-length", property.maxLength);

387

}

388

}

389

390

return model;

391

}

392

393

@Override

394

public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {

395

Map<String, ModelsMap> result = super.postProcessAllModels(objs);

396

397

// Add custom processing for all models

398

for (ModelsMap models : result.values()) {

399

for (ModelMap modelMap : models.getModels()) {

400

CodegenModel model = (CodegenModel) modelMap.get("model");

401

402

// Add validation annotations for required properties

403

for (CodegenProperty prop : model.requiredVars) {

404

prop.vendorExtensions.put("x-validation-required", true);

405

}

406

}

407

}

408

409

return result;

410

}

411

}

412

```

413

414

### Processing Operations

415

416

```java

417

@Override

418

public CodegenOperation fromOperation(String resourcePath, String httpMethod,

419

Operation operation, List<Server> servers) {

420

CodegenOperation op = super.fromOperation(resourcePath, httpMethod, operation, servers);

421

422

// Customize operation

423

op.nickname = "custom" + StringUtils.camelize(op.nickname);

424

425

// Process parameters

426

for (CodegenParameter param : op.allParams) {

427

if (param.isQueryParam && param.isRequired) {

428

param.vendorExtensions.put("x-required-query", true);

429

}

430

}

431

432

// Process responses

433

for (CodegenResponse response : op.responses) {

434

if ("200".equals(response.code)) {

435

response.vendorExtensions.put("x-success-response", true);

436

}

437

}

438

439

return op;

440

}

441

```

442

443

### Working with Template Context

444

445

```java

446

@Override

447

public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {

448

OperationsMap result = super.postProcessOperationsWithModels(objs, allModels);

449

450

// Access operations

451

OperationMap operations = result.getOperations();

452

List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");

453

454

// Add custom template variables

455

operations.put("hasAsyncOperations",

456

ops.stream().anyMatch(op -> op.vendorExtensions.containsKey("x-async")));

457

458

// Group operations by tag

459

Map<String, List<CodegenOperation>> operationsByTag = ops.stream()

460

.collect(Collectors.groupingBy(op ->

461

op.tags != null && !op.tags.isEmpty() ? op.tags.get(0).getName() : "default"));

462

463

operations.put("operationsByTag", operationsByTag);

464

465

return result;

466

}

467

```