Commit 29e6cd3f authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

GONRG-997

Added a swagger 3.0
parent e52297c8
......@@ -2,72 +2,92 @@
<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>
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>backup-service</artifactId>
<groupId>org.opengroup.osdu</groupId>
<version>0.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<parent>
<artifactId>backup-service</artifactId>
<groupId>org.opengroup.osdu</groupId>
<version>0.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<properties>
<os-core-common.version>0.3.5</os-core-common.version>
<openapi.version>1.4.8</openapi.version>
</properties>
<artifactId>backup-core</artifactId>
<description>Backup service Core on GCP</description>
<version>0.0.1</version>
<artifactId>backup-core</artifactId>
<description>Backup service Core on GCP</description>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>0.3.5</version>
</dependency>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>${os-core-common.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>1.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>5.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>1.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>5.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.7.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.7.RELEASE</version>
<scope>test</scope>
</dependency>
<!-- OpenAPI -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${openapi.version}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-data-rest</artifactId>
<version>${openapi.version}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-data-rest</artifactId>
<version>${openapi.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.backup;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
......
/*
* Copyright 2020 Google LLC
* Copyright 2020 EPAM Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.backup.config;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.examples.Example;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springdoc.core.customizers.OperationCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfiguration {
@Bean
public OpenAPI openApi() {
return new OpenAPI()
.info(new Info()
.description(
"Backup service provide a set of APIs to schedule backups for different Assets "
+ "(Datastore, Storage, ElasticSearch, etc depends on "
+ "which currently implemented ), \n"
+ "list registered Schedules, list available Backups, "
+ "restore Asset state from Backup.")
.title("Backup Service")
.version("1.0"))
.components(new Components()
.addSecuritySchemes("JWT",
new SecurityScheme()
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")
.in(SecurityScheme.In.HEADER)
.name("Authorization")))
.addSecurityItem(
new SecurityRequirement()
.addList("JWT"));
}
@Bean
public OperationCustomizer customize() {
return (operation, handlerMethod) -> operation.addParametersItem(
new Parameter()
.in("header")
.required(true)
.description("Tenant Id")
.addExample("opendes", getTenantExample())
.name(DpsHeaders.DATA_PARTITION_ID));
}
private Example getTenantExample() {
Example example = new Example();
example.setValue("opendes");
example.setDescription("Tenant Id");
return example;
}
}
......@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.backup.config.property;
import lombok.Getter;
......@@ -25,8 +24,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "osdu.entitlements")
public class EntitlementProperties {
private String url;
private String url;
private String appKey;
private String appKey;
}
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.backup.config.property;
import java.util.concurrent.TimeUnit;
......@@ -10,12 +25,12 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "osdu.scheduler")
public class SchedulersProperties {
private TimeUnit tearDownTimeUnit;
private TimeUnit tearDownTimeUnit;
private TimeUnit backupTimeUnit;
private TimeUnit backupTimeUnit;
private int tearDownPeriod;
private int tearDownPeriod;
private int initialDelay;
private int initialDelay;
}
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.backup.swagger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping(value = "/swagger")
public String swagger() {
System.out.println("swagger-ui.html");
return "redirect:swagger-ui.html";
}
}
{
"openapi": "3.0.1",
"info": {
"title": "Backup Service",
"description": "Backup service provide a set of APIs to schedule backups for different Assets (Datastore, Storage, ElasticSearch, etc depends on which currently implemented ), \nlist registered Schedules, list available Backups, restore Asset state from Backup.",
"version": "1.0"
},
"servers": [
{
"url": "http://localhost:8080/api/backup/v1",
"description": "Generated server url"
}
],
"security": [
{
"JWT": []
}
],
"paths": {
"/list_backups": {
"get": {
"tags": [
"backup-api"
],
"operationId": "listBackups",
"parameters": [
{
"name": "data-partition-id",
"in": "header",
"description": "Tenant Id",
"required": true,
"examples": {
"opendes": {
"description": "Tenant Id",
"value": "opendes"
}
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"$ref": "#/components/schemas/BackupStamp"
}
}
}
}
}
}
}
}
},
"/backup_import": {
"post": {
"tags": [
"backup-api"
],
"operationId": "submitImport",
"parameters": [
{
"name": "data-partition-id",
"in": "header",
"description": "Tenant Id",
"required": true,
"examples": {
"opendes": {
"description": "Tenant Id",
"value": "opendes"
}
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BackupImportRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/BackupStamp"
}
}
}
}
}
}
},
"/list_schedules": {
"get": {
"tags": [
"backup-api"
],
"operationId": "listSchedules",
"parameters": [
{
"name": "data-partition-id",
"in": "header",
"description": "Tenant Id",
"required": true,
"examples": {
"opendes": {
"description": "Tenant Id",
"value": "opendes"
}
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/BackupSchedule"
}
}
}
}
}
}
}
},
"/schedule": {
"get": {
"tags": [
"backup-api"
],
"operationId": "getScheduleById",
"parameters": [
{
"name": "id",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "data-partition-id",
"in": "header",
"description": "Tenant Id",
"required": true,
"examples": {
"opendes": {
"description": "Tenant Id",
"value": "opendes"
}
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/BackupSchedule"
}
}
}
}
}
},
"put": {
"tags": [
"backup-api"
],
"operationId": "updateBackupSchedule",
"parameters": [
{
"name": "data-partition-id",
"in": "header",
"description": "Tenant Id",
"required": true,
"examples": {
"opendes": {
"description": "Tenant Id",
"value": "opendes"
}
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BackupSchedule"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/BackupSchedule"
}
}
}
}
}
},
"post": {
"tags": [
"backup-api"
],
"operationId": "submitBackupSchedule",
"parameters": [
{
"name": "data-partition-id",
"in": "header",
"description": "Tenant Id",
"required": true,
"examples": {
"opendes": {
"description": "Tenant Id",
"value": "opendes"
}
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BackupSchedule"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/BackupSchedule"
}
}
}
}