From fee5e3569dda0e6622434be3b9ba6d3856f7954e Mon Sep 17 00:00:00 2001 From: Martin Vogel <martin.vogel@sinc.de> Date: Tue, 6 Sep 2022 08:33:22 +0000 Subject: [PATCH] chore: remove experimental open-api module --- README.md | 1 - open-api/README.md | 47 ------- open-api/pom.xml | 129 ------------------ .../ModelClassPostProcessor.java | 91 ------------ pom.xml | 1 - 5 files changed, 269 deletions(-) delete mode 100644 open-api/README.md delete mode 100644 open-api/pom.xml delete mode 100644 open-api/src/main/java/de/fitko/fitconnect/api/postprocessing/ModelClassPostProcessor.java diff --git a/README.md b/README.md index e8d5f696d..a4cab080f 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,6 @@ See the projects' module documentation for more specific information: * [API Module ](api/README.md) * [Core Module ](core/README.md) * [Client Module ](client/README.md) -* [Open-API Module ](open-api/README.md) ### Setup diff --git a/open-api/README.md b/open-api/README.md deleted file mode 100644 index ed8c51663..000000000 --- a/open-api/README.md +++ /dev/null @@ -1,47 +0,0 @@ -### 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. - diff --git a/open-api/pom.xml b/open-api/pom.xml deleted file mode 100644 index 18466de24..000000000 --- a/open-api/pom.xml +++ /dev/null @@ -1,129 +0,0 @@ -<?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 diff --git a/open-api/src/main/java/de/fitko/fitconnect/api/postprocessing/ModelClassPostProcessor.java b/open-api/src/main/java/de/fitko/fitconnect/api/postprocessing/ModelClassPostProcessor.java deleted file mode 100644 index ea5203dba..000000000 --- a/open-api/src/main/java/de/fitko/fitconnect/api/postprocessing/ModelClassPostProcessor.java +++ /dev/null @@ -1,91 +0,0 @@ -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; - } - } -} diff --git a/pom.xml b/pom.xml index 3501ca279..6d6d10805 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,6 @@ <module>api</module> <module>core</module> <module>client</module> - <module>open-api</module> </modules> <dependencyManagement> -- GitLab