This guide helps you diagnose and resolve common issues with the OpenAPI Model Generator plugin.
# Verify plugin is applied correctly
./gradlew generateHelp
# Check available tasks
./gradlew tasks --group="openapi generation"
# Enable debug logging
./gradlew generateAllModels --info --stacktrace
# Test configuration without generating code
./gradlew generateAllModels --dry-run
# Check for configuration cache issues
./gradlew generateAllModels --configuration-cache
Symptoms:
Plugin with id 'com.guidedbyte.openapi-modelgen' not foundSolution:
plugins {
// ✅ REQUIRED: Apply OpenAPI Generator plugin first
id 'org.openapi.generator' version '7.14.0'
// ✅ Then apply this plugin
id 'com.guidedbyte.openapi-modelgen' version '1.1.1'
}
Common Mistakes:
❌ Wrong order - this plugin must come after OpenAPI Generator
plugins {
id 'com.guidedbyte.openapi-modelgen' version '1.1.1'
id 'org.openapi.generator' version '7.14.0' // Too late!
}
❌ Missing OpenAPI Generator plugin entirely
plugins {
id 'com.guidedbyte.openapi-modelgen' version '2.1.0' // Will fail
}
Symptoms:
Problem: Using assignment syntax instead of method calls
❌ Incorrect - Assignment syntax
openapiModelgen {
defaults {
outputDir = "build/generated" // Compilation error
validateSpec = true // Compilation error
}
}
✅ Correct - Method call syntax
openapiModelgen {
defaults {
outputDir "build/generated" // Method call
validateSpec true // Method call
}
}
Symptoms:
Common Validation Issues:
❌ Problem: Missing required inputSpec or modelPackage
specs {
api {
// Missing inputSpec and modelPackage
}
}
✅ Solution: Provide required properties
specs {
api {
inputSpec "src/main/resources/openapi/api.yaml"
modelPackage "com.example.model"
}
}
❌ Problem: Invalid Java package name
specs {
api {
inputSpec "api.yaml"
modelPackage "invalid-package-name!" // Hyphens not allowed
}
}
✅ Solution: Use valid Java package name
specs {
api {
inputSpec "api.yaml"
modelPackage "com.example.api.model" // Valid package name
}
}
❌ Problem: OpenAPI spec file doesn't exist
specs {
api {
inputSpec "nonexistent.yaml" // File not found
modelPackage "com.example.model"
}
}
✅ Solution: Verify file exists and path is correct
specs {
api {
inputSpec "src/main/resources/openapi/api.yaml" // Correct path
modelPackage "com.example.model"
}
}
Symptoms:
Diagnostic Steps:
# Validate your OpenAPI spec
./gradlew generateApi --validate-spec=true --info
# Check if output directory is created
ls -la build/generated/sources/openapi/src/main/java/
# View detailed generation information
cat build/logs/openapi-modelgen-debug.log | grep -i "generating"
Common Causes:
❌ Problem: Empty or missing components section
openapi: 3.0.3
info:
title: API
version: 1.0.0
paths: {}
# Missing components.schemas section
✅ Solution: Add schemas to components section
openapi: 3.0.3
info:
title: API
version: 1.0.0
paths: {}
components:
schemas:
User:
type: object
properties:
name:
type: string
❌ Problem: APIs generated instead of models
globalProperties([
models: "false", // Disables model generation
apis: "" // Enables API generation
])
✅ Solution: Generate models only (default)
globalProperties([
models: "", // Enables model generation
apis: "false" // Disables API generation (default)
])
Symptoms:
Common Causes:
✅ Add required dependencies
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'io.swagger.core.v3:swagger-annotations:2.2.19'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
✅ Verify Lombok annotations are correctly configured
openapiModelgen {
defaults {
configOptions([
additionalModelTypeAnnotations: "@lombok.Data;@lombok.experimental.Accessors(fluent = true);@lombok.experimental.SuperBuilder;@lombok.NoArgsConstructor(force = true);@lombok.AllArgsConstructor"
])
}
}
✅ Ensure Spring Boot 3.x configuration (default)
openapiModelgen {
defaults {
configOptions([
useSpringBoot3: "true", // Spring Boot 3.x
useJakartaEe: "true" // Jakarta EE (not Java EE)
])
}
}
Symptoms:
Solution:
openapiModelgen {
defaults {
configOptions([
useSpringBoot3: "true", // Enable Spring Boot 3.x
useJakartaEe: "true", // Use Jakarta EE packages
dateLibrary: "java8" // Use Java 8+ date/time
])
}
}
Symptoms:
Diagnostic Steps:
# Look for explicit templates that might override YAML customizations
find src/main/resources -name "*.mustache" -type f
✅ Correct structure (generator-specific directories)
src/main/resources/template-customizations/
└── spring/ # Generator name directory
├── pojo.mustache.yaml # YAML customization
└── model.mustache.yaml
❌ Incorrect structure (missing generator directory)
src/main/resources/template-customizations/
├── pojo.mustache.yaml # Wrong location
└── model.mustache.yaml
# View template resolution details (always captured)
cat build/logs/openapi-modelgen-debug.log
# Filter for template customization entries
grep -i "customization" build/logs/openapi-modelgen-debug.log
Common Causes:
❌ Problem: Both explicit template and YAML customization exist
src/main/resources/openapi-templates/spring/pojo.mustache # Explicit template
src/main/resources/template-customizations/spring/pojo.mustache.yaml # YAML (ignored!)
✅ Solution: Remove explicit template or YAML customization
src/main/resources/template-customizations/spring/pojo.mustache.yaml # YAML used
❌ Problem: Templates in wrong directory for your generator
# Your configuration uses 'spring' generator
openapiModelgen {
defaults {
generatorName "spring" # Uses 'spring' directory
}
}
# But templates are in 'java' directory
src/main/resources/template-customizations/java/pojo.mustache.yaml
✅ Solution: Move to correct generator directory
src/main/resources/template-customizations/spring/pojo.mustache.yaml
Symptoms:
Common YAML Issues:
✅ Correct indentation insertions:
❌ Unquoted Mustache patterns
conditions:
templateContains: # YAML parsing error
✅ Properly quoted patterns
conditions:
templateContains: "" # Correct
❌ Unescaped special characters
content: |
String value = "Hello: World"; # Colon in string causes issues
✅ Properly escaped or quoted
content: |
String value = "Hello\\: World"; # Escaped
# OR
content: 'String value = "Hello: World";' # Single quoted
Symptoms:
Diagnostic Steps:
# Check working directory to see actual templates (replace {specName} with your spec name)
ls -la build/template-work/spring-{specName}/
cat build/template-work/spring-{specName}/pojo.mustache
# Search for pattern in base template
grep -n "" build/template-work/spring-{specName}/pojo.mustache
Solutions:
✅ Use patterns that exist in base template insertions:
✅ Correct case insertions:
Symptoms:
Diagnostic Steps:
# Use build scan to identify bottlenecks
./gradlew generateAllModels --scan
# Time specific tasks
time ./gradlew generateAllModels
# Enable configuration cache
./gradlew generateAllModels --configuration-cache
# Run twice to test cache hit
./gradlew generateAllModels --configuration-cache # Should be faster second time
Performance Optimizations:
openapiModelgen {
defaults {
parallel true # Enable parallel multi-spec processing (default)
}
}
# Add to gradle.properties
org.gradle.configuration-cache=true
# Or use command line
./gradlew generateAllModels --configuration-cache
❌ Avoid broad patterns insertions:
Symptoms:
Solution:
# Increase Gradle daemon memory
export GRADLE_OPTS="-Xmx2g -XX:MaxMetaspaceSize=512m"
# Or add to gradle.properties
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m
Symptoms:
The plugin is designed to be configuration cache compatible. If you encounter issues:
plugins {
id 'com.guidedbyte.openapi-modelgen' version '1.1.1' // Latest version
}
❌ Custom closures may break configuration cache
openapiModelgen {
specs {
api {
inputSpec "api.yaml"
modelPackage "com.example.model"
// Avoid custom closures or non-serializable objects
}
}
}
./gradlew generateAllModels --configuration-cache --stacktrace > cache-issue.log
Symptoms:
Solutions:
Supported: OpenAPI Generator 7.10.0+
Tested with: 7.11.0, 7.14.0, 7.16.0+
plugins {
id 'org.openapi.generator' version '7.14.0' // Recommended version
id 'com.guidedbyte.openapi-modelgen' version '1.1.1'
}
dependencies {
implementation 'org.openapitools:openapi-generator:7.14.0'
}
Symptoms:
Requirements:
Solution:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17) // Or 21
}
}
The plugin automatically captures detailed debug logging to help troubleshoot template resolution, customization processing, and configuration issues.
No configuration needed - debug information is always captured:
# View complete debug log (always available)
cat build/logs/openapi-modelgen-debug.log
# Filter by specific spec name
grep "[spec:api]" build/logs/openapi-modelgen-debug.log
# Search for template-related entries
grep -i "template" build/logs/openapi-modelgen-debug.log
# View customization processing
grep -i "customization" build/logs/openapi-modelgen-debug.log
Use standard Gradle flags to control console verbosity:
# Detailed console output
./gradlew generateAllModels --info
# Full debug console output
./gradlew generateAllModels --debug
# Minimal console output
./gradlew generateAllModels --quiet
Template Resolution Debug:
=== Template Resolution Debug for 'spring' ===
Configured template sources: [user-templates, user-customizations, openapi-generator]
Available template sources: [user-customizations, openapi-generator]
✅ user-customizations: C:\project\src\main\templateCustomizations
✅ openapi-generator: OpenAPI Generator default templates (fallback)
=== End Template Resolution Debug ===
Template Processing Debug:
=== CUSTOMIZATION ENGINE ENTRY ===
Template length: 2547
Config name: pojo.mustache
Config has replacements: 2
Template starts with: ''
# View rich debug log with all details
cat build/logs/openapi-modelgen-debug.log
# Template-specific debugging
grep -i "template" build/logs/openapi-modelgen-debug.log
# Configuration validation details
./gradlew generateAllModels --dry-run --info
# Watch template customization processing
grep -i "customization" build/logs/openapi-modelgen-debug.log
# Filter by specific spec
grep "[spec:myApi]" build/logs/openapi-modelgen-debug.log
When reporting issues, include:
./gradlew buildEnvironment | grep openapi
./gradlew dependencyInsight --dependency org.openapitools
./gradlew generateHelp > config-help.txt
find build/template-work -name "*.mustache" -exec echo "=== {} ===" \; -exec cat {} \;
# Generate with verbose output
./gradlew generateAllModels --info --stacktrace
# Clean and regenerate everything
./gradlew clean generateAllModels
# Test configuration cache compatibility
./gradlew generateAllModels --configuration-cache
# Get plugin help and configuration options
./gradlew generateHelp
# Profile build performance
./gradlew generateAllModels --scan --profile
# Validate configuration without generating
./gradlew generateAllModels --dry-run
When reporting issues, please include: