{"id":31556997,"url":"https://github.com/kliushnichenko/jsonschema-generator-apt","last_synced_at":"2026-04-30T12:34:07.001Z","repository":{"id":314890213,"uuid":"1057061680","full_name":"kliushnichenko/jsonschema-generator-apt","owner":"kliushnichenko","description":"A build-time Java library for generating JSON Schemas","archived":false,"fork":false,"pushed_at":"2026-02-15T19:03:13.000Z","size":95,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-30T12:33:58.846Z","etag":null,"topics":["apt","build-time","java","json","json-schema"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kliushnichenko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-15T08:19:14.000Z","updated_at":"2026-02-15T19:01:23.000Z","dependencies_parsed_at":"2025-09-15T13:22:33.056Z","dependency_job_id":"b9fcc671-0929-40af-9da3-cf10edb5ba26","html_url":"https://github.com/kliushnichenko/jsonschema-generator-apt","commit_stats":null,"previous_names":["kliushnichenko/jsonschema-generator-apt"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/kliushnichenko/jsonschema-generator-apt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kliushnichenko%2Fjsonschema-generator-apt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kliushnichenko%2Fjsonschema-generator-apt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kliushnichenko%2Fjsonschema-generator-apt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kliushnichenko%2Fjsonschema-generator-apt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kliushnichenko","download_url":"https://codeload.github.com/kliushnichenko/jsonschema-generator-apt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kliushnichenko%2Fjsonschema-generator-apt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32465009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"online","status_checked_at":"2026-04-30T02:00:05.929Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apt","build-time","java","json","json-schema"],"created_at":"2025-10-04T23:21:07.915Z","updated_at":"2026-04-30T12:34:06.996Z","avatar_url":"https://github.com/kliushnichenko.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON Schema Generator APT\n\nA build-time Java library for generating JSON Schema. Unlike many runtime solutions, this library analyzes code during\ncompilation to produce JSON schemas, so its primary purpose is APT(Annotation Processing Tools) processors.\n\n## Usage\n\nTo start using the library, include it as a dependency in your Maven project:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.kliushnichenko\u003c/groupId\u003e\n    \u003cartifactId\u003ejsonschema-generator-apt\u003c/artifactId\u003e\n    \u003cversion\u003e${version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nGenerate JsonSchema using `JsonSchemaGenerator` class:\n\nPrimary use-case for the time being is to generate schema for method arguments or type mirror:\n\n```java\nimport io.github.kliushnichenko.jsonschema.generator.JsonSchemaGenerator;\n\nclass Demo {\n\n    JsonSchemaGenerator schemaGenerator = new JsonSchemaGenerator();\n    \n    // from `javax.lang.model.element.ExecutableElement`\n    String schema = schemaGenerator.generate(method); // method is ExecutableElement instance\n    \n    // from `javax.lang.model.type.TypeMirror`\n    String schema = schemaGenerator.generate(type); // type is TypeMirror instance\n}\n```\n\nFor example, for the method declaration like:\n\n```java\nint sum(int a, int b) {}\n```\n\nThe generated schema will look like:\n\n```json\n{\n  \"type\": \"object\",\n  \"properties\": {\n    \"a\": {\n      \"type\": \"integer\"\n    },\n    \"b\": {\n      \"type\": \"integer\"\n    }\n  },\n  \"required\": [\n    \"a\",\n    \"b\"\n  ],\n  \"additionalProperties\": false\n}\n```\n\n## Annotation Mappers\n\nThe library provides a mechanism to customize how specific annotations are translated into JSON Schema properties.\nLet's say you have a custom annotation `@Arg` that you want to affect the resulting JSON Schema.\n\n```java\n@Retention(RetentionPolicy.SOURCE)\n@Target(ElementType.PARAMETER)\npublic @interface Arg {\n    String name() default \"\";\n    String description() default \"\";\n    boolean required() default true;\n    String defaultValue() default \"\";\n}\n```\n\nApply this annotation to method parameters:\n```java\nint sum(@Arg(name = \"firstNumber\", description = \"The first number to add\") int a,\n        @Arg(name = \"secondNumber\", description = \"The second number to add\") int b);\n```\n\nImplement corresponding mapper and pass it as an argument to `JsonSchemaGenerator`:\n```java\nimport io.github.kliushnichenko.jsonschema.generator.JsonSchemaGenerator;\nimport io.github.kliushnichenko.jsonschema.generator.JsonSchemaAnnotationMapper;\nimport io.github.kliushnichenko.jsonschema.generator.model.JsonSchemaProps;\n\nclass MyGenerator {\n\n    private static final JsonSchemaAnnotationMapper\u003cArg\u003e ARG_MAPPER = (Arg annotation) -\u003e {\n        JsonSchemaProps schemaProps = new JsonSchemaProps();\n        schemaProps.setName(annotation.name());\n        schemaProps.setDescription(annotation.description());\n        schemaProps.setRequired(annotation.required());\n        return schemaProps;\n    };\n\n    private static final Map\u003cClass\u003c? extends Annotation\u003e, JsonSchemaAnnotationMapper\u003c?\u003e\u003e MAPPERS = Map.of(\n            Arg.class, ARG_MAPPER\n    );\n\n    public static void main(String[] args) {\n        JsonSchemaGenerator schemaGenerator = new JsonSchemaGenerator(MAPPERS);\n        String schema = schemaGenerator.generate(method);\n    }\n}\n```\n\nSo, the generated schema will look like:\n\n```json\n{\n  \"type\": \"object\",\n  \"properties\": {\n    \"firstNumber\": {\n      \"type\": \"integer\",\n      \"description\": \"The first number to add\"\n    },\n    \"secondNumber\": {\n      \"type\": \"integer\",\n      \"description\": \"The second number to add\"\n    }\n  },\n  \"required\": [\n    \"firstNumber\",\n    \"secondNumber\"\n  ],\n  \"additionalProperties\": false\n}\n```\n\n## Ignore arguments by type\n\nYou can configure the `JsonSchemaGenerator` to ignore specific arguments by type during schema generation. \nFor example, if you want to ignore parameters of type `HttpServletRequest`, \nyou can do so by passing a set of types to ignore when creating the generator:\n\n```java\n\n...\n\nSet\u003cString\u003e typesToIgnore = Set.of(\"javax.servlet.http.HttpServletRequest\");\n\nJsonSchemaGenerator schemaGenerator = new JsonSchemaGenerator();\nString schema = schemaGenerator.generate(method, typesToIgnore);\n```\n\n## How to enrich schema with OpenAPI annotations?\n\n### How to mark field as not required?\n\nBy default, schema generator marks all class fields as required. To mark field as not required, you can use `@Schema` annotation from `io.swagger.v3.oas.annotations.media` package:\n\n```java\nimport io.swagger.v3.oas.annotations.media.Schema;\n\nclass User {\n    @Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED)\n    private String middleName;\n}\n```\n\n### Supported `@Schema` properties\n\n- `description` - adds description to the field or object type\n- `requiredMode` - marks field as required or not required\n- `nullable` - marks field as nullable in the schema\n- `types` - allows to override the type that was generated automatically\n- `additionalProperties` - allows to set `additionalProperties` for the object type\n\n### Enum support\n\n By default, java enum type will produce an `enum` field with values discovered from the enum constants.\n\n\n### Will Jackson annotations be processed?\n\nGenerator, will respect:  \n- `@JsonProperty(\"field-name\")` - to change property name in the schema\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkliushnichenko%2Fjsonschema-generator-apt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkliushnichenko%2Fjsonschema-generator-apt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkliushnichenko%2Fjsonschema-generator-apt/lists"}