You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2022/11/22 16:29:00 UTC
[isis] 01/01: ISIS-3292: migrate Swagger Model v2 to OpenAPI v3
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch 3292-openapi
in repository https://gitbox.apache.org/repos/asf/isis.git
commit ee86fe9fffef0f7308d813f76f037d72da666055
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Nov 22 17:28:51 2022 +0100
ISIS-3292: migrate Swagger Model v2 to OpenAPI v3
- yet using some stubs, to fill in details later (TODO markers)
---
bom/pom.xml | 2 +-
core/metamodel/pom.xml | 4 +-
core/pom.xml | 4 +-
.../rendering/src/main/java/module-info.java | 4 +-
.../service/swagger/internal/BodyParameter.java | 9 +
.../service/swagger/internal/Caching.java | 25 +-
.../service/swagger/internal/Generation.java | 516 ++++++++++-----------
.../service/swagger/internal/RefSchema.java | 11 +
.../swagger/internal/SwaggerSpecGenerator.java | 8 +-
.../swagger/internal/ValuePropertyFactory.java | 4 +-
.../internal/ValuePropertyFactoryDefault.java | 89 ++--
.../rendering/service/swagger/internal/_Util.java | 33 +-
.../viewer/resources/SwaggerSpecResource.java | 5 +
13 files changed, 377 insertions(+), 337 deletions(-)
diff --git a/bom/pom.xml b/bom/pom.xml
index 8c8957e9b2..d8068e66d4 100644
--- a/bom/pom.xml
+++ b/bom/pom.xml
@@ -415,7 +415,7 @@ It is therefore a copy of org.apache:apache, with customisations clearly identif
<spring-boot.version>2.7.5</spring-boot.version>
<summernote.version>0.8.20</summernote.version>
<surefire-plugin.argLine>-Xmx384m</surefire-plugin.argLine>
- <swagger-core.version>1.6.9</swagger-core.version>
+ <swagger-core.version>2.2.7</swagger-core.version>
<togglz.version>3.3.2</togglz.version>
diff --git a/core/metamodel/pom.xml b/core/metamodel/pom.xml
index dd56597c3f..812e8baad2 100644
--- a/core/metamodel/pom.xml
+++ b/core/metamodel/pom.xml
@@ -80,8 +80,8 @@
</dependency>
<dependency>
- <groupId>io.swagger</groupId>
- <artifactId>swagger-core</artifactId>
+ <groupId>io.swagger.core.v3</groupId>
+ <artifactId>swagger-core</artifactId>
<exclusions>
<!-- metamodel no longer has a dependency on guava -->
<exclusion>
diff --git a/core/pom.xml b/core/pom.xml
index 6a6a93f861..19fa7b929b 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -851,8 +851,8 @@
</dependency>
<dependency>
- <groupId>io.swagger</groupId>
- <artifactId>swagger-core</artifactId>
+ <groupId>io.swagger.core.v3</groupId>
+ <artifactId>swagger-core</artifactId>
<version>${swagger-core.version}</version>
</dependency>
diff --git a/viewers/restfulobjects/rendering/src/main/java/module-info.java b/viewers/restfulobjects/rendering/src/main/java/module-info.java
index e6a4afd8d3..959a3ef468 100644
--- a/viewers/restfulobjects/rendering/src/main/java/module-info.java
+++ b/viewers/restfulobjects/rendering/src/main/java/module-info.java
@@ -49,6 +49,6 @@ module org.apache.causeway.viewer.restfulobjects.rendering {
requires spring.beans;
requires spring.context;
requires spring.core;
- requires swagger.core;
- requires swagger.models;
+ requires io.swagger.v3.oas.models;
+ requires io.swagger.v3.core;
}
\ No newline at end of file
diff --git a/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/BodyParameter.java b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/BodyParameter.java
new file mode 100644
index 0000000000..59d50466eb
--- /dev/null
+++ b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/BodyParameter.java
@@ -0,0 +1,9 @@
+package org.apache.causeway.viewer.restfulobjects.rendering.service.swagger.internal;
+
+import io.swagger.v3.oas.models.parameters.Parameter;
+
+public class BodyParameter extends Parameter {
+
+ //TODO[ISIS-3292] implement or replace
+
+}
diff --git a/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/Caching.java b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/Caching.java
index ef5f9f6996..05de310157 100644
--- a/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/Caching.java
+++ b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/Caching.java
@@ -18,8 +18,9 @@
*/
package org.apache.causeway.viewer.restfulobjects.rendering.service.swagger.internal;
-import io.swagger.models.Response;
-import io.swagger.models.properties.IntegerProperty;
+import io.swagger.v3.oas.models.headers.Header;
+import io.swagger.v3.oas.models.media.IntegerSchema;
+import io.swagger.v3.oas.models.responses.ApiResponse;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -41,26 +42,26 @@ import io.swagger.models.properties.IntegerProperty;
*/
enum Caching {
TRANSACTIONAL {
- @Override public void withHeaders(final Response response) {
+ @Override public void withHeaders(final ApiResponse response) {
}
},
USER_INFO {
- @Override public void withHeaders(final Response response) {
+ @Override public void withHeaders(final ApiResponse response) {
response
- .header("Cache-Control",
- new IntegerProperty()
- ._default(3600));
+ .addHeaderObject("Cache-Control",
+ new Header().schema(
+ new IntegerSchema()._default(3600)));
}
},
NON_EXPIRING {
- @Override public void withHeaders(final Response response) {
+ @Override public void withHeaders(final ApiResponse response) {
response
- .header("Cache-Control",
- new IntegerProperty()
- ._default(86400).description(_Util.roSpec("2.13")));
+ .addHeaderObject("Cache-Control",
+ new Header().schema(
+ new IntegerSchema()._default(86400).description(_Util.roSpec("2.13"))));
}
};
- public abstract void withHeaders(final Response response);
+ public abstract void withHeaders(final ApiResponse response);
}
diff --git a/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/Generation.java b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/Generation.java
index 2fca0ff7c5..44459bf5ab 100644
--- a/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/Generation.java
+++ b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/Generation.java
@@ -43,21 +43,21 @@ import org.apache.causeway.core.metamodel.spec.feature.OneToOneAssociation;
import org.apache.causeway.core.metamodel.specloader.SpecificationLoader;
import org.apache.causeway.core.metamodel.util.Facets;
-import io.swagger.models.Info;
-import io.swagger.models.ModelImpl;
-import io.swagger.models.Operation;
-import io.swagger.models.Path;
-import io.swagger.models.Response;
-import io.swagger.models.Swagger;
-import io.swagger.models.parameters.BodyParameter;
-import io.swagger.models.parameters.PathParameter;
-import io.swagger.models.parameters.QueryParameter;
-import io.swagger.models.properties.ArrayProperty;
-import io.swagger.models.properties.MapProperty;
-import io.swagger.models.properties.ObjectProperty;
-import io.swagger.models.properties.Property;
-import io.swagger.models.properties.RefProperty;
-import io.swagger.models.properties.StringProperty;
+import io.swagger.v3.oas.models.Components;
+import io.swagger.v3.oas.models.OpenAPI;
+import io.swagger.v3.oas.models.Operation;
+import io.swagger.v3.oas.models.PathItem;
+import io.swagger.v3.oas.models.Paths;
+import io.swagger.v3.oas.models.info.Info;
+import io.swagger.v3.oas.models.media.ArraySchema;
+import io.swagger.v3.oas.models.media.MapSchema;
+import io.swagger.v3.oas.models.media.ObjectSchema;
+import io.swagger.v3.oas.models.media.Schema;
+import io.swagger.v3.oas.models.media.StringSchema;
+import io.swagger.v3.oas.models.parameters.PathParameter;
+import io.swagger.v3.oas.models.parameters.QueryParameter;
+import io.swagger.v3.oas.models.responses.ApiResponse;
+import io.swagger.v3.oas.models.servers.Server;
import lombok.val;
class Generation {
@@ -75,7 +75,7 @@ class Generation {
private final Set<String> references = _Sets.newLinkedHashSet();
private final Set<String> definitions = _Sets.newLinkedHashSet();
- private Swagger swagger;
+ private OpenAPI swagger;
public Generation(
final String basePath,
@@ -92,20 +92,21 @@ class Generation {
this.valuePropertyFactory = valuePropertyFactory;
}
- Swagger generate() {
- this.swagger = new Swagger();
+ OpenAPI generate() {
+ this.swagger = new OpenAPI();
final String swaggerVersionInfo =
String.format("swagger.io (%s)",
- Swagger.class.getPackage().getImplementationVersion()
+ OpenAPI.class.getPackage().getImplementationVersion()
);
- swagger.basePath(basePath);
+ swagger.addServersItem(new Server()
+ .url(basePath));
swagger.info(new Info()
.version(swaggerVersionInfo)
.title(visibility.name() + " API")
);
-
+ swagger.setComponents(new Components());
appendRestfulObjectsSupportingPathsAndDefinitions();
appendLinkModelDefinition();
@@ -120,27 +121,31 @@ class Generation {
return swagger;
}
- private Map<String, Path> sorted(final Map<String, Path> paths) {
+ private Paths sorted(final Map<String, PathItem> paths) {
- final List<Map.Entry<String, Path>> entries = new ArrayList<>(paths.entrySet());
- entries.sort(new Comparator<Map.Entry<String, Path>>() {
+ final List<Map.Entry<String, PathItem>> entries = new ArrayList<>(paths.entrySet());
+ entries.sort(new Comparator<Map.Entry<String, PathItem>>() {
@Override
- public int compare(final Map.Entry<String, Path> o1, final Map.Entry<String, Path> o2) {
+ public int compare(final Map.Entry<String, PathItem> o1, final Map.Entry<String, PathItem> o2) {
final String tag1 = tagFor(o1);
final String tag2 = tagFor(o2);
final int tag = tag1.compareTo(tag2);
return tag != 0 ? tag : o1.getKey().compareTo(o2.getKey());
}
- protected String tagFor(final Map.Entry<String, Path> o1) {
- return o1.getValue().getOperations().stream().findFirst().map(operation -> operation.getTags().stream().findFirst().orElse("(no tag)")).orElse("(no tag)");
+ protected String tagFor(final Map.Entry<String, PathItem> o1) {
+ return o1.getValue().readOperations().stream()
+ .findFirst()
+ .map(operation -> operation.getTags().stream().findFirst().orElse("(no tag)")).orElse("(no tag)");
}
});
- final LinkedHashMap<String, Path> sorted = new LinkedHashMap<>();
+ final LinkedHashMap<String, PathItem> sorted = new LinkedHashMap<>();
entries.forEach(entry -> sorted.put(entry.getKey(), entry.getValue()));
- return sorted;
+ val _paths = new Paths();
+ _paths.putAll(sorted);
+ return _paths;
}
void appendServicePathsAndDefinitions() {
@@ -207,7 +212,7 @@ class Generation {
&& objectCollections.isEmpty()) {
continue;
}
- final ModelImpl causewayModel = appendObjectPathAndModelDefinitions(objectSpec);
+ final Schema causewayModel = appendObjectPathAndModelDefinitions(objectSpec);
updateObjectModel(causewayModel, objectSpec, objectProperties, objectCollections);
for (final OneToManyAssociation objectCollection : objectCollections) {
@@ -225,99 +230,96 @@ class Generation {
final String tag = ". restful objects supporting resources";
swagger.path("/",
- new Path()
- .get(newOperation("home-page")
- .tag(tag)
- .description(_Util.roSpec("5.1"))
- .response(200,
- newResponse(Caching.NON_EXPIRING)
- .description("OK")
- .schema(newRefProperty("RestfulObjectsSupportingHomePageRepr"))
- )));
+ new PathItem()
+ .get(_Util.response(
+ newOperation("home-page")
+ .addTagsItem(tag)
+ .description(_Util.roSpec("5.1")),
+ 200,
+ newResponse(Caching.NON_EXPIRING, newRefProperty("RestfulObjectsSupportingHomePageRepr"))
+ .description("OK"))));
addDefinition("RestfulObjectsSupportingHomePageRepr", newModel(_Util.roSpec("5.2")));
swagger.path("/user",
- new Path()
- .get(newOperation("user")
- .tag(tag)
- .description(_Util.roSpec("6.1"))
- .response(200,
- newResponse(Caching.USER_INFO)
- .description("OK")
- .schema(newRefProperty("RestfulObjectsSupportingUserRepr"))
- )));
+ new PathItem()
+ .get(_Util.response(
+ newOperation("user")
+ .addTagsItem(tag)
+ .description(_Util.roSpec("6.1")),
+ 200,
+ newResponse(Caching.USER_INFO, newRefProperty("RestfulObjectsSupportingUserRepr"))
+ .description("OK"))));
addDefinition("RestfulObjectsSupportingUserRepr",
newModel(_Util.roSpec("6.2"))
- .property("userName", stringProperty())
- .property("roles", arrayOfStrings())
- .property("links", arrayOfLinks())
- .required("userName")
- .required("roles"));
+ .addProperty("userName", stringProperty())
+ .addProperty("roles", arrayOfStrings())
+ .addProperty("links", arrayOfLinks())
+ .addRequiredItem("userName")
+ .addRequiredItem("roles"));
swagger.path("/services",
- new Path()
- .get(newOperation("services")
- .tag(tag)
- .description(_Util.roSpec("7.1"))
- .response(200,
- newResponse(Caching.USER_INFO)
- .description("OK")
- .schema(newRefProperty("RestfulObjectsSupportingServicesRepr"))
- )));
+ new PathItem()
+ .get(_Util.response(
+ newOperation("services")
+ .addTagsItem(tag)
+ .description(_Util.roSpec("7.1")),
+ 200,
+ newResponse(Caching.USER_INFO, newRefProperty("RestfulObjectsSupportingServicesRepr"))
+ .description("OK"))));
addDefinition("RestfulObjectsSupportingServicesRepr",
newModel(_Util.roSpec("7.2"))
- .property("value", arrayOfLinks())
- .required("userName")
- .required("roles"));
+ .addProperty("value", arrayOfLinks())
+ .addRequiredItem("userName")
+ .addRequiredItem("roles"));
swagger.path("/version",
- new Path()
- .get(newOperation("RestfulObjectsSupportingServicesRepr")
- .tag(tag)
- .description(_Util.roSpec("8.1"))
- .response(200,
- newResponse(Caching.NON_EXPIRING)
- .description("OK")
- .schema(new ObjectProperty())
- )));
- swagger.addDefinition("RestfulObjectsSupportingServicesRepr",
+ new PathItem()
+ .get(_Util.response(
+ newOperation("RestfulObjectsSupportingServicesRepr")
+ .addTagsItem(tag)
+ .description(_Util.roSpec("8.1")),
+ 200,
+ newResponse(Caching.NON_EXPIRING, new ObjectSchema())
+ .description("OK"))));
+
+ swagger.getComponents().addSchemas("RestfulObjectsSupportingServicesRepr",
newModel(_Util.roSpec("8.2"))
- .property("specVersion", stringProperty())
- .property("implVersion", stringProperty())
- .property("optionalCapabilities",
- new ObjectProperty()
- .property("blobsClobs", stringProperty())
- .property("deleteObjects", stringProperty())
- .property("domainModel", stringProperty())
- .property("validateOnly", stringProperty())
- .property("protoPersistentObjects", stringProperty())
+ .addProperty("specVersion", stringProperty())
+ .addProperty("implVersion", stringProperty())
+ .addProperty("optionalCapabilities",
+ new ObjectSchema()
+ .addProperty("blobsClobs", stringProperty())
+ .addProperty("deleteObjects", stringProperty())
+ .addProperty("domainModel", stringProperty())
+ .addProperty("validateOnly", stringProperty())
+ .addProperty("protoPersistentObjects", stringProperty())
)
- .required("userName")
- .required("roles"));
+ .addRequiredItem("userName")
+ .addRequiredItem("roles"));
}
void appendLinkModelDefinition() {
- swagger.addDefinition("LinkRepr",
- new ModelImpl()
+ swagger.getComponents().addSchemas("LinkRepr",
+ new Schema()
.type("object")
- .property("rel", stringProperty().description("the relationship of the resource to this referencing resource"))
- .property("href", stringProperty().description("the hyperlink reference (URL) of the resource"))
- .property("title", stringProperty().description("title to render"))
- .property("method", stringPropertyEnum("GET", "POST", "PUT", "DELETE").description("HTTP verb to access"))
- .property("type", stringProperty().description("Content-Type recognized by the resource (for HTTP Accept header)"))
- .property("arguments", new ObjectProperty().description("Any arguments, to send as query strings or in body"))
- .property("value", stringProperty().description("the representation of the link if followed"))
- .required("rel")
- .required("href")
- .required("method")
+ .addProperty("rel", stringProperty().description("the relationship of the resource to this referencing resource"))
+ .addProperty("href", stringProperty().description("the hyperlink reference (URL) of the resource"))
+ .addProperty("title", stringProperty().description("title to render"))
+ .addProperty("method", stringPropertyEnum("GET", "POST", "PUT", "DELETE").description("HTTP verb to access"))
+ .addProperty("type", stringProperty().description("Content-Type recognized by the resource (for HTTP Accept header)"))
+ .addProperty("arguments", new ObjectSchema().description("Any arguments, to send as query strings or in body"))
+ .addProperty("value", stringProperty().description("the representation of the link if followed"))
+ .addRequiredItem("rel")
+ .addRequiredItem("href")
+ .addRequiredItem("method")
);
- swagger.addDefinition("HrefRepr",
- new ModelImpl()
+ swagger.getComponents().addSchemas("HrefRepr",
+ new Schema()
.type("object")
.description("Abbreviated version of the Link resource, used primarily to reference non-value objects")
- .property("href", stringProperty().description("the hyperlink reference (URL) of the resource"))
- .required("href")
+ .addProperty("href", stringProperty().description("the hyperlink reference (URL) of the resource"))
+ .addRequiredItem("href")
);
}
@@ -326,76 +328,75 @@ class Generation {
final String serviceId = objectSpec.getLogicalTypeName();
- final Path path = new Path();
+ final PathItem path = new PathItem();
swagger.path(String.format("/services/%s", serviceId), path);
final String serviceModelDefinition = serviceId + "Repr";
final String tag = tagForlogicalTypeName(serviceId, "> services");
- path.get(
+ path.get(_Util.response(
newOperation("object")
- .tag(tag)
- .description(_Util.roSpec("15.1"))
- .response(200,
- newResponse(Caching.TRANSACTIONAL)
- .description("OK")
- .schema(newRefProperty(serviceModelDefinition)))
- );
+ .addTagsItem(tag)
+ .description(_Util.roSpec("15.1")),
+ 200,
+ newResponse(Caching.TRANSACTIONAL, newRefProperty(serviceModelDefinition))
+ .description("OK")));
- final ModelImpl model =
+ final Schema model =
newModel(_Util.roSpec("15.1.2") + ": representation of " + serviceId)
- .property("title", stringProperty())
- .property("serviceId", stringProperty()._default(serviceId))
- .property("members", new ObjectProperty());
+ .addProperty("title", stringProperty())
+ .addProperty("serviceId", stringProperty()._default(serviceId))
+ .addProperty("members", new ObjectSchema());
addDefinition(serviceModelDefinition, model);
}
- ModelImpl appendObjectPathAndModelDefinitions(final ObjectSpecification objectSpec) {
+ Schema appendObjectPathAndModelDefinitions(final ObjectSpecification objectSpec) {
final String logicalTypeName = objectSpec.getLogicalTypeName();
- final Path path = new Path();
+ final PathItem path = new PathItem();
swagger.path(String.format("/objects/%s/{objectId}", logicalTypeName), path);
final String tag = tagForlogicalTypeName(logicalTypeName, null);
final Operation operation = newOperation("object");
path.get(operation);
operation
- .tag(tag)
+ .addTagsItem(tag)
.description(_Util.roSpec("14.1"))
- .parameter(
+ .addParametersItem(
+ _Util.typed(
new PathParameter()
- .name("objectId")
- .type("string"));
+ .name("objectId"),
+ "string"));
// per https://github.com/swagger-api/swagger-spec/issues/146, swagger 2.0 doesn't support multiple
// modelled representations per path and response code;
// in particular cannot associate representation/model with Accept header ('produces(...) method)
final String restfulObjectsModelDefinition = logicalTypeName + "RestfulObjectsRepr";
if (false) {
- operation.response(200,
- newResponse(Caching.TRANSACTIONAL)
- .description("if Accept: application/json;profile=urn:org.restfulobjects:repr-types/object")
- .schema(newRefProperty(restfulObjectsModelDefinition)));
+ _Util.response(operation,
+ 200,
+ newResponse(Caching.TRANSACTIONAL, newRefProperty(restfulObjectsModelDefinition))
+ .description("if Accept: application/json;profile=urn:org.restfulobjects:repr-types/object"));
- final ModelImpl roSpecModel =
+ final Schema roSpecModel =
newModel(_Util.roSpec("14.4") + ": representation of " + logicalTypeName)
- .property("title", stringProperty())
- .property("domainType", stringProperty()._default(logicalTypeName))
- .property("instanceId", stringProperty())
- .property("members", new ObjectProperty());
- swagger.addDefinition(restfulObjectsModelDefinition, roSpecModel);
+ .addProperty("title", stringProperty())
+ .addProperty("domainType", stringProperty()._default(logicalTypeName))
+ .addProperty("instanceId", stringProperty())
+ .addProperty("members", new ObjectSchema());
+ swagger.getComponents().addSchemas(restfulObjectsModelDefinition, roSpecModel);
}
final String causewayModelDefinition = logicalTypeName + "Repr";
- operation
- .response(200,
- newResponse(Caching.TRANSACTIONAL)
- .description(logicalTypeName + " , if Accept: application/json;profile=urn:org.apache.causeway/v2")
- .schema(newRefProperty(causewayModelDefinition)));
- final ModelImpl causewayModel = new ModelImpl();
+ _Util.response(operation,
+ 200,
+ newResponse(Caching.TRANSACTIONAL, newRefProperty(causewayModelDefinition))
+ .description(logicalTypeName + " , if Accept: application/json;profile=urn:org.apache.causeway/v2"));
+
+ final Schema causewayModel = new Schema();
addDefinition(causewayModelDefinition, causewayModel);
// return so can be appended to
@@ -403,21 +404,21 @@ class Generation {
}
// UNUSED
- void appendServiceActionPromptTo(final ObjectProperty serviceMembers, final ObjectAction action) {
+ void appendServiceActionPromptTo(final ObjectSchema serviceMembers, final ObjectAction action) {
String actionId = action.getId();
- serviceMembers.property(actionId,
- new ObjectProperty()
- .property("id", stringPropertyEnum(actionId))
- .property("memberType", stringPropertyEnum("action"))
- .property("links",
- new ObjectProperty()
- .property("rel", stringPropertyEnum( String.format(
+ serviceMembers.addProperty(actionId,
+ new ObjectSchema()
+ .addProperty("id", stringPropertyEnum(actionId))
+ .addProperty("memberType", stringPropertyEnum("action"))
+ .addProperty("links",
+ new ObjectSchema()
+ .addProperty("rel", stringPropertyEnum( String.format(
"urn:org.restfulobjects:rels/details;action=%s", actionId)))
- .property("href", stringPropertyEnum(String.format(
+ .addProperty("href", stringPropertyEnum(String.format(
"actions/%s", actionId))))
- .property("method", stringPropertyEnum("GET"))
- .property("type", stringPropertyEnum(
+ .addProperty("method", stringPropertyEnum("GET"))
+ .addProperty("type", stringPropertyEnum(
"application/json;profile=urn:org.restfulobjects:repr-types/object-action"))
);
}
@@ -430,13 +431,13 @@ class Generation {
final String actionId = serviceAction.getId();
val parameters = serviceAction.getParameters();
- final Path path = new Path();
+ final PathItem path = new PathItem();
swagger.path(String.format("/services/%s/actions/%s/invoke", serviceId, actionId), path);
final String tag = tagForlogicalTypeName(serviceId, "> services");
final Operation invokeOperation =
newOperation("object", "action-result")
- .tag(tag)
+ .addTagsItem(tag)
.description(_Util.roSpec("19.1") + ": (invoke) resource of " + serviceId + "#" + actionId);
final SemanticsOf semantics = serviceAction.getSemantics();
@@ -448,23 +449,21 @@ class Generation {
val describedAs = parameter.getStaticDescription().orElse(null);
invokeOperation
- .parameter(
- new QueryParameter()
+ .addParametersItem(_Util.typed(new QueryParameter()
.name(parameter.getId())
.description(_Util.roSpec("2.9.1")
+ (_Strings.isNotEmpty(describedAs)
? (": " + describedAs)
: ""))
- .required(false)
- .type("string")
- );
+ .required(false),
+ "string"));
}
if(!parameters.isEmpty()) {
- invokeOperation.parameter(new QueryParameter()
+ invokeOperation.addParametersItem(_Util.typed(new QueryParameter()
.name("x-causeway-querystring")
.description(_Util.roSpec("2.10") + ": all (formal) arguments as base64 encoded string")
- .required(false)
- .type("string"));
+ .required(false),
+ "string"));
}
} else {
@@ -474,38 +473,34 @@ class Generation {
path.post(invokeOperation);
}
- final ModelImpl bodyParam =
- new ModelImpl()
+ final Schema bodyParam =
+ new Schema()
.type("object");
for (final ObjectActionParameter parameter : parameters) {
- final Property valueProperty;
+ final Schema valueProperty;
// TODO: need to switch on parameter's type and create appropriate impl of valueProperty
// if(parameter.getSpecification().isValue()) ...
valueProperty = stringProperty();
bodyParam
- .property(parameter.getId(),
- new ObjectProperty()
- .property("value", valueProperty)
+ .addProperty(parameter.getId(),
+ new ObjectSchema()
+ .addProperty("value", valueProperty)
);
}
- invokeOperation
- .consumes("application/json")
- .parameter(
+ _Util.consumes(invokeOperation, "application/json")
+ .addParametersItem(
new BodyParameter()
.name("body")
.schema(bodyParam));
}
- invokeOperation
- .response(
- 200, new Response()
- .description(serviceId + "#" + actionId + " , if Accept: application/json;profile=urn:org.apache.causeway/v2")
- .schema(actionReturnTypeFor(serviceAction))
- );
+ _Util.response(invokeOperation,
+ 200, newResponse(actionReturnTypeFor(serviceAction))
+ .description(serviceId + "#" + actionId + " , if Accept: application/json;profile=urn:org.apache.causeway/v2"));
}
void appendCollectionTo(
@@ -515,26 +510,23 @@ class Generation {
final String logicalTypeName = objectSpec.getLogicalTypeName();
final String collectionId = collection.getId();
- final Path path = new Path();
+ final PathItem path = new PathItem();
swagger.path(String.format("/objects/%s/{objectId}/collections/%s", logicalTypeName, collectionId), path);
final String tag = tagForlogicalTypeName(logicalTypeName, null);
final Operation collectionOperation =
newOperation("object-collection")
- .tag(tag)
+ .addTagsItem(tag)
.description(_Util.roSpec("17.1") + ": resource of " + logicalTypeName + "#" + collectionId)
- .parameter(
- new PathParameter()
- .name("objectId")
- .type("string"));
+ .addParametersItem(
+ _Util.typed(new PathParameter(), "string")
+ .name("objectId"));
path.get(collectionOperation);
- collectionOperation
- .response(
- 200, new Response()
- .description(logicalTypeName + "#" + collectionId + " , if Accept: application/json;profile=urn:org.apache.causeway/v2")
- .schema(modelFor(collection))
- );
+ _Util.response(collectionOperation,
+ 200,
+ newResponse(modelFor(collection))
+ .description(logicalTypeName + "#" + collectionId + " , if Accept: application/json;profile=urn:org.apache.causeway/v2"));
}
void appendObjectActionInvokePath(
@@ -545,18 +537,19 @@ class Generation {
final String actionId = objectAction.getId();
val parameters = objectAction.getParameters();
- final Path path = new Path();
+ final PathItem path = new PathItem();
swagger.path(String.format("/objects/%s/{objectId}/actions/%s/invoke", logicalTypeName, actionId), path);
final String tag = tagForlogicalTypeName(logicalTypeName, null);
final Operation invokeOperation =
newOperation("action-result")
- .tag(tag)
+ .addTagsItem(tag)
.description(_Util.roSpec("19.1") + ": (invoke) resource of " + logicalTypeName + "#" + actionId)
- .parameter(
+ .addParametersItem(
+ _Util.typed(
new PathParameter()
- .name("objectId")
- .type("string"));
+ .name("objectId"),
+ "string"));
final SemanticsOf semantics = objectAction.getSemantics();
if(semantics.isSafeInNature()) {
@@ -567,23 +560,26 @@ class Generation {
val describedAs = parameter.getStaticDescription().orElse(null);
invokeOperation
- .parameter(
+ .addParametersItem(
+ _Util.typed(
new QueryParameter()
.name(parameter.getId())
.description(_Util.roSpec("2.9.1")
+ (_Strings.isNotEmpty(describedAs)
? (": " + describedAs)
: ""))
- .required(false)
- .type("string")
+ .required(false),
+ "string")
);
}
if(!parameters.isEmpty()) {
- invokeOperation.parameter(new QueryParameter()
+ invokeOperation.addParametersItem(
+ _Util.typed(
+ new QueryParameter()
.name("x-causeway-querystring")
.description(_Util.roSpec("2.10") + ": all (formal) arguments as base64 encoded string")
- .required(false)
- .type("string"));
+ .required(false),
+ "string"));
}
} else {
@@ -593,82 +589,78 @@ class Generation {
path.post(invokeOperation);
}
- final ModelImpl bodyParam =
- new ModelImpl()
+ final Schema bodyParam =
+ new Schema()
.type("object");
for (final ObjectActionParameter parameter : parameters) {
final ObjectSpecification specification = parameter.getElementType();
- final Property valueProperty = specification.isValue() ? modelFor(specification) : refToLinkModel() ;
+ final Schema valueProperty = specification.isValue() ? modelFor(specification) : refToLinkModel() ;
bodyParam
- .property(parameter.getId(),
- new ObjectProperty()
- .property("value", valueProperty)
+ .addProperty(parameter.getId(),
+ new ObjectSchema()
+ .addProperty("value", valueProperty)
);
}
- invokeOperation
- .consumes("application/json")
- .parameter(
+ _Util.consumes(invokeOperation, "application/json")
+ .addParametersItem(
new BodyParameter()
.name("body")
.schema(bodyParam));
}
- invokeOperation
- .response(
- 200, new Response()
- .description(logicalTypeName + "#" + actionId)
- .schema(actionReturnTypeFor(objectAction))
- );
+ _Util.response(invokeOperation,
+ 200, newResponse(actionReturnTypeFor(objectAction))
+ .description(logicalTypeName + "#" + actionId));
}
void appendDefinitionsForOrphanedReferences() {
final Set<String> referencesWithoutDefinition = getReferencesWithoutDefinition();
for (String reference : referencesWithoutDefinition) {
- swagger.addDefinition(reference, new ModelImpl());
+ swagger.getComponents().addSchemas(reference, new Schema());
}
}
- Property actionReturnTypeFor(final ObjectAction objectAction) {
+ Schema actionReturnTypeFor(final ObjectAction objectAction) {
return objectAction.getReturnType().isPlural()
? arrayPropertyOf(objectAction.getElementType())
: modelFor(objectAction.getReturnType());
}
- private Property modelFor(final OneToManyAssociation collection) {
+ private Schema modelFor(final OneToManyAssociation collection) {
ObjectSpecification collectionSpecification = collection.getElementType();
return arrayPropertyOf(collectionSpecification);
}
- private Property arrayPropertyOf(final ObjectSpecification objectSpecification) {
- final ArrayProperty arrayProperty = new ArrayProperty();
+ private Schema arrayPropertyOf(final ObjectSpecification objectSpecification) {
+ final ArraySchema arrayProperty = new ArraySchema();
if(objectSpecification != null && objectSpecification.getCorrespondingClass() != Object.class) {
arrayProperty
.description("List of " + objectSpecification.getLogicalTypeName())
.items(modelFor(objectSpecification));
} else {
- arrayProperty.items(new ObjectProperty());
+ arrayProperty.items(new ObjectSchema());
}
return arrayProperty;
}
- private Property modelFor(final ObjectSpecification specification) {
+ private Schema modelFor(final ObjectSpecification specification) {
if(specification == null) {
- return new ObjectProperty();
+ return new ObjectSchema();
}
// no "simple" representation for void or values
final Class<?> correspondingClass = specification.getCorrespondingClass();
if(correspondingClass == void.class || correspondingClass == Void.class) {
- return new ObjectProperty();
+ return new ObjectSchema();
}
// no "simple" representation for values
- final Property property = valuePropertyFactory.newProperty(correspondingClass);
+ final Schema property = valuePropertyFactory.newProperty(correspondingClass);
if(property != null) {
// was recognized as a value
- return new ObjectProperty();
+ return new ObjectSchema();
}
if(specification.isPlural()) {
@@ -679,16 +671,16 @@ class Generation {
}
if(specification.getCorrespondingClass() == java.lang.Object.class) {
- return new ObjectProperty();
+ return new ObjectSchema();
}
if(specification.getCorrespondingClass() == java.lang.Enum.class) {
- return new StringProperty();
+ return new StringSchema();
}
return newRefProperty(specification.getLogicalTypeName() + "Repr");
}
void updateObjectModel(
- final ModelImpl model,
+ final Schema model,
final ObjectSpecification objectSpecification,
final List<OneToOneAssociation> objectProperties,
final List<OneToManyAssociation> objectCollections) {
@@ -701,22 +693,22 @@ class Generation {
.description(String.format("%s (%s)", logicalTypeName, className));
for (OneToOneAssociation objectProperty : objectProperties) {
- model.property(
+ model.addProperty(
objectProperty.getId(),
propertyFor(objectProperty.getElementType()));
}
for (OneToManyAssociation objectCollection : objectCollections) {
final ObjectSpecification elementSpec = objectCollection.getElementType();
- model.property(
+ model.addProperty(
objectCollection.getId(),
arrayPropertyOf(elementSpec)
);
}
}
- Property propertyFor(final ObjectSpecification objectSpecification) {
- final Property property =
+ Schema propertyFor(final ObjectSpecification objectSpecification) {
+ final Schema property =
valuePropertyFactory.newProperty(objectSpecification.getCorrespondingClass());
if (property != null) {
return property;
@@ -742,22 +734,22 @@ class Generation {
}
}
- static ModelImpl newModel(final String description) {
- return new ModelImpl()
+ static Schema newModel(final String description) {
+ return new Schema()
.description(description)
.type("object")
- .property("links", arrayOfLinks())
- .property("extensions", new MapProperty())
- .required("links")
- .required("extensions");
+ .addProperty("links", arrayOfLinks())
+ .addProperty("extensions", new MapSchema())
+ .addRequiredItem("links")
+ .addRequiredItem("extensions");
}
- static StringProperty stringProperty() {
- return new StringProperty();
+ static StringSchema stringProperty() {
+ return new StringSchema();
}
- static StringProperty stringPropertyEnum(final String... enumValues) {
- final StringProperty stringProperty = stringProperty();
+ static StringSchema stringPropertyEnum(final String... enumValues) {
+ final StringSchema stringProperty = stringProperty();
stringProperty._enum(Arrays.asList(enumValues));
if(enumValues.length >= 1) {
stringProperty._default(enumValues[0]);
@@ -765,39 +757,44 @@ class Generation {
return stringProperty;
}
- static ArrayProperty arrayOfLinks() {
- return new ArrayProperty()
+ static ArraySchema arrayOfLinks() {
+ return new ArraySchema()
.items(refToLinkModel());
}
- static RefProperty refToLinkModel() {
- return new RefProperty("#/definitions/LinkRepr");
+ static RefSchema refToLinkModel() {
+ return new RefSchema("#/definitions/LinkRepr");
+ }
+
+ static RefSchema refToHrefModel() {
+ return new RefSchema("#/definitions/HrefRepr");
}
- static RefProperty refToHrefModel() {
- return new RefProperty("#/definitions/HrefRepr");
+ static ArraySchema arrayOfStrings() {
+ return new ArraySchema().items(stringProperty());
}
- static ArrayProperty arrayOfStrings() {
- return new ArrayProperty().items(stringProperty());
+ //TODO[ISIS-3292] honor schema
+ static ApiResponse newResponse(final Schema schema) {
+ return new ApiResponse();
}
- static Response newResponse(final Caching caching) {
- return _Util.withCachingHeaders(new Response(), caching);
+ static ApiResponse newResponse(final Caching caching, final Schema schema) {
+ return _Util.withCachingHeaders(newResponse(schema), caching);
}
String tagForlogicalTypeName(final String logicalTypeName, final String fallback) {
return tagger.tagForLogicalTypeName(logicalTypeName, fallback);
}
- private Property newRefProperty(final String model) {
+ private Schema newRefProperty(final String model) {
addSwaggerReference(model);
- return new RefProperty("#/definitions/" + model);
+ return new RefSchema("#/definitions/" + model);
}
- private void addDefinition(final String key, final ModelImpl model) {
+ private void addDefinition(final String key, final Schema model) {
addSwaggerDefinition(key);
- swagger.addDefinition(key, model);
+ swagger.getComponents().addSchemas(key, model);
}
void addSwaggerReference(final String model) {
@@ -815,8 +812,8 @@ class Generation {
}
private static Operation newOperation(final String ... reprTypes) {
- Operation operation = new Operation()
- .produces("application/json");
+ Operation operation =
+ _Util.produces(new Operation(), "application/json");
boolean supportsV1 = false;
@@ -827,15 +824,16 @@ class Generation {
supportsV1 = true;
}
- operation = operation.produces(
+ operation = _Util.produces(operation,
"application/json;profile=" + DQ + "urn:org.restfulobjects:repr-types/" + reprType + DQ);
}
}
if(supportsV1) {
- operation = operation
- .produces("application/json;profile=" + DQ + "urn:org.apache.causeway/v2" + DQ)
- .produces("application/json;profile=" + DQ + "urn:org.apache.causeway/v2;suppress=all" + DQ);
+ operation = _Util.produces(operation,
+ "application/json;profile=" + DQ + "urn:org.apache.causeway/v2" + DQ);
+ operation = _Util.produces(operation,
+ "application/json;profile=" + DQ + "urn:org.apache.causeway/v2;suppress=all" + DQ);
}
return operation;
diff --git a/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/RefSchema.java b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/RefSchema.java
new file mode 100644
index 0000000000..4df7aec133
--- /dev/null
+++ b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/RefSchema.java
@@ -0,0 +1,11 @@
+package org.apache.causeway.viewer.restfulobjects.rendering.service.swagger.internal;
+
+import io.swagger.v3.oas.models.media.Schema;
+
+public class RefSchema extends Schema {
+
+ public RefSchema(final String string) {
+ //TODO[ISIS-3292] implement or replace
+ }
+
+}
diff --git a/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/SwaggerSpecGenerator.java b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/SwaggerSpecGenerator.java
index 634330a889..ad2e48d8ec 100644
--- a/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/SwaggerSpecGenerator.java
+++ b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/SwaggerSpecGenerator.java
@@ -30,9 +30,9 @@ import org.apache.causeway.applib.services.swagger.Visibility;
import org.apache.causeway.core.metamodel.specloader.SpecificationLoader;
import org.apache.causeway.viewer.restfulobjects.applib.CausewayModuleViewerRestfulObjectsApplib;
-import io.swagger.models.Swagger;
-import io.swagger.util.Json;
-import io.swagger.util.Yaml;
+import io.swagger.v3.core.util.Json;
+import io.swagger.v3.core.util.Yaml;
+import io.swagger.v3.oas.models.OpenAPI;
@Component
@Named(CausewayModuleViewerRestfulObjectsApplib.NAMESPACE + ".SwaggerSpecGenerator")
@@ -61,7 +61,7 @@ public class SwaggerSpecGenerator {
final Format format) {
final Generation generation = newGeneration(basePath, visibility);
- final Swagger swagger = generation.generate();
+ final OpenAPI swagger = generation.generate();
switch (format) {
case JSON:
diff --git a/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/ValuePropertyFactory.java b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/ValuePropertyFactory.java
index 23cfaf1085..3c3c1c57e7 100644
--- a/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/ValuePropertyFactory.java
+++ b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/ValuePropertyFactory.java
@@ -18,8 +18,8 @@
*/
package org.apache.causeway.viewer.restfulobjects.rendering.service.swagger.internal;
-import io.swagger.models.properties.Property;
+import io.swagger.v3.oas.models.media.Schema;
public interface ValuePropertyFactory {
- Property newProperty(Class<?> cls);
+ Schema newProperty(Class<?> cls);
}
diff --git a/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/ValuePropertyFactoryDefault.java b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/ValuePropertyFactoryDefault.java
index 381d0622f9..e39343dbcf 100644
--- a/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/ValuePropertyFactoryDefault.java
+++ b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/ValuePropertyFactoryDefault.java
@@ -19,7 +19,6 @@
package org.apache.causeway.viewer.restfulobjects.rendering.service.swagger.internal;
import java.math.BigDecimal;
-import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -40,18 +39,15 @@ import org.apache.causeway.commons.internal.collections._Maps;
import org.apache.causeway.viewer.restfulobjects.applib.CausewayModuleViewerRestfulObjectsApplib;
import org.apache.causeway.viewer.restfulobjects.rendering.service.swagger.internal.ValuePropertyPlugin.ValuePropertyCollector;
-import io.swagger.models.properties.BooleanProperty;
-import io.swagger.models.properties.ByteArrayProperty;
-import io.swagger.models.properties.DateProperty;
-import io.swagger.models.properties.DateTimeProperty;
-import io.swagger.models.properties.DecimalProperty;
-import io.swagger.models.properties.DoubleProperty;
-import io.swagger.models.properties.FloatProperty;
-import io.swagger.models.properties.IntegerProperty;
-import io.swagger.models.properties.LongProperty;
-import io.swagger.models.properties.Property;
-import io.swagger.models.properties.StringProperty;
-import io.swagger.models.properties.UUIDProperty;
+import io.swagger.v3.oas.models.media.BooleanSchema;
+import io.swagger.v3.oas.models.media.ByteArraySchema;
+import io.swagger.v3.oas.models.media.DateSchema;
+import io.swagger.v3.oas.models.media.DateTimeSchema;
+import io.swagger.v3.oas.models.media.IntegerSchema;
+import io.swagger.v3.oas.models.media.NumberSchema;
+import io.swagger.v3.oas.models.media.Schema;
+import io.swagger.v3.oas.models.media.StringSchema;
+import io.swagger.v3.oas.models.media.UUIDSchema;
@Component
@Named(CausewayModuleViewerRestfulObjectsApplib.NAMESPACE + ".ValuePropertyFactoryDefault")
@@ -61,49 +57,52 @@ public class ValuePropertyFactoryDefault implements ValuePropertyFactory {
@Autowired(required = false) private List<ValuePropertyPlugin> valuePropertyPlugins;
- public static interface Factory extends Supplier<Property> {};
+ public static interface Factory extends Supplier<Schema> {};
public ValuePropertyFactoryDefault() {
- propertyFactoryByClass.put(boolean.class, BooleanProperty::new);
- propertyFactoryByClass.put(Boolean.class, BooleanProperty::new);
+ propertyFactoryByClass.put(boolean.class, BooleanSchema::new);
+ propertyFactoryByClass.put(Boolean.class, BooleanSchema::new);
- propertyFactoryByClass.put(byte.class, IntegerProperty::new);
- propertyFactoryByClass.put(Byte.class, IntegerProperty::new);
- propertyFactoryByClass.put(short.class, IntegerProperty::new);
- propertyFactoryByClass.put(Short.class, IntegerProperty::new);
- propertyFactoryByClass.put(int.class, IntegerProperty::new);
- propertyFactoryByClass.put(Integer.class, IntegerProperty::new);
- propertyFactoryByClass.put(BigInteger.class, IntegerProperty::new);
+ propertyFactoryByClass.put(byte.class, IntegerSchema::new);
+ propertyFactoryByClass.put(Byte.class, IntegerSchema::new);
+ propertyFactoryByClass.put(short.class, IntegerSchema::new);
+ propertyFactoryByClass.put(Short.class, IntegerSchema::new);
+ propertyFactoryByClass.put(int.class, IntegerSchema::new);
+ propertyFactoryByClass.put(Integer.class, IntegerSchema::new);
- propertyFactoryByClass.put(long.class, LongProperty::new);
- propertyFactoryByClass.put(Long.class, LongProperty::new);
- propertyFactoryByClass.put(java.sql.Timestamp.class, LongProperty::new);
+ //TODO[ISIS-3292] implement or replace ...
+// propertyFactoryByClass.put(BigInteger.class, IntegerSchema::new);
- propertyFactoryByClass.put(BigDecimal.class, DecimalProperty::new);
+// propertyFactoryByClass.put(long.class, LongSchema::new);
+// propertyFactoryByClass.put(Long.class, LongSchema::new);
+// propertyFactoryByClass.put(java.sql.Timestamp.class, LongSchema::new);
- propertyFactoryByClass.put(float.class, FloatProperty::new);
- propertyFactoryByClass.put(Float.class, FloatProperty::new);
+ propertyFactoryByClass.put(BigDecimal.class, NumberSchema::new);
- propertyFactoryByClass.put(double.class, DoubleProperty::new);
- propertyFactoryByClass.put(Double.class, DoubleProperty::new);
+ //TODO[ISIS-3292] implement or replace ...
+// propertyFactoryByClass.put(float.class, FloatSchema::new);
+// propertyFactoryByClass.put(Float.class, FloatSchema::new);
+//
+// propertyFactoryByClass.put(double.class, DoubleSchema::new);
+// propertyFactoryByClass.put(Double.class, DoubleSchema::new);
- propertyFactoryByClass.put(char.class, StringProperty::new);
- propertyFactoryByClass.put(Character.class, StringProperty::new);
- propertyFactoryByClass.put(char[].class, StringProperty::new);
- propertyFactoryByClass.put(String.class, StringProperty::new);
+ propertyFactoryByClass.put(char.class, StringSchema::new);
+ propertyFactoryByClass.put(Character.class, StringSchema::new);
+ propertyFactoryByClass.put(char[].class, StringSchema::new);
+ propertyFactoryByClass.put(String.class, StringSchema::new);
- propertyFactoryByClass.put(UUID.class, UUIDProperty::new);
+ propertyFactoryByClass.put(UUID.class, UUIDSchema::new);
- propertyFactoryByClass.put(java.util.Date.class, DateTimeProperty::new);
- propertyFactoryByClass.put(DateTime.class, DateTimeProperty::new);
- propertyFactoryByClass.put(LocalDateTime.class, DateTimeProperty::new);
+ propertyFactoryByClass.put(java.util.Date.class, DateTimeSchema::new);
+ propertyFactoryByClass.put(DateTime.class, DateTimeSchema::new);
+ propertyFactoryByClass.put(LocalDateTime.class, DateTimeSchema::new);
- propertyFactoryByClass.put(java.sql.Date.class, DateProperty::new);
- propertyFactoryByClass.put(LocalDate.class, DateProperty::new);
+ propertyFactoryByClass.put(java.sql.Date.class, DateSchema::new);
+ propertyFactoryByClass.put(LocalDate.class, DateSchema::new);
- propertyFactoryByClass.put(byte[].class, ByteArrayProperty::new);
- propertyFactoryByClass.put(org.apache.causeway.applib.value.Blob.class, ByteArrayProperty::new);
+ propertyFactoryByClass.put(byte[].class, ByteArraySchema::new);
+ propertyFactoryByClass.put(org.apache.causeway.applib.value.Blob.class, ByteArraySchema::new);
// add propertyFactories from plugins
discoverValueProperties().visitEntries(propertyFactoryByClass::put);
@@ -111,7 +110,7 @@ public class ValuePropertyFactoryDefault implements ValuePropertyFactory {
}
@Override
- public Property newProperty(Class<?> cls) {
+ public Schema newProperty(final Class<?> cls) {
if(cls == null) {
return null;
}
@@ -123,7 +122,7 @@ public class ValuePropertyFactoryDefault implements ValuePropertyFactory {
// special case, want to treat as a value
if(cls.isEnum()) {
- final StringProperty property = new StringProperty();
+ final StringSchema property = new StringSchema();
final Object[] enumConstants = cls.getEnumConstants();
final List<String> enumNames = _Lists.map(
diff --git a/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/_Util.java b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/_Util.java
index e8ab769be5..a54ad0c8f2 100644
--- a/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/_Util.java
+++ b/viewers/restfulobjects/rendering/src/main/java/org/apache/causeway/viewer/restfulobjects/rendering/service/swagger/internal/_Util.java
@@ -37,7 +37,9 @@ import org.apache.causeway.core.metamodel.spec.feature.OneToManyAssociation;
import org.apache.causeway.core.metamodel.spec.feature.OneToOneAssociation;
import org.apache.causeway.core.metamodel.util.Facets;
-import io.swagger.models.Response;
+import io.swagger.v3.oas.models.Operation;
+import io.swagger.v3.oas.models.parameters.Parameter;
+import io.swagger.v3.oas.models.responses.ApiResponse;
import lombok.val;
import lombok.experimental.UtilityClass;
@@ -100,12 +102,7 @@ final class _Util {
}
Predicate<ObjectAssociation> associationsWith(final Visibility visibility) {
- return new Predicate<ObjectAssociation>() {
- @Override
- public boolean test(final ObjectAssociation objectAssociation) {
- return !visibility.isPublic() || isVisibleForPublic(objectAssociation);
- }
- };
+ return objectAssociation -> !visibility.isPublic() || isVisibleForPublic(objectAssociation);
}
List<OneToOneAssociation> propertiesOf(
@@ -148,7 +145,7 @@ final class _Util {
return "RO Spec v1.0, section " + section;
}
- Response withCachingHeaders(final Response response, final Caching caching) {
+ ApiResponse withCachingHeaders(final ApiResponse response, final Caching caching) {
caching.withHeaders(response);
return response;
@@ -164,4 +161,24 @@ final class _Util {
}
throw _Exceptions.unmatchedCase(visibility);
}
+
+ Operation produces(final Operation operation, final String string) {
+ // TODO[ISIS-3292] Auto-generated method stub
+ return operation;
+ }
+
+ <T extends Parameter> T typed(final T parameter, final String typeLiteral) {
+ // TODO[ISIS-3292] Auto-generated method stub
+ return parameter;
+ }
+
+ Operation response(final Operation operation, final int code, final ApiResponse response) {
+ // TODO[ISIS-3292] Auto-generated method stub
+ return operation;
+ }
+
+ Operation consumes(final Operation operation, final String string) {
+ // TODO[ISIS-3292] Auto-generated method stub
+ return operation;
+ }
}
diff --git a/viewers/restfulobjects/viewer/src/main/java/org/apache/causeway/viewer/restfulobjects/viewer/resources/SwaggerSpecResource.java b/viewers/restfulobjects/viewer/src/main/java/org/apache/causeway/viewer/restfulobjects/viewer/resources/SwaggerSpecResource.java
index 88f96e7a60..29172503b3 100644
--- a/viewers/restfulobjects/viewer/src/main/java/org/apache/causeway/viewer/restfulobjects/viewer/resources/SwaggerSpecResource.java
+++ b/viewers/restfulobjects/viewer/src/main/java/org/apache/causeway/viewer/restfulobjects/viewer/resources/SwaggerSpecResource.java
@@ -133,6 +133,11 @@ public class SwaggerSpecResource {
@Override
public String call() throws Exception {
+
+// return format==Format.YAML
+// ? _Strings.readFromResource(SwaggerSpecGenerator.class, "openapi-sample.yaml", StandardCharsets.UTF_8)
+// : _Strings.readFromResource(SwaggerSpecGenerator.class, "openapi-sample.json", StandardCharsets.UTF_8);
+
return swaggerService.generateSwaggerSpec(visibility, format);
}