BJ-1025: Initial swag for my-documents (#1)

* BJ-1025: Initial swag for my-documents
This commit is contained in:
malkoas 2020-12-16 17:54:02 +03:00 committed by GitHub
parent b5bac71ad9
commit 88be285635
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 7185 additions and 0 deletions

60
.gitignore vendored Normal file
View File

@ -0,0 +1,60 @@
# Dir for API portal deploy
dist
out
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
node_modules
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history
# CI
.wercker
# Generated
web_deploy/
# User-specific stuff:
.idea/
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries

4
.gitmodules vendored Normal file
View File

@ -0,0 +1,4 @@
[submodule "build_utils"]
path = build_utils
url = git@github.com:rbkmoney/build_utils.git
branch = master

18
.redocly.yaml Normal file
View File

@ -0,0 +1,18 @@
# See https://docs.redoc.ly/cli/configuration/ for more information.
apiDefinitions:
core: "openapi/openapi.yaml"
lint:
plugins:
- './plugins/local.js'
extends:
- recommended
rules:
tag-description: off
preprocessors:
local/merge-schemas: on
referenceDocs:
showConsole: true
layout:
scope: section
routingStrategy: browser
htmlTemplate: ./web/index.html

58
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,58 @@
#!groovy
// -*- mode: groovy -*-
build('swag-my-documents', 'docker-host') {
checkoutRepo()
loadBuildUtils('build_utils')
def pipeDefault
def withWsCache
def gitUtils
runStage('load pipeline') {
env.JENKINS_LIB = "build_utils/jenkins_lib"
pipeDefault = load("${env.JENKINS_LIB}/pipeDefault.groovy")
withWsCache = load("${env.JENKINS_LIB}/withWsCache.groovy")
gitUtils = load("${env.JENKINS_LIB}/gitUtils.groovy")
}
pipeDefault() {
runStage('install-deps') {
withWsCache("node_modules") {
sh 'make wc_install'
}
}
runStage('validate-spec') {
sh 'make wc_validate'
}
runStage('bundle') {
sh 'make wc_build'
}
// Java
runStage('build java client & server') {
withCredentials([[$class: 'FileBinding', credentialsId: 'java-maven-settings.xml', variable: 'SETTINGS_XML']]) {
if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME.startsWith('epic/')) {
sh 'make SETTINGS_XML=${SETTINGS_XML} BRANCH_NAME=${BRANCH_NAME} java.swag.deploy_client'
sh 'make SETTINGS_XML=${SETTINGS_XML} BRANCH_NAME=${BRANCH_NAME} java.swag.deploy_server'
} else {
sh 'make SETTINGS_XML=${SETTINGS_XML} BRANCH_NAME=${BRANCH_NAME} java.swag.compile_client'
sh 'make SETTINGS_XML=${SETTINGS_XML} BRANCH_NAME=${BRANCH_NAME} java.swag.compile_server'
}
}
}
// Release
if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME.startsWith('epic/')) {
runStage('publish release bundle') {
dir("web_deploy") {
gitUtils.push(commitMsg: "Generated from commit: $COMMIT_ID \n\non $BRANCH_NAME in $RBK_REPO_URL\n\nChanges:\n$COMMIT_MSG",
files: "*", branch: "release/$BRANCH_NAME", orphan: true)
}
}
}
}
}

90
Makefile Normal file
View File

