【问题标题】:Generate JSON Schema as several files using Jsonix使用 Jsonix 将 JSON Schema 生成为多个文件
【发布时间】:2019-09-03 16:15:19
【问题描述】:

我有几个 XSD 文件,由请求和主题分隔,但是作为输出得到的 JSON Schema 是一个包含数千行的大文件。我想知道是否有使用 Jsonix 将生成的 JSON Schema 输出为多个文件的设置。导航会更容易。

下面是我的 pom.xml 的 Jsonix 部分:

    <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.13.3</version>
        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>

                    <extension>true</extension>
                    <args>
                        <arg>-Xannotate</arg>
                        <arg>-Xjsonix</arg>
                        <arg>-Xjsonix-generateJsonSchema</arg>  
                    </args>
                    <plugins>
                        <plugin>
                            <groupId>org.hisrc.jsonix</groupId>
                            <artifactId>jsonix-schema-compiler</artifactId>
                            <version>2.3.10</version>
                        </plugin>

                        <plugin>
                            <groupId>org.jvnet.jaxb2_commons</groupId>
                            <artifactId>jaxb2-basics-annotate</artifactId>
                            <version>1.0.2</version>
                        </plugin>
                        <plugin>
                            <groupId>org.jvnet.jaxb2_commons</groupId>
                            <artifactId>jaxb2-annotate-plugin-test-annox-annotations</artifactId>
                            <version>1.0.0</version>
                        </plugin>
                        <plugin>
                            <groupId>io.swagger</groupId>
                            <artifactId>swagger-annotations</artifactId>
                            <version>1.5.10</version>
                        </plugin>
                    </plugins>


                    <schemaDirectory>src/main/resources</schemaDirectory>
                    <schemaIncludes>
                        <include>**/*.xsd</include>
                    </schemaIncludes>

                    <bindingDirectory>src/main/resources</bindingDirectory>
                    <bindingIncludes>
                        <include>**/*.xjb</include>
                    </bindingIncludes>

                    <generatePackage>com.my.awesome.package</generatePackage>
                    <generateDirectory>${project.build.directory}/generated-sources/jsonSchema</generateDirectory>

                    <verbose>true</verbose>

                </configuration>
            </execution>
        </executions>
    </plugin>

【问题讨论】:

    标签: maven-plugin jsonix


    【解决方案1】:

    Jsonix 的作者在这里。

    我想知道是否有使用 Jsonix 将生成的 JSON Schema 输出为多个文件的设置。

    是的,请阅读modules and mappings

    简而言之,映射或多或少对应于 Java 中的一个包。 模块是一个或多个映射的集合,也是一个生成单元。

    您可以configure编译器生成包含特定映射的模块。

    如果我正确理解您的情况,您的架构很大,并且您想将映射或 JSON 架构划分为多个文件。

    这就是我的处理方式。

    我不得不说在这种情况下我还没有真正尝试过。通常人们会做相反的事情——将多个映射组合在一个模块中。但我认为没有理由不这样做。

    示例配置可能类似于:

    <jsonix:module
      name="MyRequests">
      <jsonix:mapping package="com.my.awesome.package" name="MyRequests">
        <jsonix:includes>
          <jsonix:type name="MyRequestType"/>
          ...
        </jsonix:includes>
      <jsonix:mapping>
    </jsonix:module>
    <jsonix:module
      name="MyResponses">
      <jsonix:mapping package="com.my.awesome.package" name="MyResponses">
        <jsonix:includes>
          <jsonix:type name="MyResponseType"/>
          ...
        </jsonix:includes>
      <jsonix:mapping>
    </jsonix:module>
    

    我不能 100% 确定这会奏效,但这是一个很好的起点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      • 2013-10-12
      • 2015-03-07
      • 1970-01-01
      • 2018-09-23
      • 1970-01-01
      相关资源
      最近更新 更多