Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:

- name: Generate new public Json Schema
shell: bash
run: ./mvnw install -Dmaven.plugin.validation=NONE -DskipSign -ntp -P framework-only
run: ./mvnw install -DskipTests -Dmaven.plugin.validation=NONE -DskipSign -ntp -P framework-only

- name: Commit files and generate new tag
run: |
Expand Down
29 changes: 17 additions & 12 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,12 @@ config:
priority: 0 # Sets the order of evaluation of this interpolator among others. Higher priority wins.
prefix: spectrum # Variable prefix
delimiter: . # Variable tokens' delimiter
transformCase: none # Function to specify how to transform the original camelCase of the key to match the external variable to search
transformCase: NONE # Function to specify how to transform the original camelCase of the key to match the external variable to search
properties: # Properties interpolator
priority: 1 # Sets the order of evaluation of this interpolator among others. Higher priority wins.
prefix: spectrum # Variable prefix
delimiter: . # Variable tokens' delimiter
transformCase: none # Function to specify how to transform the original camelCase of the key to match the external variable to search
transformCase: NONE # Function to specify how to transform the original camelCase of the key to match the external variable to search
inPlace: # In-place configuration file interpolator
priority: 2 # Sets the order of evaluation of this interpolator among others. Higher priority wins.
enabled: true
Expand All @@ -669,6 +669,9 @@ The other keys are explained in the corresponding sections.

### In-place Interpolation

> ⚠️ **Interpolating data*.yaml**<br/>
> The `in-place interpolation` is the only way to inject values into the `data*.yaml`, other interpolators won't work.

You can interpolate values directly in the `configuration*.yaml` and `data*.yaml` with a dollar-string in one of the following two ways,
depending on the type needed as result. Let's suppose we have the variable `key = 123`:

Expand Down Expand Up @@ -842,10 +845,11 @@ config:
priority: 0
prefix: spectrum
delimiter: .
transformCase: none
transformCase: NONE
```

This means every configuration key will be searched in env vars, with the `spectrum` prefix and words delimited by a dot.
The name of the variable to resolve is the json path of the corresponding configuration key.
For instance, you can inject the `application.baseUrl` setting an env variable named `spectrum.application.baseUrl`.

To give you another example, you can use this config to inject env vars like `APPLICATION_BASEURL`:
Expand All @@ -858,16 +862,16 @@ config:
environment:
prefix: ''
delimiter: _
transformCase: upper
transformCase: UPPER
```

Allowed values for the `transformCase` property are:

| Value | Description | Example |
|---------|-----------------------------------------------------------------------------------|---------------------|
| `none` | searches a key with the same case of the property, which is `camelCase` (default) | application.baseUrl |
| `lower` | searches a lowercase key | application.baseurl |
| `upper` | searches a uppercase key | APPLICATION.BASEURL |
| `NONE` | searches a key with the same case of the property, which is `camelCase` (default) | application.baseUrl |
| `LOWER` | searches a lowercase key | application.baseurl |
| `UPPER` | searches a uppercase key | APPLICATION.BASEURL |

> ⚠️ **Priority**<br/>
> Pay attention to the priority: by default, the `inPlace` interpolator takes precedence over this one.
Expand Down Expand Up @@ -899,10 +903,11 @@ config:
priority: 1
prefix: spectrum
delimiter: .
transformCase: none
transformCase: NONE
```

This means every configuration key will be searched in system properties, with the `spectrum` prefix and words delimited by a dot.
The name of the variable to resolve is the json path of the corresponding configuration key.
For instance, you can inject the `application.baseUrl` setting the system property `-Dspectrum.application.baseUrl`.

To give you another example, you can use this config to inject system properties like `-DAPPLICATION_BASEURL`:
Expand All @@ -915,16 +920,16 @@ config:
properties:
prefix: ''
delimiter: _
transformCase: upper
transformCase: UPPER
```

Allowed values for the `transformCase` property are:

| Value | Description | Example |
|---------|-----------------------------------------------------------------------------------|---------------------|
| `none` | searches a key with the same case of the property, which is `camelCase` (default) | application.baseUrl |
| `lower` | searches a lowercase key | application.baseurl |
| `upper` | searches a uppercase key | APPLICATION.BASEURL |
| `NONE` | searches a key with the same case of the property, which is `camelCase` (default) | application.baseUrl |
| `LOWER` | searches a lowercase key | application.baseurl |
| `UPPER` | searches a uppercase key | APPLICATION.BASEURL |