@ -0,0 +1,90 @@
UTILS_PATH := build_utils
TEMPLATES_PATH := .
SERVICE_NAME := swag-my-documents
BUILD_IMAGE_TAG := 442c2c274c1d8e484e5213089906a4271641d95e
CALL_ANYWHERE := all install validate build java.compile java.deploy
CALL_W_CONTAINER := $(CALL_ANYWHERE)
all: validate
-include $(UTILS_PATH)/make_lib/utils_container.mk
.PHONY: $(CALL_W_CONTAINER)
install:
npm install
validate:
npm run validate
build:
npm run build
# Java
ifdef SETTINGS_XML
DOCKER_RUN_OPTS = -v $(SETTINGS_XML):$(SETTINGS_XML)
DOCKER_RUN_OPTS += -e SETTINGS_XML=$(SETTINGS_XML)
endif
ifdef LOCAL_BUILD
DOCKER_RUN_OPTS += -v $$HOME/.m2:/home/$(UNAME)/.m2:rw
endif
COMMIT_HASH := $(shell git --no-pager log -1 --pretty=format:"%h")
NUMBER_COMMITS := $(shell git rev-list --count HEAD)
JAVA_PKG_VERSION := 1.$(NUMBER_COMMITS)-$(COMMIT_HASH)
ifdef BRANCH_NAME
ifeq "$(findstring epic,$(BRANCH_NAME))" "epic"
JAVA_PKG_VERSION := $(JAVA_PKG_VERSION)-epic
endif
endif
MVN = mvn -s $(SETTINGS_XML) -Dcommit.number="$(NUMBER_COMMITS)"
java.swag.compile_client: java.settings
$(MVN) clean && \
$(MVN) compile -P="client"
java.swag.deploy_client: java.settings
$(MVN) clean && \
$(MVN) versions:set versions:commit -DnewVersion="$(JAVA_PKG_VERSION)-client" && \
$(MVN) deploy -P="client"
java.swag.install_client: java.settings
$(MVN) clean && \
$(MVN) versions:set versions:commit -DnewVersion="$(JAVA_PKG_VERSION)-client" && \
$(MVN) install -P="client"
java.swag.compile_server: java.settings
$(MVN) clean && \
$(MVN) compile -P="server"
java.swag.deploy_server: java.settings
$(MVN) clean && \
$(MVN) versions:set versions:commit -DnewVersion="$(JAVA_PKG_VERSION)-server" && \
$(MVN) deploy -P="server"
java.swag.install_server: java.settings
$(MVN) clean && \
$(MVN) versions:set versions:commit -DnewVersion="$(JAVA_PKG_VERSION)-server" && \
$(MVN) install -P="server"
java.compile: java.settings
$(MVN) compile
java.deploy: java.settings
$(MVN) versions:set versions:commit -DnewVersion="$(JAVA_PKG_VERSION)" && \
$(MVN) deploy
java.install: java.settings
$(MVN) clean && \
$(MVN) versions:set versions:commit -DnewVersion="$(JAVA_PKG_VERSION)" && \
$(MVN) install
java.settings:
$(if $(SETTINGS_XML),, echo "SETTINGS_XML not defined"; exit 1)

1
build_utils Submodule

@ -0,0 +1 @@
Subproject commit e1318727d4d0c3e48f5122bf3197158b6695f50e

View File

@ -0,0 +1,8 @@
name: X-Request-Deadline
in: header
description: Максимальное время обработки запроса
required: false
schema:
type: string
minLength: 1
maxLength: 40

View File

@ -0,0 +1,16 @@
name: documentType
in: query
description: Тип документов
required: true
schema:
type: array
items:
type: string
enum:
- tariffAgreement
- identityCardHeadOfOrganization
- statementShareholdersRegister
- locationInformation
- clientQuestionnaire
- financialPosition
- businessReputation

View File

@ -0,0 +1,8 @@
name: partyID
in: query
description: Уникальный идентификатор участника в рамках платформы
required: false
schema:
type: string
maxLength: 40
minLength: 1

View File

@ -0,0 +1,8 @@
name: X-Request-ID
in: header
description: Уникальный идентификатор запроса к системе
required: true
schema:
type: string
minLength: 4
maxLength: 64

View File

@ -0,0 +1,17 @@
description: Ошибка бизнес-логики
content:
application/json:
schema:
description: Ошибка в переданных данных
type: object
required:
- code
properties:
code:
type: string
enum:
- invalidRequest
- invalidDeadline
- invalidPartyID
message:
type: string

View File

@ -0,0 +1,36 @@
type: object
required:
- id
- expirationDate
- documentType
- partyID
- files
properties:
id:
description: Идентификатор документа
type: integer
format: int64
expirationDate:
description: Дата окончания срока действия
type: string
format: date
documentType:
description: Тип документа
type: string
enum:
- tariffAgreement
- identityCardHeadOfOrganization
- statementShareholdersRegister
- locationInformation
- clientQuestionnaire
- financialPosition
- businessReputation
partyID:
description: Идентификатор участника
type: string
maxLength: 40
minLength: 1
files:
type: array
items:
$ref: '../schemas/File.yaml'

View File

@ -0,0 +1,15 @@
type: object
required:
- id
- filename
properties:
id:
description: Идентификатор файла
type: string
maxLength: 40
minLength: 1
filename:
description: Имя файла
type: string
maxLength: 1000
minLength: 1

View File

