Skip to content
Snippets Groups Projects
Commit 5f69911f authored by Martin Vogel's avatar Martin Vogel
Browse files

Remove experimental open-api module, will be continued in develop branch

parent a35d68c1
No related branches found
No related tags found
1 merge request!28Entferne OpenAPI-Modul
This commit is part of merge request !28. Comments created here will be created in the context of that merge request.
...@@ -47,7 +47,6 @@ See the projects' module documentation for more specific information: ...@@ -47,7 +47,6 @@ See the projects' module documentation for more specific information:
* [API Module ](api/README.md) * [API Module ](api/README.md)
* [Core Module ](core/README.md) * [Core Module ](core/README.md)
* [Client Module ](client/README.md) * [Client Module ](client/README.md)
* [Open-API Module ](open-api/README.md)
### Setup ### Setup
......
### OpenAPI Model Generation
This module generates model classes from the open-api specification of the submission api.
Usage: ``mvn compile exec:java`` generates all models into the package ``de.fitko.fitconnect.api.domain.model.submission`` under
**target/generated-sources/openapi/gen**.
### Config
The relevant config parameters are listed below.
````xml
<configuration>
<!-- open api spec url -->
<inputSpec>${submission-api.baseurl}/${submission-api.version}/${submission-api.spec}</inputSpec>
<!-- language generator -->
<generatorName>java</generatorName>
<!-- validation is currently disabled, otherwise the generation fails due to duplicate entries -->
<skipValidateSpec>true</skipValidateSpec>
<!-- use jackson annotations -->
<library>resttemplate</library>
<!-- target package name -->
<modelPackage>de.fitko.fitconnect.api.domain.model.submission</modelPackage>
<!-- target folder to write files into -->
<configOptions>
<sourceFolder>../../../src/main/java</sourceFolder>
</configOptions>
</configuration>
````
### Draft/Todo PostProcessing
The ``de.fitko.fitconnect.api.postprocessing.ModelClassPostProcessor`` is running in a maven execute step and
replaces all comments and unwanted annotations.
Currently, there are some @Nullable and @NonNull annotations from ```javax.annotations``` that need to be replaced.
In a further step the cleaned and post-processed model classes can be updated in the original ``api/domain/model``
package of the ``api`` module via the maven resource plugin.
<?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">
<parent>
<artifactId>sdk-java</artifactId>
<groupId>de.fitko.fitconnect.sdk</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>open-api</artifactId>
<packaging>jar</packaging>
<properties>
<submission-api.baseurl>https://schema.fitko.de/fit-connect/submission-api</submission-api.baseurl>
<submission-api.version>1.0.7</submission-api.version>
<submission-api.spec>submission-api.yaml</submission-api.spec>
</properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.0.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${submission-api.baseurl}/${submission-api.version}/${submission-api.spec}
</inputSpec>
<generatorName>java</generatorName>
<generateApis>false</generateApis>
<skipValidateSpec>true</skipValidateSpec>
<generateApis>false</generateApis>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>false</generateSupportingFiles>
<library>resttemplate</library>
<modelPackage>de.fitko.fitconnect.api.domain.model.submission</modelPackage>
<configOptions>
<sourceFolder>gen</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<mainClass>de.fitko.fitconnect.api.postprocessing.ModelClassPostProcessor</mainClass>
<workingDirectory>postprocessing</workingDirectory>
<arguments>
<argument>target/generated-sources/openapi/gen/de/fitko/fitconnect/api/domain/model/submission
</argument>
</arguments>
</configuration>
</plugin>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-resource-one</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/../api/src/main/java/de/fitko/fitconnect/api/domain/generated
</outputDirectory>
<resources>
<resource>
<directory>
target/generated-sources/openapi/gen/de/fitko/fitconnect/api/domain/model/submission
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>-->
</plugins>
</build>
</project>
\ No newline at end of file
package de.fitko.fitconnect.api.postprocessing;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ModelClassPostProcessor {
private static final Logger logger = LoggerFactory.getLogger(ModelClassPostProcessor.class);
public static void main(final String[] args) {
final ModelClassPostProcessor postProcessor = new ModelClassPostProcessor();
final var dir = args[0]; // -modelPath
postProcessor.readModelsToStrings(dir)
.stream()
.map(ModelClassPostProcessor::replaceContent)
//.peek(pair -> logger.info(pair.content))
.forEach(ModelClassPostProcessor::writeFiles);
}
private static ModelPair replaceContent(final ModelPair pair) {
String content = pair.content;
// Remove all Comments
content = content.replaceAll("\\/\\*([\\S\\s]+?)\\*\\/", "");
content = content.replaceAll("(?s)/\\*.*?\\*/", "");
// Remove unwanted annos
content = content.replaceAll("@ApiModel([\\w]+)((.*))", "");
content = content.replaceAll("@ApiModelProperty([\\w]+)((.*))", "");
content = content.replaceAll("Generated([\\w]+)((.*))", "");
// Replace javax
//content = content.replaceAll("Nonnull([\\w]+)((.*))", "");
//content = content.replaceAll("(@\([\\w]+)\\((.*?)\\)(?:\s|$))", "");
return new ModelPair(pair.originalPath, content);
}
public Set<ModelPair> readModelsToStrings(final String dir) {
return Stream.of(new File(dir).listFiles())
.filter(file -> !file.isDirectory())
.peek(file -> logger.info("Postprocessing model {}", file.getName()))
.map(file -> new ModelPair(file.toPath(), getFileAsString(file)))
.collect(Collectors.toSet());
}
private String getFileAsString(final File file) {
try {
return Files.readString(file.toPath(), StandardCharsets.UTF_8);
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
private static void writeFiles(final ModelPair modelPair) {
try {
final File f = new File(modelPair.originalPath.toFile().getAbsolutePath());
final FileWriter fw = new FileWriter( f, false);
fw.write(modelPair.content);
fw.flush();
fw.close();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
private static class ModelPair {
final Path originalPath;
final String content;
ModelPair(final Path originalPath, final String content) {
this.originalPath = originalPath;
this.content = content;
}
@Override
public String toString() {
return content;
}
}
}
...@@ -47,7 +47,6 @@ ...@@ -47,7 +47,6 @@
<module>api</module> <module>api</module>
<module>core</module> <module>core</module>
<module>client</module> <module>client</module>
<module>open-api</module>
</modules> </modules>
<dependencyManagement> <dependencyManagement>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment