Skip to content

Commit

Permalink
save work
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-grecourt committed Sep 23, 2023
1 parent 46d989c commit dcbf62c
Show file tree
Hide file tree
Showing 31 changed files with 250 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import static io.helidon.builder.processor.Types.CONFIG_TYPE;
import static io.helidon.builder.processor.Types.FACTORY_METHOD_TYPE;
import static io.helidon.builder.processor.Types.PROTOTYPE_TYPE;
import static io.helidon.builder.processor.Types.RUNTIME_OBJECT_TYPE;
import static io.helidon.common.types.TypeNames.OBJECT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import io.helidon.common.processor.classmodel.TypeArgument;
import io.helidon.common.types.AccessModifier;
import io.helidon.common.types.TypeName;
import io.helidon.common.types.TypeNames;

import static io.helidon.builder.processor.Types.CHAR_ARRAY_TYPE;
import static io.helidon.builder.processor.Types.CONFIG_TYPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* Hamcrest matchers for {@link java.util.Map}.
*/
public final class MapMatcher {
private MapMatcher() {
}

/**
* A matcher for an {@link java.util.Map} that performs a deep equality.
Expand All @@ -37,6 +39,15 @@ public final class MapMatcher {
* assertThat(actualMap, isMapEqualTo(expectedMap));
* </pre>
*
* This method targets trees implemented using {@link java.util.Map} where values of type {@link java.util.Map}
* are considered tree nodes, and values with other types are considered leaf nodes.
* <p>
* The deep-equality is performed by diffing a flat string representation of each map. If the diff yields no differences,
* the maps are considered deeply equal.
* <p>
* The entries are compared using strings, both keys and leaf nodes must implement {@link Object#toString()}.
*
* @param expected expected map
* @param <K> type of the map keys
* @param <V> type of the map values
* @return matcher validating the {@link java.util.Map} is deeply equal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020 Oracle and/or its affiliates.
* Copyright (c) 2017, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,8 @@ Property defaultProperty() {

private static boolean setupExtensionType(String key, Node valueNode) {
if (isExtension(key)) {
/*
* The nodeId in a node is more like node "category" in SnakeYAML. For those OpenAPI interfaces which implement
* Extensible we need to set the node's type if the extension is a List or Map.
*/
// The nodeId in a node is more like node "category" in SnakeYAML. For those OpenAPI interfaces which implement
// Extensible we need to set the node's type if the extension is a List or Map.
switch (valueNode.getNodeId()) {
case sequence -> {
valueNode.setType(List.class);
Expand All @@ -231,6 +229,9 @@ private static boolean setupExtensionType(String key, Node valueNode) {
valueNode.setType(Map.class);
return true;
}
default -> {
return false;
}
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@
class JsonpAnnotationScannerExtension implements AnnotationScannerExtension {

private static final System.Logger LOGGER = System.getLogger(JsonpAnnotationScannerExtension.class.getName());

private static final JsonReaderFactory JSON_READER_FACTORY = Json.createReaderFactory(Collections.emptyMap());

private static final Representer MISSING_FIELD_TOLERANT_REPRESENTER;

static {
MISSING_FIELD_TOLERANT_REPRESENTER = new Representer(new DumperOptions());
MISSING_FIELD_TOLERANT_REPRESENTER.getPropertyUtils().setSkipMissingProperties(true);
}

private final OpenApiHelper openApiHelper;

JsonpAnnotationScannerExtension(OpenApiHelper openApiHelper) {
this.openApiHelper = openApiHelper;
}

@Override
public Object parseExtension(String key, String value) {
try {
Expand Down Expand Up @@ -93,6 +97,8 @@ public Object parseValue(String value) {
throw ex;
}
}
default -> {
}
}

// Treat as JSON string.
Expand All @@ -101,7 +107,7 @@ public Object parseValue(String value) {

@Override
public Schema parseSchema(String jsonSchema) {
return OpenApiParser.parse(OpenApiHelper.types(),
return OpenApiParser.parse(openApiHelper.types(),
Schema.class,
new StringReader(jsonSchema),
MISSING_FIELD_TOLERANT_REPRESENTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
final class MpOpenApiManager implements OpenApiManager<OpenAPI> {

private static final System.Logger LOGGER = System.getLogger(MpOpenApiManager.class.getName());
private static final List<AnnotationScannerExtension> SCANNER_EXTENSIONS = List.of(new JsonpAnnotationScannerExtension());
private static final String CONFIG_EXT_PREFIX = "mp.openapi.extensions.helidon.";

/**
Expand All @@ -58,14 +57,18 @@ final class MpOpenApiManager implements OpenApiManager<OpenAPI> {

private final MpOpenApiManagerConfig managerConfig;
private final OpenApiConfig openApiConfig;
private final OpenApiHelper openApiHelper;
private final List<AnnotationScannerExtension> scannerExtensions;
private final LazyValue<List<FilteredIndexView>> filteredIndexViews = LazyValue.create(this::buildFilteredIndexViews);

MpOpenApiManager(Config config) {
this.managerConfig = MpOpenApiManagerConfig.builder()
.update(builder -> config.getOptionalValue(USE_JAXRS_SEMANTICS_KEY, Boolean.class)
.ifPresent(builder::useJaxRsSemantics))
.build();
this.openApiHelper = new OpenApiHelper(config);
this.openApiConfig = new OpenApiConfigImpl(config);
this.scannerExtensions = List.of(new JsonpAnnotationScannerExtension(openApiHelper));
}

@Override
Expand All @@ -85,7 +88,7 @@ public OpenAPI load(String content) {
OpenApiDocument.INSTANCE.config(openApiConfig);
OpenApiDocument.INSTANCE.modelFromReader(OpenApiProcessor.modelFromReader(openApiConfig, contextClassLoader));
if (!content.isBlank()) {
OpenAPI document = OpenApiParser.parse(OpenApiHelper.types(), OpenAPI.class, new StringReader(content));
OpenAPI document = OpenApiParser.parse(openApiHelper.types(), OpenAPI.class, new StringReader(content));
OpenApiDocument.INSTANCE.modelFromStaticFile(document);
}
if (!openApiConfig.scanDisable()) {
Expand All @@ -104,7 +107,7 @@ public OpenAPI load(String content) {
@Override
public String format(OpenAPI model, OpenApiFormat format) {
StringWriter sw = new StringWriter();
OpenApiSerializer.serialize(OpenApiHelper.types(), model, format, sw);
OpenApiSerializer.serialize(openApiHelper.types(), model, format, sw);
return sw.toString();
}

Expand All @@ -127,7 +130,7 @@ private void processAnnotations() {
// merging the resulting OpenAPI models into one.
OpenAPI model = new OpenAPIImpl(); // Start with skeletal model
for (IndexView indexView : indexViews) {
OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(openApiConfig, indexView, SCANNER_EXTENSIONS);
OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(openApiConfig, indexView, scannerExtensions);
OpenAPI scanned = scanner.scan();
if (LOGGER.isLoggable(Level.DEBUG)) {
LOGGER.log(Level.DEBUG, String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
@Prototype.Blueprint
@Configured
interface MpOpenApiManagerConfigBlueprint extends SmallRyeOpenApiConfigBlueprint {
interface MpOpenApiManagerConfigBlueprint {

/**
* If {@code true} and the {@code jakarta.ws.rs.core.Application} class returns a non-empty set, endpoints defined by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import java.util.Map;
import java.util.Set;

import io.helidon.common.LazyValue;
import io.helidon.common.config.Config;
import io.helidon.common.config.GlobalConfig;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.openapi.models.Extensible;
import org.eclipse.microprofile.openapi.models.Operation;
import org.eclipse.microprofile.openapi.models.PathItem;
Expand All @@ -44,15 +41,11 @@ final class OpenApiHelper {
private static final java.util.logging.Logger SNAKE_YAML_INTROSPECTOR_LOGGER =
java.util.logging.Logger.getLogger(org.yaml.snakeyaml.introspector.PropertySubstitute.class.getPackage().getName());

private static final LazyValue<Map<Class<?>, ExpandedTypeDescription>> TYPES = LazyValue.create(
() -> new OpenApiHelper().generatedHelper.types());

// The SnakeYAMLParserHelper is generated by a maven plug-in.
private final SnakeYAMLParserHelper<ExpandedTypeDescription> generatedHelper;

private OpenApiHelper() {
Config config = GlobalConfig.config();
boolean warningsEnabled = config.get("openapi.parsing.warnings.enabled").asBoolean().orElse(false);
OpenApiHelper(Config config) {
boolean warningsEnabled = config.getOptionalValue("mp.openapi.parsing.warnings.enabled", Boolean.class).orElse(false);
if (SNAKE_YAML_INTROSPECTOR_LOGGER.isLoggable(java.util.logging.Level.WARNING) && !warningsEnabled) {
SNAKE_YAML_INTROSPECTOR_LOGGER.setLevel(java.util.logging.Level.SEVERE);
}
Expand All @@ -65,8 +58,8 @@ private OpenApiHelper() {
*
* @return types of this helper
*/
static Map<Class<?>, ExpandedTypeDescription> types() {
return TYPES.get();
Map<Class<?>, ExpandedTypeDescription> types() {
return generatedHelper.types();
}

private static void adjustTypeDescriptions(Map<Class<?>, ExpandedTypeDescription> types) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ protected MappingNode representJavaBean(Set<Property> properties, Object javaBea
// property assigned.
MappingNode result = super.representJavaBean(properties, javaBean);

// Now promote the individual sub-nodes for each extension property (if any) up one level so that they are peers of the
// other properties. Also remove the "extensions" node.
// Now promote the individual sub-nodes for each extension property (if any) up one level so that they are peers of
// the other properties. Also remove the "extensions" node.
processExtensions(result, javaBean);

// Clearing representedObjects is an awkward but effective way of preventing SnakeYAML from using anchors and
Expand Down

This file was deleted.

Loading

0 comments on commit dcbf62c

Please sign in to comment.