.properties to .yaml conversion while preserving comment? - spring-boot

Here is an earlier discussion, which asks about - How to convert from application.properties to application.yml in Spring Boot?
The solutions discussed above work but there is a limitation with #comments.
Comments (#comments) in .properties file are not carried forward in to .yaml file after conversion.
So want to check if there is any tool (online/ide based/offline) that supports conversion with comments carried forward into .yaml file.

read each line of the properties file
keep track of the comments
put the grouped property in a data structure together with the comment
write the data structure to the YAML file

Related

Documenting YAML configuration files

We are using YAML as a config file format and want to add comments to it that we can convert to documentation, in the same way that Sphinx Autodoc, Doxygen, or Roxygen (in R) work.
I'm aware of this take that suggests description should be an integral part of the YAML document: Documenting yaml
I disagree with this. Our YAML files are configuration, not data - our documentation should show how to change and adapt the YAML rather than describe what's in the YAML right now.
I found:
http://chrisbcole.me/yamldoc/
https://yamldocs.dev/
https://github.com/Jakski/sphinxcontrib-autoyaml
https://github.com/ted-dunstone/yaml2doc
Neither appears to be in very wide use, am I missing something?

Write header line for empty CSVs using Apache Nifis "CsvRecordSetWriter" Controller and "ConvertRecord" Processor

I'm using NiFi 1.11.4 to read CSV files from an SFTP, do a few transformations and then drop them off on GCS. Some of the files contain no content, only a header line. During my transformations I convert the files to the AVRO format, but when converting back to CSV no file output is produced for the files where the content is empty.
I have the following settings for the Processor:
And for the Controller:
I did find the following topic: How to use ConvertRecord and CSVRecordSetWriter to output header (with no data) in Apache NiFi? but in the comments it mentions explicitly that ConvertRecord should cover this since 1.8. Sadly I understood it incorrectly, it does not seem to work or my setup is wrong.
While I could make it work with by explicitly writing the schema as a line to empty files, I wanted to know if there is also a more elegant way?

How to divide the changelog.yaml into subsections?

I would like to separate each change of the databaseChangeLog in YAML format into its own file (again YAML) and include/import it somehow. It should be in way such that I can use a FileSystemAccessor or ClassPathAccessor to load it again.
Is there some example how to do that?
Thanks,
Dieter
The way to do this is described at https://www.liquibase.org/bestpractices.html
The example given shows XML formatted changelogs, but the basic idea would be the same for YAML formatted changelogs.
Leave me a comment and I can generate a sample in YAML.
After some searching I found this on the liquibase repo:
https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/test/resources/liquibase/parser/core/yaml/doubleNestedChangeLog.yaml
It is an example how you can separate your yaml files analog to the xml as shown by SteveDonies link.

Load only one section from a YAML config file

I have multiple components that each of them needs to load specific definitions for it to run, I want to make one big YAML file divided into sections, that each section will belong to a different component.
So instead of having 4 config files for 4 components I'll have one big config file that divided into sections.
Now I want to load on each component just the relvant section from the yaml config file.
Can I do it? and how?
Update:
Both answers have satisfied me (embedded YAML files in one YAML file and the other answer was to unmarshal the JSON to an object that contains only the relevant section I'm interstring in).
The YAML specification allows to have multiple YAML documents in one file by delimiting them with ---: http://yaml.org/spec/1.2/spec.html#id2760395
You would have to check how the library you're utilizing handles this.

Why should we use yml over properties

If we put spring.datasource.url = url it takes only one line.
However, If we put same thing in .yml it takes 4 lines.
spring :
datasource:
url : url
Yet developers and frameworks(like Spring) prefer .yml over .properties.
Why should we use .yml over .properties file?
Some Googling would have definitely helped you.
Ex : From http://javajee.com/a-quick-comparison-of-yaml-with-properties-file ,
YAML supports Maps, lists and scalar types. YAML is hierarchical and may use consistent spaces to denote hierarchy.
and,
Properties file is mainly used with Java, supports only String types and is non-hierarchical; we can have maps by denoting hierarchies as dots
Another long and descriptive guide is http://hsoienterprises.com/2014/03/10/property-list-vs-json-vs-yaml/ , which I'll leave for you to read.

Resources