> ⚠️ **Priority**<br/>
> Pay attention to the priority: by default, the `inPlace` interpolator takes precedence over this one.
Expand Down
2 changes: 1 addition & 1 deletion it/src/test/resources/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ config:
environment:
priority: 10
delimiter: _
transformCase: upper
transformCase: UPPER
properties: { }

application:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
import java.util.function.Function;

import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonStreamContext;

import lombok.AllArgsConstructor;
import lombok.Generated;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -73,17 +71,10 @@ void getKeyPathTokens(final List<String> accumulator, final JsonStreamContext co
@AllArgsConstructor
enum TransformCase {

NONE("none", s -> s),
LOWER("lower", String::toLowerCase),
UPPER("upper", String::toUpperCase);
NONE(s -> s),
LOWER(String::toLowerCase),
UPPER(String::toUpperCase);

private final String value;
private final Function<String, String> function;

@JsonValue
@Generated
public String getValue() {
return value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public void applyToConfigBuilder(final SchemaGeneratorConfigBuilder schemaGenera
protected SchemaGeneratorConfigBuilder commonSetupFor(final SchemaGeneratorConfigBuilder schemaGeneratorConfigBuilder) {
schemaGeneratorConfigBuilder
.with(new JacksonModule(SKIP_SUBTYPE_LOOKUP, FLATTENED_ENUMS_FROM_JSONVALUE))
.with(FORBIDDEN_ADDITIONAL_PROPERTIES_BY_DEFAULT, MAP_VALUES_AS_ADDITIONAL_PROPERTIES, NULLABLE_FIELDS_BY_DEFAULT);
.with(FORBIDDEN_ADDITIONAL_PROPERTIES_BY_DEFAULT,
MAP_VALUES_AS_ADDITIONAL_PROPERTIES,
TRANSIENT_FIELDS,
NULLABLE_FIELDS_BY_DEFAULT);

schemaGeneratorConfigBuilder
.forFields()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ public class Configuration {
private static final Configuration INSTANCE = new Configuration();

@Setter
@JsonIgnore
@JsonPropertyDescription("Generic configuration. This node is read only from the base configuration.yaml")
private Config config;
private transient Config config;

@JsonPropertyDescription("Common vars to interpolate other String values in the configuration")
private Map<String, Object> vars;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.giulong.spectrum.utils;

import static com.fasterxml.jackson.databind.MapperFeature.PROPAGATE_TRANSIENT_MARKER;
import static com.fasterxml.jackson.databind.SerializationFeature.FAIL_ON_EMPTY_BEANS;
import static lombok.AccessLevel.PRIVATE;

Expand Down Expand Up @@ -45,6 +46,7 @@ public final class YamlUtils {
private final ObjectMapper yamlMapper = YAMLMapper
.builder()
.defaultMergeable(true)
.configure(PROPAGATE_TRANSIENT_MARKER, true)
.addModules(
new JavaTimeModule(),
buildModuleFor(Object.class, InterpolatedObjectDeserializer.getInstance()),
Expand Down
4 changes: 2 additions & 2 deletions spectrum/src/main/resources/yaml/configuration.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ config:
priority: 0 # Sets the order of evaluation of this interpolator among others. Higher priority wins.
prefix: spectrum # Variable prefix
delimiter: . # Variable tokens' delimiter
transformCase: none # Function to specify how to transform the original camelCase of the key to match the external variable to search
transformCase: NONE # Function to specify how to transform the original camelCase of the key to match the external variable to search
properties: # Properties interpolator
priority: 1 # Sets the order of evaluation of this interpolator among others. Higher priority wins.
prefix: spectrum # Variable prefix
delimiter: . # Variable tokens' delimiter
transformCase: none # Function to specify how to transform the original camelCase of the key to match the external variable to search
transformCase: NONE # Function to specify how to transform the original camelCase of the key to match the external variable to search
inPlace: # In-place configuration file interpolator
priority: 2 # Sets the order of evaluation of this interpolator among others. Higher priority wins.
enabled: true
Expand Down
Loading