Skip to content

Commit

Permalink
Merge branch 'dev_openapiplugin' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
maybeec committed Sep 14, 2020
2 parents 2faaef0 + 844ee8d commit 54cab73
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<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>
<artifactId>openapiplugin-model</artifactId>
<version>2.4.0</version>
<version>7.0.0</version>
<name>CobiGen Openapiplugin Model</name>
<packaging>jar</packaging>
<description>CobiGen - OpenAPI Plug-in Model</description>
Expand Down
34 changes: 17 additions & 17 deletions cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>openapiplugin</artifactId>
<name>CobiGen - Open API Plug-in</name>
<version>2.4.0</version>
<version>7.0.0</version>
<packaging>jar</packaging>
<description>CobiGen - OpenAPI Plug-in</description>

Expand All @@ -17,16 +17,16 @@
</properties>

<dependencies>
<dependency>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>openapiplugin-model</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>core-api</artifactId>
<version>5.3.0</version>
<version>[7.0.0,)</version>
</dependency>
<dependency>
<groupId>com.reprezen.kaizen</groupId>
Expand All @@ -43,31 +43,31 @@
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>core-test</artifactId>
<version>6.0.0</version>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>core</artifactId>
<version>6.0.0</version>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>tempeng-freemarker</artifactId>
<version>2.0.0</version>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/META-INF/LICENSEP2BUNDLE.html</exclude>
</excludes>
</resource>
</resources>
</build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/META-INF/LICENSEP2BUNDLE.html</exclude>
</excludes>
</resource>
</resources>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import java.util.List;

import com.devonfw.cobigen.api.annotation.Activation;
import com.devonfw.cobigen.api.extension.GeneratorPluginActivator;
import com.devonfw.cobigen.api.extension.Merger;
import com.devonfw.cobigen.api.extension.TriggerInterpreter;
import com.devonfw.cobigen.openapiplugin.inputreader.OpenAPIInputReader;
import com.google.common.collect.Lists;

