From 2b18120c0b5ba218924a30cb5fa0f8d255a7322c Mon Sep 17 00:00:00 2001 From: Armin Friedl Date: Wed, 1 Jul 2020 22:58:56 +0200 Subject: [PATCH] Try client generator --- .drone.yml | 14 +++- LICENSE | 9 +++ container/etc/nginx/conf.d/fling.conf | 34 +++++++++ .../controller/OpenApiConfiguration.java | 71 +++++++++++++++++++ 4 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 LICENSE create mode 100644 service/fling/src/main/java/net/friedl/fling/controller/OpenApiConfiguration.java diff --git a/.drone.yml b/.drone.yml index 66bf451..4be0d9c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -47,9 +47,17 @@ steps: context: ./container repo: arminfriedl/fling tags: dev - when: - branch: - - master + +- name: runservice + image: arminfriedl/fling:dev + pull: always + detach: true + +- name: generate-clients + image: openapitools/openapi-generator-cli + commands: + - sleep 35 + - java -jar /opt/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i http://runservice:3000/v3/api-docs -g python -o flingclient volumes: - name: m2-cache diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e53cba0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright © 2020 Armin Friedl + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/container/etc/nginx/conf.d/fling.conf b/container/etc/nginx/conf.d/fling.conf index 3651c7b..ffa2005 100644 --- a/container/etc/nginx/conf.d/fling.conf +++ b/container/etc/nginx/conf.d/fling.conf @@ -27,6 +27,40 @@ server { client_max_body_size 5G; } + # handle openapi requests by openapi servlet + location /v3/api-docs { + proxy_pass http://localhost:8080; + + proxy_set_header X-Forwarded-Host $host:$server_port; + proxy_set_header X-Forwarded-Server $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Proto $scheme; + + # Required for web sockets to function + proxy_http_version 1.1; + proxy_buffering off; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } + + # handle openapi requests by openapi servlet + location /swagger-ui.html { + proxy_pass http://localhost:8080; + + proxy_set_header X-Forwarded-Host $host:$server_port; + proxy_set_header X-Forwarded-Server $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Proto $scheme; + + # Required for web sockets to function + proxy_http_version 1.1; + proxy_buffering off; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } + # always respond with index.html for unknown paths # (routing is client side) location / { diff --git a/service/fling/src/main/java/net/friedl/fling/controller/OpenApiConfiguration.java b/service/fling/src/main/java/net/friedl/fling/controller/OpenApiConfiguration.java new file mode 100644 index 0000000..8bf33c9 --- /dev/null +++ b/service/fling/src/main/java/net/friedl/fling/controller/OpenApiConfiguration.java @@ -0,0 +1,71 @@ +package net.friedl.fling.controller; + +import java.util.Optional; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.security.SecurityScheme; +import io.swagger.v3.oas.models.security.SecurityScheme.Type; +import io.swagger.v3.oas.models.servers.Server; +import lombok.Data; + +@Data +@Configuration +@ConfigurationProperties("fling.api") +public class OpenApiConfiguration { + + private String version; + private String serverUrl; + private String serverDescription; + + @Bean + public OpenAPI openApi() { + OpenAPI openApi = new OpenAPI() + .components(new Components() + .addSecuritySchemes("bearer", bearerScheme()) + .addSchemas("resource", new Schema() + .type("string").format("binary"))) + .info(apiInfo()); + + serverItem().ifPresent(openApi::addServersItem); + + return openApi; + } + + public SecurityScheme bearerScheme() { + return new SecurityScheme() + .name("bearerAuth") + .type(Type.HTTP) + .scheme("bearer") + .bearerFormat("JWT"); + } + + public Info apiInfo() { + return new Info() + .contact(new Contact() + .name("Armin Friedl") + .url("https://www.friedl.net") + .email("dev@friedl.net")) + .license(new License() + .name("The MIT License (MIT)")) + .title("The Fling API") + .description("Share file collections with expiration, protection and short urls") + .version(version); + } + + public Optional serverItem() { + if (serverUrl == null) return Optional.empty(); + + return Optional.of( + new Server() + .description(serverDescription) + .url(serverUrl)); + } +} \ No newline at end of file