Skip to content

A Spring Boot starter that auto-generates JSON Schema for application.yaml or application.properties from @ConfigurationProperties. Simplifies configuration documentation and validation, with support for IDE autocompletion (e.g., IntelliJ, VS Code) and CI/CD pipelines.

License

alexmond/spring-boot-config-json-schema

Repository files navigation

Spring Boot Config JSON Schema Generator

Maven Central License Build Status codecov

Spring Boot Config JSON Schema Generator

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.

Quick Start

Maven Dependencies

For Testing

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);
    }

}

For Production (REST or Actuator)

REST API Endpoint

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();
    }

}

Actuator Endpoint

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-schema

Changelog

Contributing

Contributions welcome! See CONTRIBUTING for guidelines. Open issues for bugs or feature requests ( e.g., IDE enhancements, validation support).

License

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).

About

A Spring Boot starter that auto-generates JSON Schema for application.yaml or application.properties from @ConfigurationProperties. Simplifies configuration documentation and validation, with support for IDE autocompletion (e.g., IntelliJ, VS Code) and CI/CD pipelines.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •