• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

victools/jsonschema-generator: Java JSON Schema Generator – creating JSON Schem ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

victools/jsonschema-generator

开源软件地址:

https://github.com/victools/jsonschema-generator

开源编程语言:

Java 68.8%

开源软件介绍:

Java JSON Schema Generator

Build Status Maven Central

Creating JSON Schema (Draft 6, Draft 7, Draft 2019-09 or Draft 2020-12) from your Java classes utilising Jackson.


This project consists of:

  • the victools/jsonschema-generator (the only thing you need to get started)
  • a few modules bundling standard configurations for your convenience:
    • victools/jsonschema-module-jackson – deriving JSON Schema attributes from jackson annotations (e.g. "description", property name overrides, what properties to ignore) as well as looking up appropriate (annotated) subtypes
    • victools/jsonschema-module-jakarta-validation – deriving JSON Schema attributes from jakarta.validation.constraints annotations (e.g. which properties are nullable or not, their "minimum"/"maximum", "minItems"/"maxItems", "minLength"/"maxLength")
    • victools/jsonschema-module-javax-validation – deriving JSON Schema attributes from javax.validation annotations (e.g. which properties are nullable or not, their "minimum"/"maximum", "minItems"/"maxItems", "minLength"/"maxLength")
    • victools/jsonschema-module-swagger-1.5 – deriving JSON Schema attributes from swagger (1.5.x) annotations (e.g. "description", property name overrides, what properties to ignore, their "minimum"/"maximum", "const"/"enum")
    • victools/jsonschema-module-swagger-2 – deriving JSON Schema attributes from swagger (2.x) @Schema annotations
  • the victools/jsonschema-maven-plugin – allowing you to generate JSON Schemas as part of your Maven build

Another example for such a module is:


Documentation

JavaDoc is being used throughout the codebase, offering contextual information in your respective IDE or being available online through services like javadoc.io.

Additional documentation and configuration examples can be found here: https://victools.github.io/jsonschema-generator


Usage

Dependency (Maven)

<dependency>
    <groupId>com.github.victools</groupId>
    <artifactId>jsonschema-generator</artifactId>
    <version>4.25.0</version>
</dependency>

Since version 4.7, the release versions of the main generator library and the (standard) victools modules listed above are aligned. It is recommended to use identical versions for all of them to ensure compatibility.

It is discouraged to use a older/lower jsonschema-generator version than any of your jsonschema-module-* dependencies. If the module uses any feature only added to the jsonschema-generator in the newer version, runtime errors are to be expected.

Code

Complete/Minimal Example

import com.fasterxml.jackson.databind.JsonNode;
import com.github.victools.jsonschema.generator.OptionPreset;
import com.github.victools.jsonschema.generator.SchemaGenerator;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfig;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder;
import com.github.victools.jsonschema.generator.SchemaVersion;
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON);
SchemaGeneratorConfig config = configBuilder.build();
SchemaGenerator generator = new SchemaGenerator(config);
JsonNode jsonSchema = generator.generateSchema(YourClass.class);

System.out.println(jsonSchema.toPrettyString());



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap