Skip to content

Commit d0118a2

Browse files
lmsurpreJohnTimm
authored andcommitted
SwaggerGenerator Updates (#433)
* introduce FHIRSwaggersGenerator for generating one-swagger-per-resource Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com> * Package edits for generating one swagger per resource type TODO: do the same for FHIROpenApiGenerator and try out the OpenAPI files in liberty. Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com> * fixed an issue with the swagger definition for Integer Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com> * Generate inline primitive types In the previous version, we generated a definition for each FHIR primitive type. This correctly captured the fact that these can have an id and/or extensions (inhereted from Element) but would lead to the wrong JSON since these elements need to get serialized differently in JSON. Technically, we should introduce a `_fieldname` variant for each instance of a primitive type, but primitive extensions are not common and it adds significant complexity to the swagger. Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
1 parent b8056c7 commit d0118a2

3 files changed

Lines changed: 336 additions & 96 deletions

File tree

fhir-swagger-generator/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@
4545
</formatFileSets>
4646
</configuration>
4747
</plugin>
48+
<plugin>
49+
<groupId>org.apache.maven.plugins</groupId>
50+
<artifactId>maven-jar-plugin</artifactId>
51+
<configuration>
52+
<archive>
53+
<manifest>
54+
<addClasspath>true</addClasspath>
55+
<mainClass>com.ibm.fhir.swagger.generator.FHIRSwaggerGenerator</mainClass>
56+
</manifest>
57+
</archive>
58+
</configuration>
59+
</plugin>
4860
</plugins>
4961
</build>
5062

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.ibm.fhir.swagger.generator;
2+
/*
3+
* (C) Copyright IBM Corp. 2019
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
import javax.json.Json;
9+
import javax.json.JsonArrayBuilder;
10+
import javax.json.JsonBuilderFactory;
11+
import javax.json.JsonObjectBuilder;
12+
13+
/**
14+
*
15+
*/
16+
public class APIConnectAdapter {
17+
18+
/**
19+
* Set this to the hostname of your FHIR Server and the generated assembly will proxy this
20+
*/
21+
private static final String HOST = "localhost";
22+
23+
private static final JsonBuilderFactory factory = Json.createBuilderFactory(null);
24+
25+
static void addApiConnectStuff(JsonObjectBuilder swagger) {
26+
JsonObjectBuilder ibmConfig = factory.createObjectBuilder()
27+
.add("gateway", "datapower-api-gateway")
28+
.add("type", "rest")
29+
.add("phase", "realized")
30+
.add("enforced", true)
31+
.add("testable", true)
32+
.add("cors", factory.createObjectBuilder().add("enabled", true))
33+
.add("assembly", buildAssembly())
34+
.add("properties", buildProperties())
35+
.add("activity-log", factory.createObjectBuilder()
36+
.add("enabled", true)
37+
.add("error-content", "header")
38+
.add("success-content", "activity"))
39+
.add("application-authentication", factory.createObjectBuilder()
40+
.add("certificate", false))
41+
.add("catalogs", factory.createObjectBuilder());
42+
swagger.add("x-ibm-configuration", ibmConfig);
43+
}
44+
45+
private static JsonObjectBuilder buildAssembly() {
46+
JsonObjectBuilder executeInvoke = factory.createObjectBuilder().add("invoke", buildExecuteInvoke());
47+
48+
JsonArrayBuilder execute = factory.createArrayBuilder().add(executeInvoke);
49+
50+
return factory.createObjectBuilder()
51+
.add("execute", execute)
52+
.add("catch", factory.createArrayBuilder());
53+
}
54+
55+
private static JsonObjectBuilder buildExecuteInvoke() {
56+
JsonObjectBuilder headerControl = factory.createObjectBuilder()
57+
.add("type", "blacklist")
58+
.add("values", factory.createArrayBuilder());
59+
JsonObjectBuilder paramControl = factory.createObjectBuilder()
60+
.add("type", "whitelist")
61+
.add("values", factory.createArrayBuilder());
62+
return factory.createObjectBuilder()
63+
.add("version", "2.0.0")
64+
.add("title", "invoke")
65+
.add("header-control", headerControl)
66+
.add("parameter-control",paramControl)
67+
.add("timeout", 60)
68+
.add("verb", "keep")
69+
.add("cache-response", "protocol")
70+
.add("cache-ttl", 900)
71+
.add("stop-on-error", factory.createArrayBuilder())
72+
.add("target-url", "$(target-url)$(api.operation.path)$(request.search)");
73+
}
74+
75+
private static JsonObjectBuilder buildProperties() {
76+
JsonObjectBuilder targetUrl = factory.createObjectBuilder()
77+
.add("value", "https://" + HOST + "/fhir-server/api/v4/")
78+
.add("description", "The URL of the target service")
79+
.add("encoded", false);
80+
81+
return factory.createObjectBuilder().add("target-url", targetUrl);
82+
}
83+
}

0 commit comments

Comments
 (0)