Skip to content

Commit

Permalink
Updated swagger ui.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Mar 5, 2020
1 parent d425ee1 commit c07a4cc
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Proteus Changelog.
## Unreleased
### No issue

**Fix Double conversion and add BigDecimal support.**


[d425ee1da2fa5a7](https://github.com/noboomu/proteus/commit/d425ee1da2fa5a7) Joshua Bauer *2020-02-25 00:54:22*

**Cleanup poms and improve redirect.**


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.sinistral.proteus.server.predicates.ServerPredicates;
import io.sinistral.proteus.wrappers.JsonViewWrapper;
import io.undertow.io.IoCallback;
import io.undertow.server.DefaultResponseListener;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.handlers.Cookie;
Expand Down Expand Up @@ -695,6 +694,7 @@ public static <T> ServerResponse<T> response(Class<T> clazz)
return new ServerResponse<T>();
}


public static ServerResponse<ByteBuffer> response(ByteBuffer body)
{
return new ServerResponse<ByteBuffer>().body(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,6 @@ else if (m.getReturnType().getTypeName().contains("java.util.concurrent.Completi

Annotation securityRequirementAnnotation = Arrays.stream(annotations).filter(a -> a.getClass().getName().contains("SecurityRequirement")).findFirst().orElse(null);

if (securityRequirementAnnotation != null) {

if (securityRequirementAnnotation != null) {

Expand All @@ -803,8 +802,6 @@ else if (m.getReturnType().getTypeName().contains("java.util.concurrent.Completi
log.warn("No name field on security requirement");
}

}

}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.sinistral.proteus.openapi.wrappers;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import io.sinistral.proteus.server.exceptions.ServerException;
import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
import io.undertow.util.AttachmentKey;
import io.undertow.util.HttpString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.core.Response;
import java.util.Optional;

@Singleton
public class HeaderApiKeyWrapper implements HandlerWrapper
{
private static final Logger logger = LoggerFactory.getLogger(HeaderApiKeyWrapper.class.getName());

public static final AttachmentKey<Throwable> THROWABLE = AttachmentKey.create(Throwable.class);

@Inject
@Named("openapi.securitySchemes.ApiKeyAuth.name")
protected static String AUTH_KEY_NAME;

@Inject(optional = true)
@Named("security.apiKey")
protected static String API_KEY;

private final HttpString API_KEY_HEADER;

public HeaderApiKeyWrapper()
{
API_KEY_HEADER = new HttpString(AUTH_KEY_NAME);
}

@Override
public HttpHandler wrap(HttpHandler handler)
{
return exchange -> {

if(API_KEY == null)
{
handler.handleRequest(exchange);
return;
}

Optional<String> keyValue = Optional.ofNullable(exchange.getRequestHeaders().getFirst(API_KEY_HEADER));

if(!keyValue.isPresent() || !keyValue.get().equals(API_KEY))
{

logger.error("Missing security credentials");
exchange.putAttachment(THROWABLE, new ServerException("Unauthorized access", Response.Status.UNAUTHORIZED));
throw new ServerException("Unauthorized access", Response.Status.UNAUTHORIZED);

}

handler.handleRequest(exchange);



};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta charset="UTF-8">
<title>{{ title }}</title>
<link href="https://fonts.googleapis.com/css?family=Inconsolata:400,700|Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.23.11/swagger-ui.css" rel='stylesheet' />
<link href="//unpkg.com/swagger-ui-dist@3/swagger-ui.css" rel='stylesheet' />
<link href="{{ basePath }}/swagger-ui.css" rel='stylesheet' />

<style>
Expand Down Expand Up @@ -76,8 +76,8 @@
<div id="swagger-ui"></div>


<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.23.11/swagger-ui-bundle.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.23.11/swagger-ui-standalone-preset.js"></script>
<script src="//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js"></script>
<script src="//unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js"></script>

<script>

Expand All @@ -88,6 +88,9 @@
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: 'StandaloneLayout',

deepLinking: true,
Expand Down

0 comments on commit c07a4cc

Please sign in to comment.