What is the use of star(*) in yaml file?

Viewed 7330

I was going through spring boot actuator when I stumbled upon this quote:

* has a special meaning in YAML, so be sure to add quotes if you want to include (or exclude) all endpoints.

I tried to look over the internet about it without any luck. What is the use of * in yaml file?

2 Answers

* is used to remove the repeated nodes. Consider this yaml example:

myprop:
  uid: &id XXX
myprop1:
  id: *id

The above will expand to:

myprop:
  uid: XXX
myprop1:
  id: XXX

Now try running this code:

@Value("${myprop.uid}") String uid;
@Value("${myprop1.id}") String id;

@Bean
ApplicationRunner runner() {
    return args -> {
        System.out.println(uid);  // prints "XXX"
        System.out.println(id); // prints "XXX"
        System.out.println(uid.equals(id)); // prints "true"
    };
}

From the spec:

Repeated nodes (objects) are first identified by an anchor (marked with the ampersand - “&”), and are then aliased (referenced with an asterisk - “*”) thereafter.

It depends on the context of the YAML file. You said you was going through spring boot actuator, so you can take a look into the reference documentation of Spring Boot, the chapter 5.2.2. Exposing Endpoints to be exact.

* can be used to select all endpoints. For example, to expose everything over HTTP except the env and beans endpoints, use the following properties:

management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=env,beans

The asterisk * means that all the endpoints that belongs to a certain category are either included or exluded.

The sentence below just says that the asterisk * character must be quoted "*" in case of the YAML format usage over classic properties file.

* has a special meaning in YAML, so be sure to add quotes if you want to include (or exclude) all endpoints, as shown in the following example:

By the way, this sentence is the same one you have sited at your question.

Related