A Spring Boot starter library that automatically generates JSON Schema documentation for your application’s configuration properties. It simplifies the process of documenting and validating configuration by generating JSON Schema from your Spring Boot configuration classes.
For detailed documentation, please visit our full documentation.
A good article on this subject: Spring Boot Config Documentation, Two Ways With IntelliJ IDEA
Add the following dependency to your pom.xml when using the generator in tests:
<dependency>
<groupId>org.alexmond</groupId>
<artifactId>spring-boot-config-json-schema-starter</artifactId>
<version>1.0.8</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);
}
}To expose the JSON schema via a REST endpoint (similar to Swagger API docs), add the following dependency to your
pom.xml:
<dependency>
<groupId>org.alexmond</groupId>
<artifactId>spring-boot-config-json-schema-starter</artifactId>
<version>1.0.8</version>
</dependency>Then create a REST controller:
@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() {
return jsonSchemaService.generateFullSchemaYaml();
}
}To expose the JSON schema via an Actuator endpoint, add the following dependency to your
pom.xml:
<dependency>
<groupId>org.alexmond</groupId>
<artifactId>spring-boot-config-json-schema-starter</artifactId>
<version>1.0.8</version>
</dependency>Then create Actuator endpoint:
@Component
@Endpoint(id = "config-schema")
@RequiredArgsConstructor
public class ConfigSchemaEndpoint {
private final JsonSchemaService jsonSchemaService;
@ReadOperation
public String schema() {
return jsonSchemaService.generateFullSchemaJson();
}
}@Component
@Endpoint(id = "config-schema.yaml")
@RequiredArgsConstructor
public class ConfigSchemaYamlEndpoint {
private final JsonSchemaService jsonSchemaService;
@ReadOperation
public String schema() {
return jsonSchemaService.generateFullSchemaYaml();
}
}Configure in application.yaml:
management:
endpoints:
web:
exposure:
include: config-schemaContributions welcome! See CONTRIBUTING for guidelines. Open issues for bugs or feature requests ( e.g., IDE enhancements, validation support).
Licensed under Apache 2.0 License.
⭐ Star this repo if you find it useful! Share feedback via [issues](https://github.com/alexmond/spring-boot-config-json-schema/issues).