Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true

[*.properties]
trim_trailing_whitespace = false

[pom.xml]
indent_style = unset
13 changes: 9 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
default_stages: [pre-commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v6.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
rev: v1.5.5
hooks:
- id: remove-crlf
- id: remove-tabs
args: [ --whitespaces-count=2 ]
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: 2.7.3
rev: 3.4.0
hooks:
- id: editorconfig-checker
- repo: https://github.com/extenda/pre-commit-hooks
rev: v0.11.0
rev: v0.14.0
hooks:
- id: google-java-formatter
- id: commitlint
stages: [commit-msg]
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.37.1
hooks:
- id: yamllint
args: [ --strict, -c=.yamllint ]
17 changes: 17 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extends: relaxed
rules:
colons:
max-spaces-before: 0
max-spaces-after: -1
indentation:
spaces: 2
indent-sequences: true
check-multi-line-strings: false
line-length:
max: 150
allow-non-breakable-words: true
level: error
new-line-at-end-of-file: enable
new-lines:
type: unix
trailing-spaces: {}
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@
</dependencyManagement>

<dependencies>

<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;

public class SpecificationLoader {

Expand All @@ -29,10 +30,17 @@ public static byte[] load(String spec) {
* @return The openapi model
*/
public static OpenApi parseSpecification(
String specificationPath, Function<String, OpenApi> mapper) {
String specificationPath, Function<String, OpenApi> mapper, Function<Object, String> toJson) {
long t0 = System.currentTimeMillis();
byte[] data = load(specificationPath);
String openapiAsText = new String(data, StandardCharsets.UTF_8);

if (specificationPath.endsWith(".yaml") || specificationPath.endsWith(".yml")) {
var yaml = new Yaml();
Object yamlObj = yaml.load(openapiAsText);
openapiAsText = toJson.apply(yamlObj);
}

OpenApi spec = OpenApi.parse(mapper, openapiAsText);

LOG.debug(
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/retailsvc/http/ServerBaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public abstract class ServerBaseTest {

@BeforeEach
void setUp() {
specification = parseSpecification("openapi.json", s -> gson.fromJson(s, OpenApi.class));
specification = parseSpecification("openapi.json", s -> gson.fromJson(s, OpenApi.class), null);
}

@AfterEach
Expand Down
11 changes: 8 additions & 3 deletions src/test/java/com/retailsvc/http/start/ServerLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.retailsvc.http.openapi.SpecificationLoader.parseSpecification;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.retailsvc.http.ExceptionHandler;
import com.retailsvc.http.Handlers;
import com.retailsvc.http.OpenApiServer;
Expand All @@ -13,23 +14,27 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ServerLauncher {

private static final Logger LOG = LoggerFactory.getLogger(ServerLauncher.class);

public static void main(String[] args) throws Exception {
static void main() throws Exception {
new ServerLauncher();
}

public ServerLauncher() throws IOException {
long t0 = System.currentTimeMillis();

final Gson gson = new Gson();
final Gson gson = new GsonBuilder().setPrettyPrinting().create();

var specification = parseSpecification("openapi.json", s -> gson.fromJson(s, OpenApi.class));
Function<String, OpenApi> jsonToSpec = contents -> gson.fromJson(contents, OpenApi.class);
Function<Object, String> toJson = gson::toJson;

var specification = parseSpecification("openapi.yaml", jsonToSpec, toJson);

Map<String, HttpHandler> handlers = new HashMap<>();
handlers.put("get-data", new GetDataHandler());
Expand Down
10 changes: 10 additions & 0 deletions src/test/resources/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@
}
}
}
},
"/anyOf": {
"post": {

}
},
"/allOf": {
"post": {

}
}
},
"components": {
Expand Down
Loading
Loading