You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2019/12/03 14:43:59 UTC
[isis] 02/04: ISIS-2200: improves ordering of swagger paths
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit b9d6072ca38bb610d6d9bb36fd9ea716858bad43
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Dec 3 14:37:10 2019 +0000
ISIS-2200: improves ordering of swagger paths
and refactors the Tagger, ClassExcluder and ValuePropertyFactory under Spring control so that they can be substituted if necessary.
---
.../services/swagger/SwaggerServiceDefault.java | 7 +-
.../services/swagger/internal/ClassExcluder.java | 46 +-------
...assExcluder.java => ClassExcluderAbstract.java} | 22 +++-
...lassExcluder.java => ClassExcluderDefault.java} | 27 ++---
.../services/swagger/internal/Generation.java | 67 ++++++------
.../swagger/internal/SwaggerSpecGenerator.java | 24 ++++-
.../services/swagger/internal/Tagger.java | 64 +----------
.../internal/{Tagger.java => TaggerDefault.java} | 36 +++----
.../swagger/internal/ValuePropertyFactory.java | 119 +--------------------
...ctory.java => ValuePropertyFactoryDefault.java} | 7 +-
.../swagger/internal/ValuePropertyPlugin.java | 6 +-
.../services/swagger/internal/GenerationTest.java | 2 +-
.../services/swagger/internal/TaggerTest.java | 16 +--
.../fixtures/fixturescripts/FixtureResult.java | 2 +-
14 files changed, 129 insertions(+), 316 deletions(-)
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/SwaggerServiceDefault.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/SwaggerServiceDefault.java
index 0efcf68..af5bda9 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/SwaggerServiceDefault.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/SwaggerServiceDefault.java
@@ -19,7 +19,6 @@
package org.apache.isis.metamodel.services.swagger;
import javax.inject.Inject;
-import javax.inject.Singleton;
import org.springframework.stereotype.Service;
@@ -37,13 +36,17 @@ import static org.apache.isis.commons.internal.resources._Resources.prependConte
public class SwaggerServiceDefault implements SwaggerService {
@Inject SpecificationLoader specificationLoader;
+ private final SwaggerSpecGenerator swaggerSpecGenerator;
+
+ public SwaggerServiceDefault(SwaggerSpecGenerator swaggerSpecGenerator) {
+ this.swaggerSpecGenerator = swaggerSpecGenerator;
+ }
@Override
public String generateSwaggerSpec(
final Visibility visibility,
final Format format) {
- final SwaggerSpecGenerator swaggerSpecGenerator = new SwaggerSpecGenerator(specificationLoader);
final String swaggerSpec = swaggerSpecGenerator.generate(basePath.get(), visibility, format);
return swaggerSpec;
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluder.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluder.java
index c0e2ccd..f7a6c2c 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluder.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluder.java
@@ -1,49 +1,9 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
package org.apache.isis.metamodel.services.swagger.internal;
-import java.util.List;
-
import org.apache.isis.metamodel.spec.ObjectSpecification;
import org.apache.isis.metamodel.spec.feature.ObjectAction;
-public class ClassExcluder {
-
- protected boolean exclude(final ObjectSpecification objectSpec) {
- if(objectSpec == null) {
- return false;
- }
- return objectSpec.isExcludedFromMetamodel();
- }
-
- public boolean exclude(final ObjectAction objectAction) {
- final ObjectSpecification returnType = objectAction.getReturnType();
- if(exclude(returnType)) {
- return true;
- }
-
- final List<ObjectSpecification> parameterTypes = objectAction.getParameterTypes();
- for (ObjectSpecification parameterType : parameterTypes) {
- if(exclude(parameterType)) {
- return true;
- }
- }
- return false;
- }
+public interface ClassExcluder {
+ boolean exclude(final ObjectSpecification objectSpec);
+ boolean exclude(ObjectAction objectAction);
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluder.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluderAbstract.java
similarity index 68%
copy from core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluder.java
copy to core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluderAbstract.java
index c0e2ccd..5f8920e 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluder.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluderAbstract.java
@@ -19,19 +19,35 @@
package org.apache.isis.metamodel.services.swagger.internal;
import java.util.List;
+import java.util.Set;
+import org.apache.isis.commons.internal.collections._Sets;
import org.apache.isis.metamodel.spec.ObjectSpecification;
import org.apache.isis.metamodel.spec.feature.ObjectAction;
+import org.springframework.stereotype.Component;
-public class ClassExcluder {
+public abstract class ClassExcluderAbstract implements ClassExcluder {
- protected boolean exclude(final ObjectSpecification objectSpec) {
+ private final Set<String> packageNamesToIgnore = _Sets.newHashSet();
+
+ protected void ignorePackage(final String packageName) {
+ packageNamesToIgnore.add(packageName);
+ }
+
+ @Override
+ public boolean exclude(final ObjectSpecification objectSpec) {
if(objectSpec == null) {
return false;
}
- return objectSpec.isExcludedFromMetamodel();
+ if (objectSpec.isExcludedFromMetamodel()) {
+ return true;
+ }
+
+ return packageNamesToIgnore.stream()
+ .anyMatch(packageName -> objectSpec.getCorrespondingClass().getName().startsWith(packageName));
}
+ @Override
public boolean exclude(final ObjectAction objectAction) {
final ObjectSpecification returnType = objectAction.getReturnType();
if(exclude(returnType)) {
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluder.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluderDefault.java
similarity index 59%
copy from core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluder.java
copy to core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluderDefault.java
index c0e2ccd..0ee84fd 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluder.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ClassExcluderDefault.java
@@ -19,31 +19,18 @@
package org.apache.isis.metamodel.services.swagger.internal;
import java.util.List;
+import java.util.Set;
+import org.apache.isis.commons.internal.collections._Sets;
import org.apache.isis.metamodel.spec.ObjectSpecification;
import org.apache.isis.metamodel.spec.feature.ObjectAction;
+import org.springframework.stereotype.Component;
-public class ClassExcluder {
+@Component
+public class ClassExcluderDefault extends ClassExcluderAbstract {
- protected boolean exclude(final ObjectSpecification objectSpec) {
- if(objectSpec == null) {
- return false;
- }
- return objectSpec.isExcludedFromMetamodel();
+ public ClassExcluderDefault() {
+ ignorePackage("org.apache.isis.commons.internal");
}
- public boolean exclude(final ObjectAction objectAction) {
- final ObjectSpecification returnType = objectAction.getReturnType();
- if(exclude(returnType)) {
- return true;
- }
-
- final List<ObjectSpecification> parameterTypes = objectAction.getParameterTypes();
- for (ObjectSpecification parameterType : parameterTypes) {
- if(exclude(parameterType)) {
- return true;
- }
- }
- return false;
- }
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Generation.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Generation.java
index 18d044a..b279e25 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Generation.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Generation.java
@@ -18,11 +18,7 @@
*/
package org.apache.isis.metamodel.services.swagger.internal;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
import java.util.stream.Collectors;
import org.apache.isis.applib.annotation.SemanticsOf;
@@ -76,26 +72,16 @@ class Generation {
public Generation(
final String basePath,
final SwaggerService.Visibility visibility,
- final SpecificationLoader specificationLoader) {
+ final SpecificationLoader specificationLoader,
+ final Tagger tagger,
+ final ClassExcluder classExcluder,
+ final ValuePropertyFactory valuePropertyFactory) {
this.basePath = basePath;
this.visibility = visibility;
this.specificationLoader = specificationLoader;
-
- this.valuePropertyFactory = newValuePropertyFactory();
- this.tagger = newTagger();
- this.classExcluder = newClassExcluder();
- }
-
- protected ValuePropertyFactory newValuePropertyFactory() {
- return new ValuePropertyFactory();
- }
-
- protected ClassExcluder newClassExcluder() {
- return new ClassExcluder();
- }
-
- protected Tagger newTagger() {
- return new Tagger();
+ this.tagger = tagger;
+ this.classExcluder = classExcluder;
+ this.valuePropertyFactory = valuePropertyFactory;
}
Swagger generate() {
@@ -121,12 +107,36 @@ class Generation {
appendDefinitionsForOrphanedReferences();
+ swagger.setPaths(sorted(swagger.getPaths()));
+
return swagger;
}
+ private Map<String, Path> sorted(Map<String, Path> paths) {
+
+ final List<Map.Entry<String, Path>> entries = new ArrayList<>(paths.entrySet());
+ entries.sort(new Comparator<Map.Entry<String, Path>>() {
+ @Override
+ public int compare(Map.Entry<String, Path> o1, Map.Entry<String, Path> 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(Map.Entry<String, Path> o1) {
+ return o1.getValue().getOperations().stream().findFirst().map(operation -> operation.getTags().stream().findFirst().orElse("(no tag)")).orElse("(no tag)");
+ }
+ });
+
+ final LinkedHashMap<String, Path> sorted = new LinkedHashMap<>();
+ entries.forEach(entry -> sorted.put(entry.getKey(), entry.getValue()));
+
+ return sorted;
+ }
+
void appendServicePathsAndDefinitions() {
- // (previously we took a protective copy to avoid a concurrent modification exception,
- // but this is now done by SpecificationLoader itself)
+
for (val spec : specificationLoader.snapshotSpecifications()) {
val domainServiceFacet = spec.getFacet(DomainServiceFacet.class);
@@ -166,15 +176,6 @@ class Generation {
}
}
- // @SuppressWarnings("unused")
- // private void debugAllLoadedClasses(final Collection<ObjectSpecification> allSpecs) {
- // final ImmutableList<String> specs = FluentIterable.from(allSpecs)
- // .transform((final ObjectSpecification objectSpecification)->
- // objectSpecification.getCorrespondingClass().getName())
- // .toSortedList(Ordering.natural());
- // final String all = Joiner.on(",").join(specs);
- // System .out.println(all);
- // }
void appendObjectPathsAndDefinitions() {
// (previously we took a protective copy to avoid a concurrent modification exception,
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/SwaggerSpecGenerator.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/SwaggerSpecGenerator.java
index 9a2c5f8..ae679c4 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/SwaggerSpecGenerator.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/SwaggerSpecGenerator.java
@@ -22,17 +22,32 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.isis.applib.services.swagger.SwaggerService;
import org.apache.isis.metamodel.specloader.SpecificationLoader;
+import org.springframework.stereotype.Component;
import io.swagger.models.Swagger;
import io.swagger.util.Json;
import io.swagger.util.Yaml;
+import javax.inject.Inject;
+
+@Component
public class SwaggerSpecGenerator {
private final SpecificationLoader specificationLoader;
+ private final Tagger tagger;
+ private final ClassExcluder classExcluder;
+ private final ValuePropertyFactory valuePropertyFactory;
- public SwaggerSpecGenerator(final SpecificationLoader specificationLoader) {
+ @Inject
+ public SwaggerSpecGenerator(
+ final SpecificationLoader specificationLoader,
+ final Tagger tagger,
+ final ClassExcluder classExcluder,
+ final ValuePropertyFactory valuePropertyFactory) {
this.specificationLoader = specificationLoader;
+ this.tagger = tagger;
+ this.classExcluder = classExcluder;
+ this.valuePropertyFactory = valuePropertyFactory;
}
public String generate(
@@ -58,7 +73,12 @@ public class SwaggerSpecGenerator {
}
protected Generation newGeneration(final String basePath, final SwaggerService.Visibility visibility) {
- return new Generation(basePath, visibility, specificationLoader);
+ return new Generation(
+ basePath, visibility,
+ specificationLoader,
+ tagger,
+ classExcluder,
+ valuePropertyFactory);
}
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Tagger.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Tagger.java
index eff6cb9..501d6a7 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Tagger.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Tagger.java
@@ -18,67 +18,11 @@
*/
package org.apache.isis.metamodel.services.swagger.internal;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import org.apache.isis.applib.annotation.Programmatic;
-class Tagger {
+public interface Tagger {
-
- static Pattern tagSpringFramework = Pattern.compile("^org\\.springframework\\.([^\\.]+)\\.(.+)$");
- static Pattern tagPatternIsisExtensions = Pattern.compile("^org\\.apache\\.isis\\.extensions\\.([^\\.]+)\\.(.+)$");
- static Pattern tagPatternIsisAddons = Pattern.compile("^org\\.isisaddons\\.module\\.([^\\.]+)\\.(.+)$");
- static Pattern tagPatternIncodeCatalog = Pattern.compile("^org\\.incode\\.module\\.([^\\.]+)\\.(.+)$");
- static Pattern tagPatternForFqcn = Pattern.compile("^.*\\.([^\\.]+)\\.([^\\.]+)$");
- static Pattern tagPatternForTwoParts = Pattern.compile("^([^\\.]+)\\.([^\\.]+)$");
- static Pattern tagPatternForJaxbDto = Pattern.compile("^.*\\.([^\\.]+)\\.(v[0-9][^\\.]*)\\.([^\\.]+)$");
-
- String tagForObjectType(final String objType, final String fallback) {
- if (objType.startsWith("org.apache.isis.")) {
- return "> apache isis internals";
- }
-
- Matcher matcher;
- matcher = tagSpringFramework.matcher(objType);
- if (matcher.matches()) {
- return "> spring framework " + matcher.group(1);
- }
- matcher = tagPatternIsisExtensions.matcher(objType);
- if (matcher.matches()) {
- return "apache isis extensions " + matcher.group(1);
- }
- matcher = tagPatternIsisAddons.matcher(objType);
- if (matcher.matches()) {
- return "isisaddons.org " + matcher.group(1);
- }
- matcher = tagPatternIncodeCatalog.matcher(objType);
- if (matcher.matches()) {
- return "catalog.incode.org " + matcher.group(1);
- }
- matcher = tagPatternForJaxbDto.matcher(objType);
- if (matcher.matches()) {
- return matcher.group(1);
- }
- matcher = tagPatternForFqcn.matcher(objType);
- if (matcher.matches()) {
- return matcher.group(1);
- }
- matcher = tagPatternForTwoParts.matcher(objType);
- if (matcher.matches()) {
- if (objType.startsWith("isisApplib")) {
- return "> apache isis applib";
- }
- if (objType.startsWith("isissecurity")) {
- return "> apache isis extensions";
- }
- // special cases for other Isis addons, eg "isisxxxx"
- if (objType.startsWith("isis")) {
- return "isisaddons " + objType.substring(4, objType.indexOf("."));
- }
-
- return matcher.group(1);
- }
-
- return fallback != null? fallback: objType;
- }
+ @Programmatic
+ String tagForObjectType(String objType, String fallback);
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Tagger.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/TaggerDefault.java
similarity index 70%
copy from core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Tagger.java
copy to core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/TaggerDefault.java
index eff6cb9..d53ff1d 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Tagger.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/TaggerDefault.java
@@ -21,18 +21,23 @@ package org.apache.isis.metamodel.services.swagger.internal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-class Tagger {
+import org.apache.isis.applib.annotation.Programmatic;
+import org.springframework.stereotype.Component;
+
+@Component
+public class TaggerDefault implements Tagger {
-
static Pattern tagSpringFramework = Pattern.compile("^org\\.springframework\\.([^\\.]+)\\.(.+)$");
+ static Pattern tagPatternIsisExtensions2 = Pattern.compile("^isisExt(.+)$");
static Pattern tagPatternIsisExtensions = Pattern.compile("^org\\.apache\\.isis\\.extensions\\.([^\\.]+)\\.(.+)$");
- static Pattern tagPatternIsisAddons = Pattern.compile("^org\\.isisaddons\\.module\\.([^\\.]+)\\.(.+)$");
- static Pattern tagPatternIncodeCatalog = Pattern.compile("^org\\.incode\\.module\\.([^\\.]+)\\.(.+)$");
static Pattern tagPatternForFqcn = Pattern.compile("^.*\\.([^\\.]+)\\.([^\\.]+)$");
static Pattern tagPatternForTwoParts = Pattern.compile("^([^\\.]+)\\.([^\\.]+)$");
static Pattern tagPatternForJaxbDto = Pattern.compile("^.*\\.([^\\.]+)\\.(v[0-9][^\\.]*)\\.([^\\.]+)$");
- String tagForObjectType(final String objType, final String fallback) {
+ @Override
+ @Programmatic
+ public String tagForObjectType(final String objType, final String fallback) {
+
if (objType.startsWith("org.apache.isis.")) {
return "> apache isis internals";
}
@@ -44,15 +49,7 @@ class Tagger {
}
matcher = tagPatternIsisExtensions.matcher(objType);
if (matcher.matches()) {
- return "apache isis extensions " + matcher.group(1);
- }
- matcher = tagPatternIsisAddons.matcher(objType);
- if (matcher.matches()) {
- return "isisaddons.org " + matcher.group(1);
- }
- matcher = tagPatternIncodeCatalog.matcher(objType);
- if (matcher.matches()) {
- return "catalog.incode.org " + matcher.group(1);
+ return "> apache isis extensions - " + matcher.group(1);
}
matcher = tagPatternForJaxbDto.matcher(objType);
if (matcher.matches()) {
@@ -67,14 +64,11 @@ class Tagger {
if (objType.startsWith("isisApplib")) {
return "> apache isis applib";
}
- if (objType.startsWith("isissecurity")) {
- return "> apache isis extensions";
- }
- // special cases for other Isis addons, eg "isisxxxx"
- if (objType.startsWith("isis")) {
- return "isisaddons " + objType.substring(4, objType.indexOf("."));
+
+ if (objType.startsWith("isisExt")) {
+ return "> apache isis extensions - " + matcher.group(1);
}
-
+
return matcher.group(1);
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ValuePropertyFactory.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ValuePropertyFactory.java
index 6e1d4b6..a00f88f 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ValuePropertyFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ValuePropertyFactory.java
@@ -18,123 +18,8 @@
*/
package org.apache.isis.metamodel.services.swagger.internal;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.function.Supplier;
-
-import org.joda.time.DateTime;
-import org.joda.time.LocalDate;
-import org.joda.time.LocalDateTime;
-
-import org.apache.isis.commons.internal.collections._Lists;
-import org.apache.isis.commons.internal.collections._Maps;
-import org.apache.isis.commons.internal.context._Plugin;
-import org.apache.isis.metamodel.services.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;
-
-public class ValuePropertyFactory {
-
- private final Map<Class<?>, Factory> propertyFactoryByClass = _Maps.newHashMap();
-
- public static interface Factory extends Supplier<Property> {};
-
- public ValuePropertyFactory() {
-
- propertyFactoryByClass.put(boolean.class, BooleanProperty::new);
- propertyFactoryByClass.put(Boolean.class, BooleanProperty::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(long.class, LongProperty::new);
- propertyFactoryByClass.put(Long.class, LongProperty::new);
- propertyFactoryByClass.put(java.sql.Timestamp.class, LongProperty::new);
-
- propertyFactoryByClass.put(BigDecimal.class, DecimalProperty::new);
-
- propertyFactoryByClass.put(float.class, FloatProperty::new);
- propertyFactoryByClass.put(Float.class, FloatProperty::new);
-
- propertyFactoryByClass.put(double.class, DoubleProperty::new);
- propertyFactoryByClass.put(Double.class, DoubleProperty::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(UUID.class, UUIDProperty::new);
-
- propertyFactoryByClass.put(java.util.Date.class, DateTimeProperty::new);
- propertyFactoryByClass.put(DateTime.class, DateTimeProperty::new);
- propertyFactoryByClass.put(LocalDateTime.class, DateTimeProperty::new);
-
- propertyFactoryByClass.put(java.sql.Date.class, DateProperty::new);
- propertyFactoryByClass.put(LocalDate.class, DateProperty::new);
-
- propertyFactoryByClass.put(byte[].class, ByteArrayProperty::new);
- propertyFactoryByClass.put(org.apache.isis.applib.value.Blob.class, ByteArrayProperty::new);
-
- // add propertyFactories from plugins
- discoverValueProperties().visitEntries(propertyFactoryByClass::put);
-
- }
-
- public Property newProperty(Class<?> cls) {
- if(cls == null) {
- return null;
- }
-
- final Factory factory = propertyFactoryByClass.get(cls);
- if(factory != null) {
- return factory.get();
- }
-
- // special case, want to treat as a value
- if(cls.isEnum()) {
- final StringProperty property = new StringProperty();
- final Object[] enumConstants = cls.getEnumConstants();
-
- final List<String> enumNames = _Lists.map(
- Arrays.asList(enumConstants), input->((Enum<?>)input).name());
- property.setEnum(enumNames);
- return property;
- }
-
- return null;
- }
-
- // -- HELPER
-
- private static ValuePropertyCollector discoverValueProperties() {
- final Set<ValuePropertyPlugin> plugins = _Plugin.loadAll(ValuePropertyPlugin.class);
- final ValuePropertyCollector collector = ValuePropertyPlugin.collector();
- plugins.forEach(plugin->{
- plugin.plugin(collector);
- });
- return collector;
- }
+public interface ValuePropertyFactory {
+ Property newProperty(Class<?> cls);
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ValuePropertyFactory.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ValuePropertyFactoryDefault.java
similarity index 96%
copy from core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ValuePropertyFactory.java
copy to core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ValuePropertyFactoryDefault.java
index 6e1d4b6..8fc57c0 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ValuePropertyFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ValuePropertyFactoryDefault.java
@@ -35,6 +35,7 @@ import org.apache.isis.commons.internal.collections._Lists;
import org.apache.isis.commons.internal.collections._Maps;
import org.apache.isis.commons.internal.context._Plugin;
import org.apache.isis.metamodel.services.swagger.internal.ValuePropertyPlugin.ValuePropertyCollector;
+import org.springframework.stereotype.Component;
import io.swagger.models.properties.BooleanProperty;
import io.swagger.models.properties.ByteArrayProperty;
@@ -49,13 +50,14 @@ import io.swagger.models.properties.Property;
import io.swagger.models.properties.StringProperty;
import io.swagger.models.properties.UUIDProperty;
-public class ValuePropertyFactory {
+@Component
+public class ValuePropertyFactoryDefault implements ValuePropertyFactory {
private final Map<Class<?>, Factory> propertyFactoryByClass = _Maps.newHashMap();
public static interface Factory extends Supplier<Property> {};
- public ValuePropertyFactory() {
+ public ValuePropertyFactoryDefault() {
propertyFactoryByClass.put(boolean.class, BooleanProperty::new);
propertyFactoryByClass.put(Boolean.class, BooleanProperty::new);
@@ -102,6 +104,7 @@ public class ValuePropertyFactory {
}
+ @Override
public Property newProperty(Class<?> cls) {
if(cls == null) {
return null;
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ValuePropertyPlugin.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ValuePropertyPlugin.java
index 9926d6b..112c554 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ValuePropertyPlugin.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/ValuePropertyPlugin.java
@@ -23,15 +23,15 @@ import java.util.Objects;
import java.util.function.BiConsumer;
import org.apache.isis.commons.internal.collections._Maps;
-import org.apache.isis.metamodel.services.swagger.internal.ValuePropertyFactory.Factory;
+import org.apache.isis.metamodel.services.swagger.internal.ValuePropertyFactoryDefault.Factory;
public interface ValuePropertyPlugin {
// -- CONTRACT
public static interface ValuePropertyCollector {
- public void addValueProperty(final Class<?> cls, final ValuePropertyFactory.Factory factory);
- public void visitEntries(BiConsumer<Class<?>, ValuePropertyFactory.Factory> visitor);
+ public void addValueProperty(final Class<?> cls, final ValuePropertyFactoryDefault.Factory factory);
+ public void visitEntries(BiConsumer<Class<?>, ValuePropertyFactoryDefault.Factory> visitor);
}
public static ValuePropertyCollector collector() {
diff --git a/core/metamodel/src/test/java/org/apache/isis/metamodel/services/swagger/internal/GenerationTest.java b/core/metamodel/src/test/java/org/apache/isis/metamodel/services/swagger/internal/GenerationTest.java
index 0800c83..0c317ae 100644
--- a/core/metamodel/src/test/java/org/apache/isis/metamodel/services/swagger/internal/GenerationTest.java
+++ b/core/metamodel/src/test/java/org/apache/isis/metamodel/services/swagger/internal/GenerationTest.java
@@ -31,7 +31,7 @@ public class GenerationTest {
@Test
public void testAddReference() throws Exception {
- Generation context = new Generation(null, null, null);
+ Generation context = new Generation(null, null, null, new TaggerDefault(), new ClassExcluderDefault(), new ValuePropertyFactoryDefault());
context.addSwaggerReference("foo");
context.addSwaggerReference("bar");
diff --git a/core/metamodel/src/test/java/org/apache/isis/metamodel/services/swagger/internal/TaggerTest.java b/core/metamodel/src/test/java/org/apache/isis/metamodel/services/swagger/internal/TaggerTest.java
index 66ddac0..0e719ac 100644
--- a/core/metamodel/src/test/java/org/apache/isis/metamodel/services/swagger/internal/TaggerTest.java
+++ b/core/metamodel/src/test/java/org/apache/isis/metamodel/services/swagger/internal/TaggerTest.java
@@ -30,49 +30,49 @@ public class TaggerTest {
@Test
public void fullyQualifiedClass() throws Exception {
- String tag = new Tagger().tagForObjectType("foo.bar.Abc", null);
+ String tag = new TaggerDefault().tagForObjectType("foo.bar.Abc", null);
assertThat(tag, is(equalTo("bar")));
}
@Test
public void jaxb() throws Exception {
- String tag = new Tagger().tagForObjectType("todoapp.app.viewmodels.todoitem.v1_0.ToDoItemDto", null);
+ String tag = new TaggerDefault().tagForObjectType("todoapp.app.viewmodels.todoitem.v1_0.ToDoItemDto", null);
assertThat(tag, is(equalTo("todoitem")));
}
@Test
public void schemaClass() throws Exception {
- String tag = new Tagger().tagForObjectType("bar.Abc", null);
+ String tag = new TaggerDefault().tagForObjectType("bar.Abc", null);
assertThat(tag, is(equalTo("bar")));
}
@Test
public void noPackage() throws Exception {
- String tag = new Tagger().tagForObjectType("Abc", null);
+ String tag = new TaggerDefault().tagForObjectType("Abc", null);
assertThat(tag, is(equalTo("Abc")));
}
@Test
public void isisAddons() throws Exception {
- String tag = new Tagger().tagForObjectType("org.isisaddons.module.security.app.feature.ApplicationClass", null);
+ String tag = new TaggerDefault().tagForObjectType("org.isisaddons.module.security.app.feature.ApplicationClass", null);
assertThat(tag, is(equalTo("isisaddons.org security")));
}
@Test
public void incodeCatalog() throws Exception {
- String tag = new Tagger().tagForObjectType("org.incode.module.communications.foo.bar.FooBar", null);
+ String tag = new TaggerDefault().tagForObjectType("org.incode.module.communications.foo.bar.FooBar", null);
assertThat(tag, is(equalTo("catalog.incode.org communications")));
}
@Test
public void internals() throws Exception {
- String tag = new Tagger().tagForObjectType("org.apache.isis.applib.fixturescripts.FixtureResult", null);
+ String tag = new TaggerDefault().tagForObjectType("org.apache.isis.applib.fixturescripts.FixtureResult", null);
assertThat(tag, is(equalTo("> apache isis internals")));
}
@Test
public void applib() throws Exception {
- String tag = new Tagger().tagForObjectType("isisApplib.ConfigurationServiceMenu", null);
+ String tag = new TaggerDefault().tagForObjectType("isisApplib.ConfigurationServiceMenu", null);
assertThat(tag, is(equalTo("> apache isis applib")));
}
diff --git a/extensions/testing/fixtures/src/main/java/org/apache/isis/extensions/fixtures/fixturescripts/FixtureResult.java b/extensions/testing/fixtures/src/main/java/org/apache/isis/extensions/fixtures/fixturescripts/FixtureResult.java
index 701c189..3933718 100644
--- a/extensions/testing/fixtures/src/main/java/org/apache/isis/extensions/fixtures/fixturescripts/FixtureResult.java
+++ b/extensions/testing/fixtures/src/main/java/org/apache/isis/extensions/fixtures/fixturescripts/FixtureResult.java
@@ -42,7 +42,7 @@ import lombok.Setter;
@DomainObject(
nature = Nature.VIEW_MODEL,
- objectType = "extFixture.FixtureResult"
+ objectType = "isisExtFixture.FixtureResult"
)
@ViewModelLayout(paged=500)
@XmlRootElement(name = "fixtureResult")