<?xml version="1.0" encoding="UTF-8"?>
<!--

    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.apache.iotdb</groupId>
        <artifactId>iotdb-protocol</artifactId>
        <version>2.0.7</version>
    </parent>
    <artifactId>openapi</artifactId>
    <name>IoTDB: Protocol: OpenAPI</name>
    <dependencies>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
        </dependency>
        <dependency>
            <groupId>jakarta.validation</groupId>
            <artifactId>jakarta.validation-api</artifactId>
        </dependency>
        <dependency>
            <groupId>jakarta.ws.rs</groupId>
            <artifactId>jakarta.ws.rs-api</artifactId>
        </dependency>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-jaxrs</artifactId>
        </dependency>
        <!-- Just needed for unused import code -->
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-multipart</artifactId>
        </dependency>
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <!-- TODO: For some reason the code-generation is run twice -->
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-java-rest-codes-common</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/openapi3/iotdb_rest_common.yaml</inputSpec>
                            <output>${project.build.directory}/generated-sources/java</output>
                            <apiPackage>org.apache.iotdb.db.protocol.rest</apiPackage>
                            <modelPackage>org.apache.iotdb.db.protocol.rest.model</modelPackage>
                            <invokerPackage>org.apache.iotdb.db.protocol.rest.invoker</invokerPackage>
                            <generatorName>jaxrs-jersey</generatorName>
                            <groupId>org.apache.iotdb</groupId>
                            <artifactId>iotdb-rest-service</artifactId>
                            <artifactVersion>${project.version}</artifactVersion>
                            <addCompileSourceRoot>true</addCompileSourceRoot>
                            <configOptions>
                                <licenseName>Apache License 2.0</licenseName>
                                <groupId>org.apache.iotdb</groupId>
                                <artifactId>iotdb-rest-service</artifactId>
                                <artifactVersion>${project.version}</artifactVersion>
                                <dateLibrary>java8</dateLibrary>
                                <useGzipFeature>true</useGzipFeature>
                            </configOptions>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate-java-rest-codes-v1</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/openapi3/iotdb_rest_v1.yaml</inputSpec>
                            <output>${project.build.directory}/generated-sources/java</output>
                            <apiPackage>org.apache.iotdb.db.protocol.rest.v1</apiPackage>
                            <modelPackage>org.apache.iotdb.db.protocol.rest.v1.model</modelPackage>
                            <invokerPackage>org.apache.iotdb.db.protocol.rest.v1.invoker</invokerPackage>
                            <generatorName>jaxrs-jersey</generatorName>
                            <groupId>org.apache.iotdb</groupId>
                            <artifactId>iotdb-rest-service</artifactId>
                            <artifactVersion>${project.version}</artifactVersion>
                            <addCompileSourceRoot>true</addCompileSourceRoot>
                            <configOptions>
                                <licenseName>Apache License 2.0</licenseName>
                                <groupId>org.apache.iotdb</groupId>
                                <artifactId>iotdb-rest-service</artifactId>
                                <artifactVersion>${project.version}</artifactVersion>
                                <dateLibrary>java8</dateLibrary>
                                <useGzipFeature>true</useGzipFeature>
                            </configOptions>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate-java-rest-codes-v2</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/openapi3/iotdb_rest_v2.yaml</inputSpec>
                            <output>${project.build.directory}/generated-sources/java</output>
                            <apiPackage>org.apache.iotdb.db.protocol.rest.v2</apiPackage>
                            <modelPackage>org.apache.iotdb.db.protocol.rest.v2.model</modelPackage>
                            <invokerPackage>org.apache.iotdb.db.protocol.rest.v2.invoker</invokerPackage>
                            <generatorName>jaxrs-jersey</generatorName>
                            <groupId>org.apache.iotdb</groupId>
                            <artifactId>iotdb-rest-service</artifactId>
                            <artifactVersion>${project.version}</artifactVersion>
                            <addCompileSourceRoot>true</addCompileSourceRoot>
                            <configOptions>
                                <licenseName>Apache License 2.0</licenseName>
                                <groupId>org.apache.iotdb</groupId>
                                <artifactId>iotdb-rest-service</artifactId>
                                <artifactVersion>${project.version}</artifactVersion>
                                <dateLibrary>java8</dateLibrary>
                                <useGzipFeature>true</useGzipFeature>
                            </configOptions>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate-java-rest-codes-table-v1</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/openapi3/iotdb_rest_table_v1.yaml</inputSpec>
                            <output>${project.build.directory}/generated-sources/java</output>
                            <apiPackage>org.apache.iotdb.db.protocol.rest.table.v1</apiPackage>
                            <modelPackage>org.apache.iotdb.db.protocol.rest.table.v1.model</modelPackage>
                            <invokerPackage>org.apache.iotdb.db.protocol.rest.table.v1.invoker</invokerPackage>
                            <generatorName>jaxrs-jersey</generatorName>
                            <groupId>org.apache.iotdb</groupId>
                            <artifactId>iotdb-rest-service</artifactId>
                            <artifactVersion>${project.version}</artifactVersion>
                            <addCompileSourceRoot>true</addCompileSourceRoot>
                            <configOptions>
                                <licenseName>Apache License 2.0</licenseName>
                                <groupId>org.apache.iotdb</groupId>
                                <artifactId>iotdb-rest-service</artifactId>
                                <artifactVersion>${project.version}</artifactVersion>
                                <dateLibrary>java8</dateLibrary>
                                <useGzipFeature>true</useGzipFeature>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <sources>
                                <source>${project.basedir}/target/generated-sources/java/src/gen/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!--
        TODO: For some reason I am unable to prevent the generation of the default implementations in the "impl"
        package. Also I was unable to prevent the maven-compiler-plugin from compiling them. So we're simply
        excluding them from the jar as a measure of last resort.
      -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/impl/**</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <configuration>
                    <usedDependencies combine.children="append">
                        <!-- We just need this dependency to prevent the compiler from freaking out on unused imports -->
                        <usedDependency>org.glassfish.jersey.media:jersey-media-multipart</usedDependency>
                    </usedDependencies>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
