Generate openAPI 3.0 specification.
Issue-ID: AAF-995
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Change-Id: I3de5dae9688d89b3bac0d86beff982247667854d
diff --git a/certService/pom.xml b/certService/pom.xml
index d5b6e7d..89e7023 100644
--- a/certService/pom.xml
+++ b/certService/pom.xml
@@ -40,6 +40,8 @@
<bouncycastle.version>1.60</bouncycastle.version>
<docker-maven-plugin.version>0.33.0</docker-maven-plugin.version>
<docker.tag>${project.version}</docker.tag>
+ <springdoc-openapi-maven-plugin.apiDocsUrl>http://localhost:8080/v3/api-docs
+ </springdoc-openapi-maven-plugin.apiDocsUrl>
</properties>
<dependencyManagement>
@@ -135,7 +137,6 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
-
</plugins>
</pluginManagement>
<plugins>
@@ -148,6 +149,18 @@
<goal>repackage</goal>
</goals>
</execution>
+ <execution>
+ <id>pre-integration-test</id>
+ <goals>
+ <goal>start</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>post-integration-test</id>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
</executions>
</plugin>
<plugin>
@@ -174,6 +187,24 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.springdoc</groupId>
+ <artifactId>springdoc-openapi-maven-plugin</artifactId>
+ <version>0.2</version>
+ <executions>
+ <execution>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <apiDocsUrl>${springdoc-openapi-maven-plugin.apiDocsUrl}</apiDocsUrl>
+ <outputFileName>api-docs.json</outputFileName>
+ <outputDir>${project.build.directory}</outputDir>
+ </configuration>
+ </plugin>
</plugins>
</build>
diff --git a/certService/src/main/java/org/onap/aaf/certservice/certification/CsrModelFactory.java b/certService/src/main/java/org/onap/aaf/certservice/certification/CsrModelFactory.java
index 80858f4..98daa6e 100644
--- a/certService/src/main/java/org/onap/aaf/certservice/certification/CsrModelFactory.java
+++ b/certService/src/main/java/org/onap/aaf/certservice/certification/CsrModelFactory.java
@@ -39,14 +39,14 @@
private final PemObjectFactory pemObjectFactory = new PemObjectFactory();
public CsrModel createCsrModel(StringBase64 csr, StringBase64 privateKey) throws CsrDecryptionException {
- LOGGER.debug("Decoded CSR: \n{}", csr.asString());
+ LOGGER.debug("Decoded CSR: \n{}", csr);
try {
- PemObject pemObject = pemObjectFactory.createPmObject(csr.asString());
+ PemObject pemObject = pemObjectFactory.createPemObject(csr.asString());
PKCS10CertificationRequest decodedCsr = new PKCS10CertificationRequest(
pemObject.getContent()
);
- PemObject decodedPrivateKey = pemObjectFactory.createPmObject(privateKey.asString());
+ PemObject decodedPrivateKey = pemObjectFactory.createPemObject(privateKey.asString());
return new CsrModel(decodedCsr, decodedPrivateKey);
} catch (IOException e) {
throw new CsrDecryptionException("Incorrect CSR, decryption failed", e);
diff --git a/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java b/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java
index e3339cc..08ffc56 100644
--- a/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java
+++ b/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java
@@ -31,7 +31,7 @@
public class PemObjectFactory {
- public PemObject createPmObject(String pem) throws CsrDecryptionException {
+ public PemObject createPemObject(String pem) throws CsrDecryptionException {
try (StringReader stringReader = new StringReader(pem);
PemReader pemReader = new PemReader(stringReader)) {
diff --git a/certService/src/main/resources/application.properties b/certService/src/main/resources/application.properties
index a157ae6..b9ce108 100644
--- a/certService/src/main/resources/application.properties
+++ b/certService/src/main/resources/application.properties
@@ -2,3 +2,4 @@
management.endpoints.enabled-by-default=false
management.endpoint.health.enabled=true
springdoc.swagger-ui.path=/docs
+springdoc.show-actuator=true
diff --git a/certService/src/test/java/org/onap/aaf/certservice/api/CertificationServiceTest.java b/certService/src/test/java/org/onap/aaf/certservice/api/CertificationServiceTest.java
index 99ca09b..9367fcb 100644
--- a/certService/src/test/java/org/onap/aaf/certservice/api/CertificationServiceTest.java
+++ b/certService/src/test/java/org/onap/aaf/certservice/api/CertificationServiceTest.java
@@ -67,7 +67,7 @@
certificationService.signCertificate("TestCa", "encryptedCSR", "encryptedPK");
// then
- assertEquals(testResponse.getStatusCode(), HttpStatus.OK);
+ assertEquals(HttpStatus.OK, testResponse.getStatusCode());
assertTrue(
testResponse.toString().contains(testStringCsr)
);
diff --git a/certService/src/test/java/org/onap/aaf/certservice/certification/PemObjectFactoryTest.java b/certService/src/test/java/org/onap/aaf/certservice/certification/PemObjectFactoryTest.java
index 67d7f1d..2fa747d 100644
--- a/certService/src/test/java/org/onap/aaf/certservice/certification/PemObjectFactoryTest.java
+++ b/certService/src/test/java/org/onap/aaf/certservice/certification/PemObjectFactoryTest.java
@@ -46,7 +46,7 @@
@Test
void shouldTransformStringInToPemObjectAndBackToString() throws CsrDecryptionException {
// when
- PemObject pemObject = pemObjectFactory.createPmObject(TEST_PEM);
+ PemObject pemObject = pemObjectFactory.createPemObject(TEST_PEM);
String parsedPemObject = pemObjectToString(pemObject);
// then
@@ -57,7 +57,7 @@
void shouldThrowExceptionWhenParsingPemFailed() {
// when
Exception exception = assertThrows(
- CsrDecryptionException.class, () -> pemObjectFactory.createPmObject(TEST_WRONG_PEM)
+ CsrDecryptionException.class, () -> pemObjectFactory.createPemObject(TEST_WRONG_PEM)
);
String expectedMessage = "Unable to create PEM";
diff --git a/certService/src/test/java/org/onap/aaf/certservice/certification/model/CsrModelTest.java b/certService/src/test/java/org/onap/aaf/certservice/certification/model/CsrModelTest.java
index ffce61d..c6ff2a9 100644
--- a/certService/src/test/java/org/onap/aaf/certservice/certification/model/CsrModelTest.java
+++ b/certService/src/test/java/org/onap/aaf/certservice/certification/model/CsrModelTest.java
@@ -77,7 +77,7 @@
.thenReturn(wrongKryInfo);
when(wrongKryInfo.getEncoded())
.thenThrow(new IOException());
- PemObject testPrivateKey = pemObjectFactory.createPmObject(TEST_PK);
+ PemObject testPrivateKey = pemObjectFactory.createPemObject(TEST_PK);
CsrModel csrModel = new CsrModel(testCsr, testPrivateKey);
// when
@@ -96,16 +96,16 @@
private CsrModel generateTestCsrModel() throws CsrDecryptionException, IOException {
PemObjectFactory pemObjectFactory = new PemObjectFactory();
PKCS10CertificationRequest testCsr = new PKCS10CertificationRequest(
- pemObjectFactory.createPmObject(TEST_CSR).getContent()
+ pemObjectFactory.createPemObject(TEST_CSR).getContent()
);
- PemObject testPrivateKey = pemObjectFactory.createPmObject(TEST_PK);
+ PemObject testPrivateKey = pemObjectFactory.createPemObject(TEST_PK);
return new CsrModel(testCsr, testPrivateKey);
}
private PemObject generateTestPublicKey() throws CsrDecryptionException, IOException {
PemObjectFactory pemObjectFactory = new PemObjectFactory();
PKCS10CertificationRequest testCsr = new PKCS10CertificationRequest(
- pemObjectFactory.createPmObject(TEST_CSR).getContent()
+ pemObjectFactory.createPemObject(TEST_CSR).getContent()
);
return new PemObject("PUBLIC KEY", testCsr.getSubjectPublicKeyInfo().getEncoded());
}