@ -0,0 +1,14 @@
type: http
scheme: bearer
bearerFormat: JWT
description: >
Для аутентификации вызовов мы используем [JWT](https://jwt.io).
Токен доступа передается в заголовке.
```shell
Authorization: Bearer {JWT}
```
Запросы к данному API авторизуются сессионным токеном доступа,
который вы получаете в результате аутентификации в личном кабинете
по адресу https://dashboard.rbk.money/.

14
openapi/docs/api.md Normal file
View File

@ -0,0 +1,14 @@
RBKmoney Documents API служит для получения документов мерчанта.
Схема которого описывается в соответствии со стандартом [OpenAPI 3][OAS3].
[OAS3]: https://swagger.io/specification/
## Формат содержимого
Любой запрос к API должен выполняться в кодировке UTF-8 и с указанием
содержимого в формате JSON.
```
Content-Type: application/json; charset=utf-8
```

29
openapi/openapi.yaml Normal file
View File

@ -0,0 +1,29 @@
openapi: 3.0.3
info:
version: 1.0.0
title: RBKmoney Documents API
description: >
## Описание
RBKmoney Documents API служит для получения документов мерчанта.
termsOfService: 'https://rbk.money/'
contact:
name: RBKmoney support team
email: support@rbk.money
url: 'https://developer.rbk.money'
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
components:
securitySchemes:
bearer:
$ref: './components/security-schemes/Bearer.yaml'
paths:
/documents:
$ref: ./paths/documents.yaml
tags:
- name: Documents
x-displayName: Документы
servers:
- url: 'https://api.rbk.money/lk/v1'

View File

@ -0,0 +1,30 @@
get:
summary: Получить список документов по магазину
tags:
- Documents
operationId: getDocuments
parameters:
- $ref: '../components/parameters/requestId.yaml'
- $ref: '../components/parameters/deadline.yaml'
- $ref: '../components/parameters/partyIDQuery.yaml'
- $ref: '../components/parameters/documentType.yaml'
responses:
'200':
description: Найденные документы
content:
application/json:
schema:
type: object
required:
- results
properties:
results:
type: array
items:
$ref: '../components/schemas/Document.yaml'
'400':
$ref: '../components/responses/DefaultLogicError.yaml'
'401':
description: Ошибка авторизации
'404':
description: Заданный ресурс не найден

6468
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

15
package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "swag-my-documents",
"version": "0.0.1",
"private": true,
"dependencies": {
"@redocly/openapi-cli": "^1.0.0-beta.25",
"json-merge-patch": "^1.0.0",
"redoc-cli": "^0.10.2"
},
"scripts": {
"start": "openapi preview-docs",
"build": "openapi bundle -o web_deploy/openapi.yaml && openapi bundle -o web_deploy/openapi.json",
"validate": "openapi lint"
}
}

50
plugins/local.js Normal file
View File

@ -0,0 +1,50 @@
const jsonmergepatch = require('json-merge-patch');
module.exports = {
id: 'local',
preprocessors: {
oas3: {
'merge-schemas': MergeSchemas
}
}
};
function MergeSchemas() {
const trigger = 'x-mergeSchemas';
return {
Schema: {
leave(node, ctx) {
if (!node[trigger]) {
return;
}
var schemas = node[trigger];
if (!Array.isArray(schemas)) {
return ctx.report({
message: "Argument should be an array of schemas",
location: ctx.location.child(trigger)
});
}
let merged = null;
for (index = schemas.length - 1; index >= 0; --index) {
let schema = schemas[index];
if (typeof schema !== 'object') {
return ctx.report({
message: "Non-object value",
location: ctx.location.child(trigger).child(index)
});
}
if (schema.$ref && typeof schema.$ref === 'string') {
schema = ctx.resolve(schema).node;
}
merged = jsonmergepatch.apply(merged, schema);
console.log(merged);
};
Object.assign(node, merged);
delete node[trigger];
}
}
}
}

201
pom.xml Normal file
View File

@ -0,0 +1,201 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.rbkmoney</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>swag-my-documents</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<default.package>com.rbkmoney.swag.my.documents</default.package>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-plugin-version>1.0.0</maven-plugin-version>
<java.version>13</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<slf4j-version>1.7.30</slf4j-version>
<junit-version>4.12</junit-version>
<servlet-api-version>2.5</servlet-api-version>
<jackson-version>2.11.2</jackson-version>
<spring-version>2.4.1</spring-version>
<javax-annotation-api-version>1.3.2</javax-annotation-api-version>
<jaxb-version>2.3.1</jaxb-version>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-version}</version>
<scope>provided</scope>
</dependency>
<!--Spring dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>${spring-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>${spring-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>${spring-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax-annotation-api-version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.1</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>server</id>
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.3</version>
<executions>
<execution>
<id>spring-server</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>web_deploy/openapi.yaml</inputSpec>
<generatorName>spring</generatorName>
<configOptions>
<dateLibrary>java8</dateLibrary>
</configOptions>
<apiPackage>${default.package}.api</apiPackage>
<modelPackage>${default.package}.model</modelPackage>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>client</id>
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.3</version>
<executions>
<execution>
<id>remote</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>web_deploy/openapi.yaml</inputSpec>
<generatorName>java</generatorName>
<configOptions>
<dateLibrary>java8</dateLibrary>
</configOptions>
<library>resttemplate</library>
<apiPackage>${default.package}.api</apiPackage>
<modelPackage>${default.package}.model</modelPackage>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

25
web/index.html Normal file
View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>RBKmoney Documents API</title>
<!-- needed for adaptive design -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="favicon.png">
<!--
ReDoc uses font options from the parent element
So override default browser styles
-->
<style>
body {
margin: 0;
padding: 0;
}
</style>
{{{redocHead}}}
</head>
<body>
{{{redocHTML}}}
</body>
</html>