Spring Boot Config JSON Schema Generator
Alex Mondshain <alex.mondshain@gmail.com> 2014-09-09
A Spring Boot starter that generates JSON Schema documentation from your application’s @ConfigurationProperties classes and Spring Boot configuration metadata. The generated schemas enable configuration validation and autocompletion in popular IDEs and CI/CD pipelines.
Introduction
A Spring Boot starter library uses Spring Context to process @ConfigurationProperties annotated classes and relevant properties from Spring Boot’s configuration metadata (spring-configuration-metadata.json) to generate JSON Schema. The generated schema can be used by compatible editors for configuration validation and assistance outside the Java project, as well as for configuration validation during CI/CD pipelines.
A good article on this subject: Spring Boot Config Documentation, Two Ways With IntelliJ IDEA
Features
Core Capabilities
-
Automatic JSON Schema generation from @ConfigurationProperties classes
-
Support for Jakarta Bean Validation (JSR-380) annotations
-
Full Spring Boot 3.x compatibility
-
Java 17+ runtime support
Prerequisites
-
Java 17 or higher
-
Spring Boot 3.x
-
Maven or Gradle build system
-
Configuration processor for property metadata generation:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
Usage
Maven (using in unit tests)
Add the following dependency to your pom.xml
:
<dependency>
<groupId>org.alexmond</groupId>
<artifactId>spring-boot-config-json-schema-starter</artifactId>
<version>1.0.3</version>
<scope>test</scope>
</dependency>
@SpringBootTest
@Slf4j
class SampleJsonSchemaGeneratorTests {
@Autowired
private JsonSchemaService jsonSchemaService;
@Test
void generateJsonSchema() {
var jsonConfigSchemaJson = jsonSchemaService.generateFullSchemaJson();
var jsonConfigSchemaYaml = jsonSchemaService.generateFullSchemaYaml();
log.info("Writing json schema");
Files.writeString(Paths.get("config-schema.json"), jsonConfigSchemaJson, StandardCharsets.UTF_8);
log.info("Writing yaml schema");
Files.writeString(Paths.get("config-schema.yaml"), jsonConfigSchemaYaml, StandardCharsets.UTF_8);
}
}
Using as REST API Endpoint
To expose the JSON schema via a REST endpoint (similar to Swagger API docs), first add the following dependency to your pom.xml
:
<dependency>
<groupId>org.alexmond</groupId>
<artifactId>spring-boot-config-json-schema-starter</artifactId>
<version>1.0.3</version>
</dependency>
@RestController
@Slf4j
public class GenerateJsonSchema {
@Autowired
private JsonSchemaService jsonSchemaService;
@GetMapping("/config-schema")
public String getConfigSchema() {
return jsonSchemaService.generateFullSchemaJson();
}
@GetMapping("/config-schema.yaml")
public String getConfigSchemaYaml() throws Exception {
return jsonSchemaService.generateFullSchemaYaml();
}
}
Using as Actuator Endpoint
To expose the JSON schema via an Actuator endpoint, first add the following dependency to your pom.xml
:
<dependency>
<groupId>org.alexmond</groupId>
<artifactId>spring-boot-config-json-schema-starter</artifactId>
<version>1.0.3</version>
</dependency>
In JSON format
@Component
@Endpoint(id = "config-schema")
@RequiredArgsConstructor
public class ConfigSchemaEndpoint {
private final JsonSchemaService jsonSchemaService;
@ReadOperation
public String schema() {
return jsonSchemaService.generateFullSchemaJson();
}
}
In YAML format
@Component
@Endpoint(id = "config-schema.yaml")
@RequiredArgsConstructor
public class ConfigSchemaYamlEndpoint {
private final JsonSchemaService jsonSchemaService;
@ReadOperation
public String schema() throws Exception {
return jsonSchemaService.generateFullSchemaYaml();
}
}
Using in editors
IDE Integration
IntelliJ IDEA and JetBrains IDEs
Add schema reference to the top of your YAML configuration
For testing purposes, you can find sample generic schema files here:
# Schema reference for JetBrains IDEs
$schema: "https://alexmond.github.io/spring-boot-config-json-schema-starter/current/_attachments/boot-generic-config.json"
# Application properties
spring:
datasource:
url: jdbc:h2:mem:testdb
username: sa
password: password
Examples:


Usage in Visual Studio Code
Add schema reference using YAML language server directive (requires YAML Language Support by Red Hat extension):
# yaml-language-server: $schema=https://alexmond.github.io/spring-boot-config-json-schema-starter/current/_attachments/boot-generic-config.yaml
spring:
datasource:
url: jdbc:h2:mem:testdb
username: sa
password: password
Examples:


Configuration Properties
Description of all available configuration properties for JSON Schema generation.
Name | Default Value | Description |
---|---|---|
json-config-schema.additional-properties |
logging |
Additional property paths to include in the schema generation. Default includes 'logging' namespace. |
json-config-schema.description |
Auto-generated schema from configuration metadata |
Description text for the generated schema document. |
json-config-schema.missing-type-log |
false |
When true, logs any property types that couldn’t be resolved during schema generation. |
json-config-schema.schema-id |
your-schema-id |
Unique identifier for the generated schema. |
json-config-schema.schema-spec |
JSON Schema specification URL to use. Defaults to 2020-12 draft. |
|
json-config-schema.title |
Spring Boot Configuration Properties |
Title for the schema document. |
json-config-schema.use-openapi |
true |
Enable/disable OpenAPI annotation processing for schema enhancement. |
json-config-schema.use-validation |
true |
Enable/disable validation annotation processing for constraint inclusion. |
json-config-schema.type-properties-map |
{} |
Map of property type overrides for schema generation. Allows customizing type mappings. |