<?xml version="1.0" encoding="UTF-8"?>
<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.camunda.community.rest</groupId>
    <artifactId>camunda-platform-7-rest-client-spring-boot-parent</artifactId>
    <version>7.20.0</version>
    <relativePath>../../pom.xml</relativePath>
  </parent>

  <artifactId>camunda-platform-7-rest-client-spring-boot-openapi</artifactId>
  <name>camunda-platform-7-rest-client-spring-boot/openapi-client</name>
  <packaging>jar</packaging>

  <properties>
    <!-- Do meter coverage -->
    <jacoco.skip>false</jacoco.skip>
    <openapi-generator-version>6.6.0</openapi-generator-version>
    <camunda.openapi.package>org.camunda.community.rest.client</camunda.openapi.package>
  </properties>

  <dependencies>
    <!-- Feign -->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-openfeign</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- Jackson -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.datatype</groupId>
      <artifactId>jackson-datatype-jdk8</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.datatype</groupId>
      <artifactId>jackson-datatype-jsr310</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.module</groupId>
      <artifactId>jackson-module-kotlin</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>io.swagger.core.v3</groupId>
      <artifactId>swagger-annotations</artifactId>
    </dependency>
    <dependency>
      <groupId>jakarta.validation</groupId>
      <artifactId>jakarta.validation-api</artifactId>
    </dependency>

    <!-- Camunda Open API -->
    <dependency>
      <groupId>org.camunda.bpm</groupId>
      <artifactId>camunda-engine-rest-openapi</artifactId>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-configuration-processor</artifactId>
      <optional>true</optional>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack-dependencies</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <includeArtifactIds>camunda-engine-rest-openapi</includeArtifactIds>
              <outputDirectory>${project.build.directory}/camunda-openapi</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>${openapi-generator-version}</version>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>${project.build.directory}/camunda-openapi/openapi.json</inputSpec>
              <generatorName>spring</generatorName>
              <generateApiTests>false</generateApiTests>
              <generateModelTests>false</generateModelTests>
              <generateApiDocumentation>false</generateApiDocumentation>
              <generateModelDocumentation>false</generateModelDocumentation>
              <templateDirectory>openapi-templates</templateDirectory>
              <configOptions>
                <library>spring-cloud</library>
                <dateLibrary>legacy</dateLibrary>
                <invokerPackage>${camunda.openapi.package}</invokerPackage>
                <apiPackage>${camunda.openapi.package}.api</apiPackage>
                <modelPackage>${camunda.openapi.package}.model</modelPackage>
                <useBeanValidation>false</useBeanValidation>
                <useSpringBoot3>true</useSpringBoot3>
                <openApiNullable>false</openApiNullable>
                <useFeignClient>true</useFeignClient>
              </configOptions>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.google.code.maven-replacer-plugin</groupId>
        <artifactId>maven-replacer-plugin</artifactId>
        <executions>
          <execution>
            <id>changeDeploymentMultipartToArray</id>
            <phase>process-resources</phase>
            <goals>
              <goal>replace</goal>
            </goals>
            <configuration>
              <basedir>${project.basedir}</basedir>
              <includes>
                <include>target/generated-sources/openapi/**/DeploymentApi.java</include>
              </includes>
              <regex>false</regex>
              <replacements>
                <!-- RequestPart is needed to activate correct encoding, further array is needed to allow multiple files -->
                <replacement>
                  <token>@RequestPart(value = "data", required = false) MultipartFile data</token>
                  <value>@RequestPart(value = "data", required = false) MultipartFile[] data</value>
                </replacement>
                <replacement>
                  <token>@RequestParam(value = "tenant-id"</token>
                  <value>@RequestPart(value = "tenant-id"</value>
                </replacement>
                <replacement>
                  <token>@RequestParam(value = "deployment-source"</token>
                  <value>@RequestPart(value = "deployment-source"</value>
                </replacement>
                <replacement>
                  <token>@RequestParam(value = "deploy-changed-only"</token>
                  <value>@RequestPart(value = "deploy-changed-only"</value>
                </replacement>
                <replacement>
                  <token>@RequestParam(value = "enable-duplicate-filtering"</token>
                  <value>@RequestPart(value = "enable-duplicate-filtering"</value>
                </replacement>
                <replacement>
                  <token>@RequestParam(value = "deployment-name"</token>
                  <value>@RequestPart(value = "deployment-name"</value>
                </replacement>
                <replacement>
                  <token>@RequestParam(value = "deployment-activation-time"</token>
                  <value>@RequestPart(value = "deployment-activation-time"</value>
                </replacement>
              </replacements>
            </configuration>
          </execution>
          <execution>
            <id>changeEmptyRequestParamValue</id>
            <phase>process-resources</phase>
            <goals>
              <goal>replace</goal>
            </goals>
            <configuration>
              <basedir>${project.basedir}</basedir>
              <includes>
                <include>target/generated-sources/openapi/**/HistoricVariableInstanceApi.java</include>
              </includes>
              <regex>false</regex>
              <replacements>
                <!-- RequestParam in HistoricVariableInstanceApi is generated with value = "" for variableValue as this is specified with type object in openapi.json -->
                <replacement>
                  <token>@RequestParam(value = "",</token>
                  <value>@RequestParam(value = "variableValue",</value>
                </replacement>
              </replacements>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>license</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>license-maven-plugin</artifactId>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
