open api work
This commit is contained in:
parent
95cb367016
commit
706405e794
|
@ -20,7 +20,7 @@ public class ComponentsWriter extends BaseWriter {
|
|||
|
||||
public ParameterWriter parameter(String name) {
|
||||
JsonObject po = new JsonObject();
|
||||
ensureMapObject("parameters", name).add(name, po);
|
||||
ensureObject("parameters").add(name, po);
|
||||
return new ParameterWriter(po);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package org.hl7.fhir.r5.openapi;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hl7.fhir.r5.context.IWorkerContext;
|
||||
import org.hl7.fhir.r5.model.CapabilityStatement;
|
||||
|
@ -37,7 +39,7 @@ public class OpenApiGenerator {
|
|||
}
|
||||
|
||||
public void generate(String license, String url) {
|
||||
dest.info().title(source.getTitle()).description(source.getDescription()).license(license, url).version(source.getVersion());
|
||||
dest.info().title(source.present()).description(source.getDescription()).license(license, url).version(source.getVersion());
|
||||
for (ContactDetail cd : source.getContact()) {
|
||||
dest.info().contact(cd.getName(), email(cd.getTelecom()), url(cd.getTelecom()));
|
||||
}
|
||||
|
@ -58,17 +60,28 @@ public class OpenApiGenerator {
|
|||
}
|
||||
|
||||
private void writeBaseParameters(ComponentsWriter components) {
|
||||
components.parameter("summary").name("_summary").in(ParameterLocation.query).description("Requests the server to return a designated subset of the resource").allowEmptyValue().style(ParameterStyle.matrix)
|
||||
components.parameter("rid").name("rid").in(ParameterLocation.path).description("id of the resource (=Resource.id)").required(true).allowEmptyValue(false).style(ParameterStyle.simple)
|
||||
.schema().type(SchemaType.string);
|
||||
|
||||
components.parameter("hid").name("hid").in(ParameterLocation.path).description("id of the history entry (=Resource.meta.versionId)").required(true).allowEmptyValue(false).style(ParameterStyle.simple)
|
||||
.schema().type(SchemaType.string);
|
||||
|
||||
components.parameter("summary").name("_summary").in(ParameterLocation.query).description("Requests the server to return a designated subset of the resource").allowEmptyValue().style(ParameterStyle.form)
|
||||
.schema().type(SchemaType.string).enums("true", "text", "data", "count", "false");
|
||||
|
||||
components.parameter("format").name("_format").in(ParameterLocation.query).description("Specify alternative response formats by their MIME-types (when a client is unable acccess accept: header)").allowEmptyValue().style(ParameterStyle.matrix)
|
||||
components.parameter("format").name("_format").in(ParameterLocation.query).description("Specify alternative response formats by their MIME-types (when a client is unable acccess accept: header)").allowEmptyValue().style(ParameterStyle.form)
|
||||
.schema().type(SchemaType.string).format("mime-type");
|
||||
|
||||
components.parameter("pretty").name("_pretty").in(ParameterLocation.query).description("Ask for a pretty printed response for human convenience").allowEmptyValue().style(ParameterStyle.matrix)
|
||||
components.parameter("pretty").name("_pretty").in(ParameterLocation.query).description("Ask for a pretty printed response for human convenience").allowEmptyValue().style(ParameterStyle.form)
|
||||
.schema().type(SchemaType.bool);
|
||||
|
||||
components.parameter("elements").name("_elements").in(ParameterLocation.query).description("Requests the server to return a collection of elements from the resource").allowEmptyValue().style(ParameterStyle.matrix).explode(false)
|
||||
.schema().type(SchemaType.array).format("string");
|
||||
SchemaWriter p = components.parameter("elements").name("_elements").in(ParameterLocation.query).description("Requests the server to return a collection of elements from the resource").allowEmptyValue().style(ParameterStyle.form).explode(false)
|
||||
.schema();
|
||||
p.type(SchemaType.array).format("string");
|
||||
p.items().format("string");
|
||||
|
||||
components.parameter("count").name("_count").in(ParameterLocation.query).description("The maximum number of search results on a page. The server is not bound to return the number requested, but cannot return more")
|
||||
.schema().type(SchemaType.number);
|
||||
}
|
||||
|
||||
private void generatePaths(CapabilityStatementRestComponent csr) {
|
||||
|
@ -112,15 +125,15 @@ public class OpenApiGenerator {
|
|||
ResponseObjectWriter resp = op.responses().httpResponse("200");
|
||||
resp.description("the capbility statement");
|
||||
if (isJson())
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/CapabilityStatement");
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/CapabilityStatement");
|
||||
if (isXml())
|
||||
resp.content("application/fhir+xml").schemaRef(specRef()+"/CapabilityStatement.xsd");
|
||||
|
||||
// parameters - but do they apply?
|
||||
op.paramRef("#/Components/parameters/format");
|
||||
op.paramRef("#/Components/parameters/pretty");
|
||||
op.paramRef("#/Components/parameters/summary");
|
||||
op.paramRef("#/Components/parameters/elements");
|
||||
op.paramRef("#/components/parameters/format");
|
||||
op.paramRef("#/components/parameters/pretty");
|
||||
op.paramRef("#/components/parameters/summary");
|
||||
op.paramRef("#/components/parameters/elements");
|
||||
}
|
||||
|
||||
private void generateRead(CapabilityStatementRestResourceComponent r) {
|
||||
|
@ -131,17 +144,18 @@ public class OpenApiGenerator {
|
|||
ResponseObjectWriter resp = op.responses().httpResponse("200");
|
||||
resp.description("the resource being returned");
|
||||
if (r.getVersioning() != ResourceVersionPolicy.NOVERSION)
|
||||
resp.header("ETag").description("Version from Resource.meta.version as a weak ETag");
|
||||
resp.header("ETag").description("Version from Resource.meta.version as a weak ETag").schema().type(SchemaType.string);
|
||||
if (isJson())
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/"+r.getType());
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/"+r.getType());
|
||||
if (isXml())
|
||||
resp.content("application/fhir+xml").schemaRef(specRef()+"/"+r.getType()+".xsd");
|
||||
|
||||
// parameters:
|
||||
op.paramRef("#/Components/parameters/summary");
|
||||
op.paramRef("#/Components/parameters/format");
|
||||
op.paramRef("#/Components/parameters/pretty");
|
||||
op.paramRef("#/Components/parameters/elements");
|
||||
op.paramRef("#/components/parameters/rid");
|
||||
op.paramRef("#/components/parameters/summary");
|
||||
op.paramRef("#/components/parameters/format");
|
||||
op.paramRef("#/components/parameters/pretty");
|
||||
op.paramRef("#/components/parameters/elements");
|
||||
}
|
||||
|
||||
private void generateSearch(CapabilityStatementRestResourceComponent r) {
|
||||
|
@ -152,22 +166,26 @@ public class OpenApiGenerator {
|
|||
ResponseObjectWriter resp = op.responses().httpResponse("200");
|
||||
resp.description("the resource being returned");
|
||||
if (isJson())
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/Bundle");
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/Bundle");
|
||||
if (isXml())
|
||||
resp.content("application/fhir+xml").schemaRef(specRef()+"/Bundle.xsd");
|
||||
// todo: how do we know that these apply?
|
||||
op.paramRef("#/Components/parameters/format");
|
||||
op.paramRef("#/Components/parameters/pretty");
|
||||
op.paramRef("#/Components/parameters/summary");
|
||||
op.paramRef("#/Components/parameters/elements");
|
||||
op.paramRef("#/components/parameters/format");
|
||||
op.paramRef("#/components/parameters/pretty");
|
||||
op.paramRef("#/components/parameters/summary");
|
||||
op.paramRef("#/components/parameters/elements");
|
||||
Set<String> set = new HashSet<>();
|
||||
for (CapabilityStatementRestResourceSearchParamComponent spc : r.getSearchParam()) {
|
||||
ParameterWriter p = op.parameter(spc.getName());
|
||||
p.in(ParameterLocation.query).description(spc.getDocumentation());
|
||||
p.schema().type(getSchemaType(spc.getType()));
|
||||
if (spc.hasDefinition()) {
|
||||
SearchParameter sp = context.fetchResource(SearchParameter.class, spc.getDefinition());
|
||||
if (sp != null) {
|
||||
p.description(sp.getDescription());
|
||||
if (!set.contains(spc.getName())) {
|
||||
set.add(spc.getName());
|
||||
ParameterWriter p = op.parameter(spc.getName());
|
||||
p.in(ParameterLocation.query).description(spc.getDocumentation());
|
||||
p.schema().type(getSchemaType(spc.getType()));
|
||||
if (spc.hasDefinition()) {
|
||||
SearchParameter sp = context.fetchResource(SearchParameter.class, spc.getDefinition());
|
||||
if (sp != null) {
|
||||
p.description(sp.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -181,22 +199,30 @@ public class OpenApiGenerator {
|
|||
ResponseObjectWriter resp = op.responses().httpResponse("200");
|
||||
resp.description("the resource being returned");
|
||||
if (isJson())
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/Bundle");
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/Bundle");
|
||||
if (isXml())
|
||||
resp.content("application/fhir+xml").schemaRef(specRef()+"/Bundle.xsd");
|
||||
// todo: how do we know that these apply?
|
||||
op.paramRef("#/Components/parameters/format");
|
||||
op.paramRef("#/Components/parameters/pretty");
|
||||
op.paramRef("#/Components/parameters/summary");
|
||||
op.paramRef("#/Components/parameters/elements");
|
||||
op.paramRef("#/components/parameters/format");
|
||||
op.paramRef("#/components/parameters/pretty");
|
||||
op.paramRef("#/components/parameters/summary");
|
||||
op.paramRef("#/components/parameters/elements");
|
||||
Set<String> set = new HashSet<>();
|
||||
set.add("_summary");
|
||||
set.add("_format");
|
||||
set.add("_pretty");
|
||||
set.add("_elements");
|
||||
for (CapabilityStatementRestResourceSearchParamComponent spc : csr.getSearchParam()) {
|
||||
ParameterWriter p = op.parameter(spc.getName());
|
||||
p.in(ParameterLocation.query).description(spc.getDocumentation());
|
||||
p.schema().type(getSchemaType(spc.getType()));
|
||||
if (spc.hasDefinition()) {
|
||||
SearchParameter sp = context.fetchResource(SearchParameter.class, spc.getDefinition());
|
||||
if (sp != null) {
|
||||
p.description(sp.getDescription());
|
||||
if (!set.contains(spc.getName())) {
|
||||
set.add(spc.getName());
|
||||
ParameterWriter p = op.parameter(spc.getName());
|
||||
p.in(ParameterLocation.query).description(spc.getDocumentation());
|
||||
p.schema().type(getSchemaType(spc.getType()));
|
||||
if (spc.hasDefinition()) {
|
||||
SearchParameter sp = context.fetchResource(SearchParameter.class, spc.getDefinition());
|
||||
if (sp != null) {
|
||||
p.description(sp.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -219,20 +245,20 @@ public class OpenApiGenerator {
|
|||
private void generateHistoryType(CapabilityStatementRestResourceComponent r) {
|
||||
OperationWriter op = makePathResHistListType(r).operation("get");
|
||||
op.summary("Read the past states of the resource");
|
||||
op.operationId("histinst"+r.getType());
|
||||
op.operationId("histtype"+r.getType());
|
||||
opOutcome(op.responses().defaultResponse());
|
||||
ResponseObjectWriter resp = op.responses().httpResponse("200");
|
||||
resp.description("the resources being returned");
|
||||
if (isJson())
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/Bundle");
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/Bundle");
|
||||
if (isXml())
|
||||
resp.content("application/fhir+xml").schemaRef(specRef()+"/Bundle.xsd");
|
||||
op.paramRef("#/Components/parameters/summary");
|
||||
op.paramRef("#/Components/parameters/format");
|
||||
op.paramRef("#/Components/parameters/pretty");
|
||||
op.paramRef("#/Components/parameters/elements");
|
||||
op.paramRef("#/components/parameters/summary");
|
||||
op.paramRef("#/components/parameters/format");
|
||||
op.paramRef("#/components/parameters/pretty");
|
||||
op.paramRef("#/components/parameters/elements");
|
||||
op.paramRef("#/components/parameters/count");
|
||||
|
||||
op.parameter("_count").in(ParameterLocation.query).description("The maximum number of search results on a page. The server is not bound to return the number requested, but cannot return more").schema().type(SchemaType.number);
|
||||
op.parameter("_since").in(ParameterLocation.query).description("Only include resource versions that were created at or after the given instant in time").schema().type(SchemaType.dateTime);
|
||||
op.parameter("_at").in(ParameterLocation.query).description("Only include resource versions that were current at some point during the time period specified in the date time value (see Search notes on date searching)").schema().type(SchemaType.dateTime);
|
||||
op.parameter("_list").in(ParameterLocation.query).description("Only include resource versions that are referenced in the specified list (current list references are allowed)").schema().type(SchemaType.string);
|
||||
|
@ -246,15 +272,16 @@ public class OpenApiGenerator {
|
|||
ResponseObjectWriter resp = op.responses().httpResponse("200");
|
||||
resp.description("the resources being returned");
|
||||
if (isJson())
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/Bundle");
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/Bundle");
|
||||
if (isXml())
|
||||
resp.content("application/fhir+xml").schemaRef(specRef()+"/Bundle.xsd");
|
||||
op.paramRef("#/Components/parameters/summary");
|
||||
op.paramRef("#/Components/parameters/format");
|
||||
op.paramRef("#/Components/parameters/pretty");
|
||||
op.paramRef("#/Components/parameters/elements");
|
||||
op.paramRef("#/components/parameters/rid");
|
||||
op.paramRef("#/components/parameters/summary");
|
||||
op.paramRef("#/components/parameters/format");
|
||||
op.paramRef("#/components/parameters/pretty");
|
||||
op.paramRef("#/components/parameters/elements");
|
||||
op.paramRef("#/components/parameters/count");
|
||||
|
||||
op.parameter("_count").in(ParameterLocation.query).description("The maximum number of search results on a page. The server is not bound to return the number requested, but cannot return more").schema().type(SchemaType.number);
|
||||
op.parameter("_since").in(ParameterLocation.query).description("Only include resource versions that were created at or after the given instant in time").schema().type(SchemaType.dateTime);
|
||||
op.parameter("_at").in(ParameterLocation.query).description("Only include resource versions that were current at some point during the time period specified in the date time value (see Search notes on date searching)").schema().type(SchemaType.dateTime);
|
||||
op.parameter("_list").in(ParameterLocation.query).description("Only include resource versions that are referenced in the specified list (current list references are allowed)").schema().type(SchemaType.string);
|
||||
|
@ -263,20 +290,20 @@ public class OpenApiGenerator {
|
|||
private void generateHistorySystem(CapabilityStatementRestComponent csr) {
|
||||
OperationWriter op = makePathHistListSystem().operation("get");
|
||||
op.summary("Read the past states of all resources");
|
||||
op.operationId("histinstAll");
|
||||
op.operationId("histAll");
|
||||
opOutcome(op.responses().defaultResponse());
|
||||
ResponseObjectWriter resp = op.responses().httpResponse("200");
|
||||
resp.description("the resources being returned");
|
||||
if (isJson())
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/Bundle");
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/Bundle");
|
||||
if (isXml())
|
||||
resp.content("application/fhir+xml").schemaRef(specRef()+"/Bundle.xsd");
|
||||
op.paramRef("#/Components/parameters/summary");
|
||||
op.paramRef("#/Components/parameters/format");
|
||||
op.paramRef("#/Components/parameters/pretty");
|
||||
op.paramRef("#/Components/parameters/elements");
|
||||
op.paramRef("#/components/parameters/summary");
|
||||
op.paramRef("#/components/parameters/format");
|
||||
op.paramRef("#/components/parameters/pretty");
|
||||
op.paramRef("#/components/parameters/elements");
|
||||
op.paramRef("#/components/parameters/count");
|
||||
|
||||
op.parameter("_count").in(ParameterLocation.query).description("The maximum number of search results on a page. The server is not bound to return the number requested, but cannot return more").schema().type(SchemaType.number);
|
||||
op.parameter("_since").in(ParameterLocation.query).description("Only include resource versions that were created at or after the given instant in time").schema().type(SchemaType.dateTime);
|
||||
op.parameter("_at").in(ParameterLocation.query).description("Only include resource versions that were current at some point during the time period specified in the date time value (see Search notes on date searching)").schema().type(SchemaType.dateTime);
|
||||
op.parameter("_list").in(ParameterLocation.query).description("Only include resource versions that are referenced in the specified list (current list references are allowed)").schema().type(SchemaType.string);
|
||||
|
@ -290,15 +317,17 @@ public class OpenApiGenerator {
|
|||
ResponseObjectWriter resp = op.responses().httpResponse("200");
|
||||
resp.description("the resource being returned");
|
||||
if (r.getVersioning() != ResourceVersionPolicy.NOVERSION)
|
||||
resp.header("ETag").description("Version from Resource.meta.version as a weak ETag for that version");
|
||||
resp.header("ETag").description("Version from Resource.meta.version as a weak ETag for that version").schema().type(SchemaType.string);
|
||||
if (isJson())
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/"+r.getType());
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/"+r.getType());
|
||||
if (isXml())
|
||||
resp.content("application/fhir+xml").schemaRef(specRef()+"/"+r.getType()+".xsd");
|
||||
op.paramRef("#/Components/parameters/summary");
|
||||
op.paramRef("#/Components/parameters/format");
|
||||
op.paramRef("#/Components/parameters/pretty");
|
||||
op.paramRef("#/Components/parameters/elements");
|
||||
op.paramRef("#/components/parameters/rid");
|
||||
op.paramRef("#/components/parameters/hid");
|
||||
op.paramRef("#/components/parameters/summary");
|
||||
op.paramRef("#/components/parameters/format");
|
||||
op.paramRef("#/components/parameters/pretty");
|
||||
op.paramRef("#/components/parameters/elements");
|
||||
}
|
||||
|
||||
// todo: how does prefer header affect return type?
|
||||
|
@ -312,7 +341,7 @@ public class OpenApiGenerator {
|
|||
RequestBodyWriter req = op.request();
|
||||
req.description("The new state of the resource").required(true);
|
||||
if (isJson())
|
||||
req.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/"+r.getType());
|
||||
req.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/"+r.getType());
|
||||
if (isXml())
|
||||
req.content("application/fhir+xml").schemaRef(specRef()+"/"+r.getType()+".xsd");
|
||||
|
||||
|
@ -320,15 +349,16 @@ public class OpenApiGenerator {
|
|||
ResponseObjectWriter resp = op.responses().httpResponse("200");
|
||||
resp.description("the resource being returned after being updated");
|
||||
if (r.getVersioning() != ResourceVersionPolicy.NOVERSION)
|
||||
resp.header("ETag").description("Version from Resource.meta.version as a weak ETag");
|
||||
resp.header("ETag").description("Version from Resource.meta.version as a weak ETag").schema().type(SchemaType.string);
|
||||
if (isJson())
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/"+r.getType());
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/"+r.getType());
|
||||
if (isXml())
|
||||
resp.content("application/fhir+xml").schemaRef(specRef()+"/"+r.getType()+".xsd");
|
||||
op.paramRef("#/Components/parameters/summary");
|
||||
op.paramRef("#/Components/parameters/format");
|
||||
op.paramRef("#/Components/parameters/pretty");
|
||||
op.paramRef("#/Components/parameters/elements");
|
||||
op.paramRef("#/components/parameters/rid");
|
||||
op.paramRef("#/components/parameters/summary");
|
||||
op.paramRef("#/components/parameters/format");
|
||||
op.paramRef("#/components/parameters/pretty");
|
||||
op.paramRef("#/components/parameters/elements");
|
||||
}
|
||||
|
||||
private void generatePatch(CapabilityStatementRestResourceComponent r) {
|
||||
|
@ -338,8 +368,8 @@ public class OpenApiGenerator {
|
|||
RequestBodyWriter req = op.request();
|
||||
req.description("The new state of the resource").required(true);
|
||||
if (isJson()) {
|
||||
req.content("application/json-patch+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/"+r.getType());
|
||||
req.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/Parameters");
|
||||
req.content("application/json-patch+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/"+r.getType());
|
||||
req.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/Parameters");
|
||||
}
|
||||
if (isXml()) {
|
||||
req.content("application/xml-patch+xml").schemaRef(specRef()+"/"+r.getType()+".xsd");
|
||||
|
@ -350,15 +380,16 @@ public class OpenApiGenerator {
|
|||
ResponseObjectWriter resp = op.responses().httpResponse("200");
|
||||
resp.description("the resource being returned after being patched");
|
||||
if (r.getVersioning() != ResourceVersionPolicy.NOVERSION)
|
||||
resp.header("ETag").description("Version from Resource.meta.version as a weak ETag");
|
||||
resp.header("ETag").description("Version from Resource.meta.version as a weak ETag").schema().type(SchemaType.string);
|
||||
if (isJson())
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/"+r.getType());
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/"+r.getType());
|
||||
if (isXml())
|
||||
resp.content("application/fhir+xml").schemaRef(specRef()+"/"+r.getType()+".xsd");
|
||||
op.paramRef("#/Components/parameters/summary");
|
||||
op.paramRef("#/Components/parameters/format");
|
||||
op.paramRef("#/Components/parameters/pretty");
|
||||
op.paramRef("#/Components/parameters/elements");
|
||||
op.paramRef("#/components/parameters/rid");
|
||||
op.paramRef("#/components/parameters/summary");
|
||||
op.paramRef("#/components/parameters/format");
|
||||
op.paramRef("#/components/parameters/pretty");
|
||||
op.paramRef("#/components/parameters/elements");
|
||||
}
|
||||
|
||||
private void generateDelete(CapabilityStatementRestResourceComponent r) {
|
||||
|
@ -369,7 +400,8 @@ public class OpenApiGenerator {
|
|||
ResponseObjectWriter resp = op.responses().httpResponse("204");
|
||||
resp.description("If the resource is deleted - no content is returned");
|
||||
if (r.getVersioning() != ResourceVersionPolicy.NOVERSION)
|
||||
resp.header("ETag").description("Version from Resource.meta.version as a weak ETag");
|
||||
resp.header("ETag").description("Version from Resource.meta.version as a weak ETag").schema().type(SchemaType.string);
|
||||
op.paramRef("#/components/parameters/rid");
|
||||
}
|
||||
|
||||
private void generateCreate(CapabilityStatementRestResourceComponent r) {
|
||||
|
@ -379,7 +411,7 @@ public class OpenApiGenerator {
|
|||
RequestBodyWriter req = op.request();
|
||||
req.description("The new state of the resource").required(true);
|
||||
if (isJson())
|
||||
req.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/"+r.getType());
|
||||
req.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/"+r.getType());
|
||||
if (isXml())
|
||||
req.content("application/fhir+xml").schemaRef(specRef()+"/"+r.getType()+".xsd");
|
||||
|
||||
|
@ -387,15 +419,15 @@ public class OpenApiGenerator {
|
|||
ResponseObjectWriter resp = op.responses().httpResponse("200");
|
||||
resp.description("the resource being returned after being updated");
|
||||
if (r.getVersioning() != ResourceVersionPolicy.NOVERSION)
|
||||
resp.header("ETag").description("Version from Resource.meta.version as a weak ETag");
|
||||
resp.header("ETag").description("Version from Resource.meta.version as a weak ETag").schema().type(SchemaType.string);
|
||||
if (isJson())
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/"+r.getType());
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/"+r.getType());
|
||||
if (isXml())
|
||||
resp.content("application/fhir+xml").schemaRef(specRef()+"/"+r.getType()+".xsd");
|
||||
op.paramRef("#/Components/parameters/summary");
|
||||
op.paramRef("#/Components/parameters/format");
|
||||
op.paramRef("#/Components/parameters/pretty");
|
||||
op.paramRef("#/Components/parameters/elements");
|
||||
op.paramRef("#/components/parameters/summary");
|
||||
op.paramRef("#/components/parameters/format");
|
||||
op.paramRef("#/components/parameters/pretty");
|
||||
op.paramRef("#/components/parameters/elements");
|
||||
}
|
||||
|
||||
private void generateBatchTransaction(CapabilityStatementRestComponent csr) {
|
||||
|
@ -405,7 +437,7 @@ public class OpenApiGenerator {
|
|||
RequestBodyWriter req = op.request();
|
||||
req.description("The batch or transaction").required(true);
|
||||
if (isJson())
|
||||
req.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/Bundle");
|
||||
req.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/Bundle");
|
||||
if (isXml())
|
||||
req.content("application/fhir+xml").schemaRef(specRef()+"/Bundle.xsd");
|
||||
|
||||
|
@ -413,24 +445,24 @@ public class OpenApiGenerator {
|
|||
ResponseObjectWriter resp = op.responses().httpResponse("200");
|
||||
resp.description("Batch or Transaction response");
|
||||
if (isJson())
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/Bundle");
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/Bundle");
|
||||
if (isXml())
|
||||
resp.content("application/fhir+xml").schemaRef(specRef()+"/Bundle.xsd");
|
||||
op.paramRef("#/Components/parameters/format");
|
||||
op.paramRef("#/Components/parameters/pretty");
|
||||
op.paramRef("#/components/parameters/format");
|
||||
op.paramRef("#/components/parameters/pretty");
|
||||
}
|
||||
|
||||
private void opOutcome(ResponseObjectWriter resp) {
|
||||
resp.description("Error, with details");
|
||||
if (isJson())
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.json.schema#/definitions/OperationOutcome");
|
||||
resp.content("application/fhir+json").schemaRef(specRef()+"/fhir.schema.json#/definitions/OperationOutcome");
|
||||
if (isXml())
|
||||
resp.content("application/fhir+xml").schemaRef(specRef()+"/OperationOutcome.xsd");
|
||||
}
|
||||
|
||||
private String specRef() {
|
||||
// todo: figure out which version we are running against
|
||||
return "http://hl7.org/fhir/STU3";
|
||||
return "https://hl7.org/fhir/STU3";
|
||||
}
|
||||
|
||||
private boolean isJson() {
|
||||
|
|
|
@ -18,7 +18,7 @@ public class SchemaWriter extends BaseWriter {
|
|||
switch (this) {
|
||||
case array: return "array";
|
||||
case bool: return "boolean";
|
||||
case dateTime: return "dateTime";
|
||||
case dateTime: return "date-time";
|
||||
case number: return "number";
|
||||
case string: return "string";
|
||||
}
|
||||
|
@ -31,11 +31,23 @@ public class SchemaWriter extends BaseWriter {
|
|||
}
|
||||
|
||||
public SchemaWriter type(SchemaType value) {
|
||||
if (value != null)
|
||||
object.addProperty("type", value.toCode());
|
||||
if (value != null) {
|
||||
if (value == SchemaType.dateTime) {
|
||||
object.addProperty("type", "string");
|
||||
object.addProperty("pattern", "([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\\.[0-9]+)?(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)))?)?)?");
|
||||
|
||||
} else
|
||||
object.addProperty("type", value.toCode());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SchemaWriter items() {
|
||||
JsonObject items = new JsonObject();
|
||||
object.add("items", items);
|
||||
return new SchemaWriter(items);
|
||||
}
|
||||
|
||||
public SchemaWriter enums(String... values) {
|
||||
JsonArray arr = forceArray("enum");
|
||||
for (String s : values)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"openapi": "3.0.2",
|
||||
"info": {
|
||||
"title": "Base FHIR Capability Statement (Empty)",
|
||||
"description": "This is the base Capability Statement for FHIR. It represents a server that provides the none of the functionality defined by FHIR. It is provided to use as a template for system designers to build their own Capability Statements from. A capability statement has to contain something, so this contains a read of a Capability Statement",
|
||||
"license": {
|
||||
"name": "test-lic",
|
||||
|
@ -28,12 +29,12 @@
|
|||
"content": {
|
||||
"application/fhir+json": {
|
||||
"schema": {
|
||||
"$ref": "http://hl7.org/fhir/STU3/fhir.json.schema#/definitions/OperationOutcome"
|
||||
"$ref": "https://hl7.org/fhir/STU3/fhir.schema.json#/definitions/OperationOutcome"
|
||||
}
|
||||
},
|
||||
"application/fhir+xml": {
|
||||
"schema": {
|
||||
"$ref": "http://hl7.org/fhir/STU3/OperationOutcome.xsd"
|
||||
"$ref": "https://hl7.org/fhir/STU3/OperationOutcome.xsd"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,12 +44,12 @@
|
|||
"content": {
|
||||
"application/fhir+json": {
|
||||
"schema": {
|
||||
"$ref": "http://hl7.org/fhir/STU3/fhir.json.schema#/definitions/CapabilityStatement"
|
||||
"$ref": "https://hl7.org/fhir/STU3/fhir.schema.json#/definitions/CapabilityStatement"
|
||||
}
|
||||
},
|
||||
"application/fhir+xml": {
|
||||
"schema": {
|
||||
"$ref": "http://hl7.org/fhir/STU3/CapabilityStatement.xsd"
|
||||
"$ref": "https://hl7.org/fhir/STU3/CapabilityStatement.xsd"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,16 +57,16 @@
|
|||
},
|
||||
"parameters": [
|
||||
{
|
||||
"$ref": "#/Components/parameters/format"
|
||||
"$ref": "#/components/parameters/format"
|
||||
},
|
||||
{
|
||||
"$ref": "#/Components/parameters/pretty"
|
||||
"$ref": "#/components/parameters/pretty"
|
||||
},
|
||||
{
|
||||
"$ref": "#/Components/parameters/summary"
|
||||
"$ref": "#/components/parameters/summary"
|
||||
},
|
||||
{
|
||||
"$ref": "#/Components/parameters/elements"
|
||||
"$ref": "#/components/parameters/elements"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -73,63 +74,88 @@
|
|||
},
|
||||
"components": {
|
||||
"parameters": {
|
||||
"rid": {
|
||||
"name": "rid",
|
||||
"in": "path",
|
||||
"description": "id of the resource (\u003dResource.id)",
|
||||
"required": true,
|
||||
"allowEmptyValue": false,
|
||||
"style": "simple",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"hid": {
|
||||
"name": "hid",
|
||||
"in": "path",
|
||||
"description": "id of the history entry (\u003dResource.meta.versionId)",
|
||||
"required": true,
|
||||
"allowEmptyValue": false,
|
||||
"style": "simple",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"summary": {
|
||||
"summary": {
|
||||
"name": "_summary",
|
||||
"in": "query",
|
||||
"description": "Requests the server to return a designated subset of the resource",
|
||||
"allowEmptyValue": true,
|
||||
"style": "matrix",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"true",
|
||||
"text",
|
||||
"data",
|
||||
"count",
|
||||
"false"
|
||||
]
|
||||
}
|
||||
"name": "_summary",
|
||||
"in": "query",
|
||||
"description": "Requests the server to return a designated subset of the resource",
|
||||
"allowEmptyValue": true,
|
||||
"style": "form",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"true",
|
||||
"text",
|
||||
"data",
|
||||
"count",
|
||||
"false"
|
||||
]
|
||||
}
|
||||
},
|
||||
"format": {
|
||||
"format": {
|
||||
"name": "_format",
|
||||
"in": "query",
|
||||
"description": "Specify alternative response formats by their MIME-types (when a client is unable acccess accept: header)",
|
||||
"allowEmptyValue": true,
|
||||
"style": "matrix",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"format": "mime-type"
|
||||
}
|
||||
"name": "_format",
|
||||
"in": "query",
|
||||
"description": "Specify alternative response formats by their MIME-types (when a client is unable acccess accept: header)",
|
||||
"allowEmptyValue": true,
|
||||
"style": "form",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"format": "mime-type"
|
||||
}
|
||||
},
|
||||
"pretty": {
|
||||
"pretty": {
|
||||
"name": "_pretty",
|
||||
"in": "query",
|
||||
"description": "Ask for a pretty printed response for human convenience",
|
||||
"allowEmptyValue": true,
|
||||
"style": "matrix",
|
||||
"schema": {
|
||||
"type": "boolean"
|
||||
}
|
||||
"name": "_pretty",
|
||||
"in": "query",
|
||||
"description": "Ask for a pretty printed response for human convenience",
|
||||
"allowEmptyValue": true,
|
||||
"style": "form",
|
||||
"schema": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"elements": {
|
||||
"elements": {
|
||||
"name": "_elements",
|
||||
"in": "query",
|
||||
"description": "Requests the server to return a collection of elements from the resource",
|
||||
"allowEmptyValue": true,
|
||||
"style": "matrix",
|
||||
"explode": false,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"name": "_elements",
|
||||
"in": "query",
|
||||
"description": "Requests the server to return a collection of elements from the resource",
|
||||
"allowEmptyValue": true,
|
||||
"style": "form",
|
||||
"explode": false,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"format": "string",
|
||||
"items": {
|
||||
"format": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"count": {
|
||||
"name": "_count",
|
||||
"in": "query",
|
||||
"description": "The maximum number of search results on a page. The server is not bound to return the number requested, but cannot return more",
|
||||
"schema": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue