OPS-156: init swag (#1)

This commit is contained in:
mr-impossibru 2022-08-18 13:05:12 +03:00 committed by GitHub
parent 8fafe7413d
commit 5f05ba80a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 6298 additions and 0 deletions

15
.github/workflows/basic-linters.yml vendored Normal file
View File

@ -0,0 +1,15 @@
name: Vality basic linters
on:
pull_request:
branches:
- master
- main
push:
branches:
- master
- main
jobs:
lint:
uses: valitydev/base-workflows/.github/workflows/basic-linters.yml@v1

10
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,10 @@
name: Maven Build Artifact
on:
pull_request:
branches:
- '*'
jobs:
build:
uses: valitydev/base-workflow/.github/workflows/maven-swag-build.yml@v1

18
.github/workflows/deploy.yml vendored Normal file
View File

@ -0,0 +1,18 @@
name: Maven Deploy Artifact
on:
push:
branches:
- 'master'
- 'main'
jobs:
deploy:
uses: valitydev/java-workflow/.github/workflows/maven-swag-deploy.yml@v1
secrets:
server-username: ${{ secrets.OSSRH_USERNAME }}
server-password: ${{ secrets.OSSRH_TOKEN }}
deploy-secret-key: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
deploy-secret-key-password: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
github-token: ${{ secrets.GITHUB_TOKEN }}
mm-webhook-url: ${{ secrets.MATTERMOST_WEBHOOK_URL }}

2
.github/workflows/settings.yml vendored Normal file
View File

@ -0,0 +1,2 @@
# These settings are synced to GitHub by https://probot.github.io/apps/settings/
_extends: .github

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

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

98
Makefile Normal file
View File

@ -0,0 +1,98 @@
UTILS_PATH := build_utils
TEMPLATES_PATH := .
SERVICE_NAME := swag-gambit
BUILD_IMAGE_TAG := 917afcdd0c0a07bf4155d597bbba72e962e1a34a
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
REPO_PROFILE := private
ifdef REPO_PUBLIC
ifeq ($(REPO_PUBLIC), true)
REPO_PROFILE := public
endif
endif
MVN = mvn -s $(SETTINGS_XML) -Dcommit.number="$(NUMBER_COMMITS)"
java.openapi.compile_client: java.settings
$(MVN) clean && \
$(MVN) compile -P="client" -P="$(REPO_PROFILE)
java.openapi.deploy_client: java.settings
$(MVN) clean && \
$(MVN) versions:set versions:commit -DnewVersion="$(JAVA_PKG_VERSION)-client" && \
$(MVN) deploy --batch-mode -Dgpg.keyname="$(GPG_KEYID)" -Dgpg.passphrase="$(GPG_PASSPHRASE)" -P="client" -P="$(REPO_PROFILE)
java.openapi.install_client: java.settings
$(MVN) clean && \
$(MVN) versions:set versions:commit -DnewVersion="$(JAVA_PKG_VERSION)-client" && \
$(MVN) install -P="client" -P="$(REPO_PROFILE)
java.openapi.compile_server: java.settings
$(MVN) clean && \
$(MVN) compile -P="server" -P="$(REPO_PROFILE)
java.openapi.deploy_server: java.settings
$(MVN) clean && \
$(MVN) versions:set versions:commit -DnewVersion="$(JAVA_PKG_VERSION)-server" && \
$(MVN) deploy --batch-mode -Dgpg.keyname="$(GPG_KEYID)" -Dgpg.passphrase="$(GPG_PASSPHRASE)" -P="server" -P="$(REPO_PROFILE)
java.openapi.install_server: java.settings
$(MVN) clean && \
$(MVN) versions:set versions:commit -DnewVersion="$(JAVA_PKG_VERSION)-server" && \
$(MVN) install -P="server" -P="$(REPO_PROFILE)
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)

View File

@ -0,0 +1,5 @@
description: Access forbidden
content:
application/json:
schema:
$ref: ../schemas/Error.yaml

View File

@ -0,0 +1,5 @@
description: Bad request data
content:
application/json:
schema:
$ref: ../schemas/Error.yaml

View File

@ -0,0 +1,5 @@
description: Resource was not found
content:
application/json:
schema:
$ref: ../schemas/Error.yaml

View File

@ -0,0 +1,5 @@
description: Unauthenticated
content:
application/json:
schema:
$ref: ../schemas/Error.yaml

View File

@ -0,0 +1,6 @@
type: object
required:
- message
properties:
message:
type: string

View File

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

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

@ -0,0 +1 @@
ValityDev Gambit API

28
openapi/openapi.yaml Normal file
View File

@ -0,0 +1,28 @@
openapi: 3.0.3
info:
version: 1.0.0
title: Vality Gambit API
description:
$ref: './docs/api.md'
termsOfService: http://vality.dev/
contact:
name: Vality support team
email: support@vality.dev
url: 'https://developer.vality.com'
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
- url: 'https://gambit:8080/gambit/v1'
paths:
/data-sets:
$ref: ./paths/createOrUpdateDataSet.yaml
security:
- bearer: []
tags:
- name: dataSets
x-displayName: Data Sets
components:
securitySchemes:
bearer:
$ref: './components/security-schemes/Bearer.yaml'

View File

@ -0,0 +1,63 @@
post:
summary: Сохранение нового набора данных
operationId: createDataSet
tags:
- dataSets
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
dataSetName:
description: unique name of data set
type: string
file:
description: csv file with header
type: string
format: binary
responses:
'201':
description: Created new data set
'400':
$ref: '../components/responses/BadRequest.yaml'
'401':
$ref: '../components/responses/Unauthenticated.yaml'
'403':
$ref: '../components/responses/AccessForbidden.yaml'
'404':
$ref: '../components/responses/NotFound.yaml'
put:
summary: Добавление данных в существующий набор
operationId: updateDataSet
tags:
- dataSets
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
dataSetName:
description: name of already existing data set
type: string
file:
description: csv file with header
type: string
format: binary
responses:
'201':
description: Updated data set
'400':
$ref: '../components/responses/BadRequest.yaml'
'401':
$ref: '../components/responses/Unauthenticated.yaml'
'403':
$ref: '../components/responses/AccessForbidden.yaml'
'404':
$ref: '../components/responses/NotFound.yaml'

5654
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-gambit",
"version": "0.1.0",
"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];
}
}
}
}

205
pom.xml Normal file
View File

@ -0,0 +1,205 @@
<?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>dev.vality</groupId>
<artifactId>library-parent-pom</artifactId>
<version>1.0.2</version>
</parent>
<artifactId>swag-gambit</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Gambit</name>
<description>Generates jar artifact containing compiled openapi classes based on generated openapi yaml files
</description>
<properties>
<default.package>dev.vality.openapi.gambit</default.package>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-plugin-version>1.0.0</maven-plugin-version>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<slf4j-version>1.7.21</slf4j-version>
<junit-version>4.13.2</junit-version>
<servlet-api-version>2.5</servlet-api-version>
<jackson-version>2.11.2</jackson-version>
<spring-version>2.3.4.RELEASE</spring-version>
<javax-annotation-api-version>1.3.2</javax-annotation-api-version>
<jaxb-version>2.3.1</jaxb-version>
<openapi-generator-version>5.2.0</openapi-generator-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>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</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>${openapi-generator-version}</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>${openapi-generator-version}</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>Vality Gambit 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>