/**
* Plug-in activator to be registered at CobiGen.
*/
@Activation(byFileExtension = { OpenAPIInputReader.VALID_EXTENSION_YAML, OpenAPIInputReader.VALID_EXTENSION_YML })
public class OpenAPIPluginActivator implements GeneratorPluginActivator {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.devonfw.cobigen.openapiplugin;

import com.devonfw.cobigen.api.annotation.ReaderPriority;
import com.devonfw.cobigen.api.extension.InputReader;
import com.devonfw.cobigen.api.extension.MatcherInterpreter;
import com.devonfw.cobigen.api.extension.Priority;
import com.devonfw.cobigen.api.extension.TriggerInterpreter;
import com.devonfw.cobigen.openapiplugin.inputreader.OpenAPIInputReader;
import com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher;

/**
* {@link TriggerInterpreter} implementation of a Swagger Interpreter
*/
@ReaderPriority(Priority.LOW)
public class OpenAPITriggerInterpreter implements TriggerInterpreter {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.devonfw.cobigen.openapiplugin.model.ResponseDef;
import com.devonfw.cobigen.openapiplugin.model.ServerDef;
import com.devonfw.cobigen.openapiplugin.util.constants.Constants;
import com.jayway.jsonpath.Configuration;
import com.reprezen.jsonoverlay.JsonOverlay;
import com.reprezen.jsonoverlay.Overlay;
import com.reprezen.jsonoverlay.Reference;
Expand All @@ -55,6 +54,12 @@
*/
public class OpenAPIInputReader implements InputReader {

/** Valid extensions for the input reader */
public static final String VALID_EXTENSION_YAML = "yaml";

/** Valid extensions for the input reader */
public static final String VALID_EXTENSION_YML = "yml";

/**
* Components retrieved from an EntityDef. Used for not executing multiple times the retrieval of
* components
Expand Down Expand Up @@ -215,7 +220,6 @@ private ComponentDef getComponent(String componentName) {
* @return list of entities
*/
private List<EntityDef> extractComponents(OpenApi3 openApi) {
Object document = Configuration.defaultConfiguration().jsonProvider().parse(Overlay.toJson(openApi).toString());
HeaderDef header = new HeaderDef();
header.setServers(extractServers(openApi));
header.setInfo(extractInfo(openApi));
Expand All @@ -227,7 +231,7 @@ private List<EntityDef> extractComponents(OpenApi3 openApi) {
entityDef.setName(key);
entityDef.setDescription(openApi.getSchema(key).getDescription());
ComponentDef componentDef = new ComponentDef();
entityDef.setProperties(extractProperties(openApi, document, key));
entityDef.setProperties(extractProperties(openApi, key));

// If no x-component tag was found on the input file, throw invalid configuration
if (openApi.getSchema(key).getExtensions().get(Constants.COMPONENT_EXT) == null) {
Expand Down Expand Up @@ -348,13 +352,11 @@ private PropertyDef extractReferenceProperty(OpenApi3 openApi, Schema componentS
*
* @param openApi
* the OpenApi3 model
* @param jsonDocument
* parsed JSON document
* @param componentName
* entity name
* @return List of {@link PropertyDef}'s
*/
private List<PropertyDef> extractProperties(OpenApi3 openApi, Object jsonDocument, String componentName) {
private List<PropertyDef> extractProperties(OpenApi3 openApi, String componentName) {
Schema componentSchema = openApi.getSchema(componentName);
Map<String, ? extends Schema> properties = componentSchema.getProperties();
List<PropertyDef> objects = new LinkedList<>();
Expand Down Expand Up @@ -698,7 +700,7 @@ public Object read(java.nio.file.Path path, Charset inputCharset, Object... addi

@Override
public boolean isMostLikelyReadable(java.nio.file.Path path) {
List<String> validExtensions = Arrays.asList("yaml", "yml");
List<String> validExtensions = Arrays.asList(VALID_EXTENSION_YAML, VALID_EXTENSION_YML);
String fileExtension = FilenameUtils.getExtension(path.toString()).toLowerCase();
return validExtensions.contains(fileExtension);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.devonfw.cobigen.api.to.GenerationReportTo;
import com.devonfw.cobigen.api.to.TemplateTo;
import com.devonfw.cobigen.impl.CobiGenFactory;
import com.devonfw.cobigen.openapiplugin.model.OpenAPIFile;
import com.devonfw.cobigen.openapiplugin.util.TestConstants;

import junit.framework.AssertionFailedError;
Expand All @@ -42,8 +41,7 @@ public class InputReaderMatcherTest {
public void testBasicElementMatcher_oneComponent() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates").toUri());

Object openApiFile =
cobigen.read("openapi", Paths.get(testdataRoot, "one-component.yaml"), TestConstants.UTF_8);
Object openApiFile = cobigen.read(Paths.get(testdataRoot, "one-component.yaml"), TestConstants.UTF_8);
assertThat(openApiFile).isNotNull();

List<Object> inputObjects = cobigen.resolveContainers(openApiFile);
Expand All @@ -59,8 +57,7 @@ public void testBasicElementMatcher_oneComponent() throws Exception {
public void testBasicElementMatcher_twoComponents() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates").toUri());

Object openApiFile =
cobigen.read("openapi", Paths.get(testdataRoot, "two-components.yaml"), TestConstants.UTF_8);
Object openApiFile = cobigen.read(Paths.get(testdataRoot, "two-components.yaml"), TestConstants.UTF_8);
assertThat(openApiFile).isNotNull();

List<Object> inputObjects = cobigen.resolveContainers(openApiFile);
Expand All @@ -76,8 +73,7 @@ public void testBasicElementMatcher_twoComponents() throws Exception {
public void testVariableAssignment_propertyName() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates").toUri());

Object openApiFile =
cobigen.read("openapi", Paths.get(testdataRoot, "one-component.yaml"), TestConstants.UTF_8);
Object openApiFile = cobigen.read(Paths.get(testdataRoot, "one-component.yaml"), TestConstants.UTF_8);
List<Object> inputObjects = cobigen.resolveContainers(openApiFile);

String templateName = "testVariableAssignment_propertyName.txt";
Expand All @@ -101,8 +97,7 @@ public void testVariableAssignment_propertyName() throws Exception {
public void testVariableAssignment_rootPackage() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates").toUri());

Object openApiFile = cobigen.read("openapi", Paths.get(testdataRoot, "root-package.yaml"), TestConstants.UTF_8);
OpenAPIFile inputFile = (OpenAPIFile) openApiFile;
Object openApiFile = cobigen.read(Paths.get(testdataRoot, "root-package.yaml"), TestConstants.UTF_8);

// Previous version: List<Object> inputObjects = cobigen.getInputObjects(openApiFile,
// TestConstants.UTF_8);
Expand All @@ -119,18 +114,18 @@ public void testVariableAssignment_rootPackage() throws Exception {
.hasContent("testingRootName");
}

/*
/**
* Tests variable assignment resolution of ROOTPACKAGE type, thus that the user can define the root
* package in the "info" part of the OpenAPI file
*
* @throws Exception test fails
* @throws Exception
* test fails
*/
@Test
public void testVariableAssignment_rootComponent() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates").toUri());

Object openApiFile = cobigen.read("openapi", Paths.get(testdataRoot, "root-package.yaml"), TestConstants.UTF_8);
OpenAPIFile inputFile = (OpenAPIFile) openApiFile;
Object openApiFile = cobigen.read(Paths.get(testdataRoot, "root-package.yaml"), TestConstants.UTF_8);

// Previous version: List<Object> inputObjects = cobigen.getInputObjects(openApiFile,
// TestConstants.UTF_8);
Expand Down Expand Up @@ -160,9 +155,7 @@ public void testVariableAssignment_rootComponent() throws Exception {
public void testVariableAssignment_attribute() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates").toUri());

Object openApiFile =
cobigen.read("openapi", Paths.get(testdataRoot, "two-components.yaml"), TestConstants.UTF_8);
OpenAPIFile inputFile = (OpenAPIFile) openApiFile;
Object openApiFile = cobigen.read(Paths.get(testdataRoot, "two-components.yaml"), TestConstants.UTF_8);

// Previous version: List<Object> inputObjects = cobigen.getInputObjects(openApiFile,
// TestConstants.UTF_8);
Expand Down Expand Up @@ -201,8 +194,7 @@ public void testVariableAssignment_noAttributeFound() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates").toUri());

Object openApiFile =
cobigen.read("openapi", Paths.get(testdataRoot, "two-components-no-attribute.yaml"), TestConstants.UTF_8);
OpenAPIFile inputFile = (OpenAPIFile) openApiFile;
cobigen.read(Paths.get(testdataRoot, "two-components-no-attribute.yaml"), TestConstants.UTF_8);

// Previous version: List<Object> inputObjects = cobigen.getInputObjects(openApiFile,
// TestConstants.UTF_8);
Expand Down
2 changes: 0 additions & 2 deletions cobigen/cobigen-openapiplugin-parent/pom.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<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>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>openapiplugin-parent</artifactId>
<version>dev-SNAPSHOT</version>
<packaging>pom</packaging>
<name>CobiGen Openapiplugin Parent</name>

Expand Down
4 changes: 2 additions & 2 deletions cobigen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

<profiles>
<profile>
<id>p2-bundle</id> <!-- Bundle and P2 -->
<id>p2-bundle</id> <!-- Bundle and P2 -->
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -139,7 +139,7 @@
<Embed-Transitive>true</Embed-Transitive>
<Bundle-Name>${project.name}</Bundle-Name>
<Include-Resource>
{maven-resources}, {maven-dependencies}, {META-INF/LICENSE.html=src/main/resources/META-INF/LICENSEP2BUNDLE.html}
{maven-resources}, {maven-dependencies}, {META-INF/LICENSE.html=src/main/resources/META-INF/LICENSEP2BUNDLE.html}
</Include-Resource>
<niceManifest>true</niceManifest>
<Import-Package></Import-Package>
Expand Down
2 changes: 1 addition & 1 deletion documentation/master-cobigen.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ DISCLAIMER: All Cobigen plugins are compatible with the latest release of Devonf
* CobiGen - Text Merger v2.1.0
* CobiGen - JSON Plug-in v7.0.0
* CobiGen - HTML Plug-in v7.0.0
* CobiGen - Open API Plug-in v2.4.0
* CobiGen - Open API Plug-in v7.0.0
* CobiGen - FreeMaker Template Engine v7.0.0
* CobiGen - Velocity Template Engine v7.0.0

Expand Down

0 comments on commit 54cab73

Please sign in to comment.