Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I have a configuration file in YAML which contains strings, floats, integers and a list. I would like, when the YAML is loaded to return the list a numpy array. So, for example, if the YAML is as follows:. Of course, this could easily be done outside YAML with something like numpy. So for example, the following fails:. Changing the tag to!!
Dumping a numpy array with the data that you get, will get you a vastly more complex YAML file than what you can get by just adding a tag. I therefore recommend that you just define a tag of your own that causess the data as you have it to load, and then convert to numpy on the fly. That way you don't have to walk over the resulting loaded structure to find score or its value. You also have to realize that the value for score in that file is a plain multi-line scalar, that will get loaded as the string '-- 19 - 45 -- 21 - 12 -- 32 - 13'.
If in your input the value for score would be sequence of sequences, which requires a space after the -that only then gets interpreted as a sequence entry indicator:. Learn more. Asked 1 year, 2 months ago. Active 6 months ago. Viewed 2k times. So for example, the following fails: score:!! How can I make this work? I am using Python v. Serge Stroobandt Aenaon Aenaon 1, 2 2 gold badges 14 14 silver badges 31 31 bronze badges. There is no list i. Active Oldest Votes.
Anthon Anthon It's yaml. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Programming tutorials can be a real drag. Featured on Meta.GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Have a question about this project?
Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Already on GitHub?
YAML Tutorial: Everything You Need to Get Started in Minutes
Sign in to your account. I need to parse some files and some fields can either include an array of strings or can just include 1 element that's inlined. How do I parse such a file? I tried field string but that of course only works for the bottom example and field string only works for the top one.
I thought maybe field string ",inline" but that's limited to structs. Any idea on how to achieve it? One, could think of the inlined string as an array of 1 length Using this I always have a slice in the unmarshaled struct, which gets a single element in case the YAML was a single value.
Note that in this example, attrs: had arbitrary key names so I used a map. You can as well use a struct, if the names are fixed:. You have just taught me how to use this library even more effectively. I did not realize there was an Unmarshaler type! I can now parse some other more complex values right from the beginning. Very awesome. You closed the issue, but I still think this is an issue. It would be great if one could do something like:. Skip to content.This YAML tutorial will demonstrate the language syntax with a guide and some simple coding examples in Python.
YAML has broad language support and maps easily into native data structures. The file starts with three dashes. These dashes indicate the start of a new YAML document.
YAML supports multiple documents, and compliant parsers will recognize each set of dashes as the beginning of a new one.
Next, we see the construct that makes up most of a typical YAML document: a key-value pair. YAML supports more than just string values. The file starts with six key-value pairs. They have four different data types. Doe and ray are strings. Pi is a floating-point number. Xmas is a boolean. French-hens is an integer. You can enclose strings in single or double-quotes or no quotes at all. YAML recognizes unquoted numerals as integers or floating point. The seventh item is an array. Calling-birds has four elements, each denoted by an opening dash.
I indented the elements in calling-birds with two spaces. Indentation is how YAML denotes nesting. The number of spaces can vary from file to file, but tabs are not allowed.
Finally, we see xmas-fifth-daywhich has five more elements inside it, each of them indented.
We can view xmas-fifth-day as a dictionary that contains two string, two integers, and another dictionary. YAML supports nesting of key-values, and mixing types. Unless otherwise indicated, newlines indicate the end of a field. You structure a YAML document with indentation. The indentation level can be one or more spaces. The specification forbids tabs because tools treat them differently.
Environment YAML Configuration File
YAML recognizes numeric types. We saw floating point and integers above. YAML supports several other numeric types. As you expect, Ox indicates a value is hex, and a leading zero denotes an octal value.Specifically, it implements the minimum set of features needed to use YAML as a configuration file format.
Strings in YAML can be wrapped both in single and double quotes. In some cases, they can also be unquoted:. Quoted styles are useful when a string starts or end with one or more relevant spaces, because unquoted strings are trimmed on both end when parsing their contents.
Quotes are required when the string contains special or reserved characters. When using single-quoted strings, any single quote ' inside its contents must be doubled to escape it:. Strings containing any of the following characters must be quoted. If the string contains any of the following control characters, it must be escaped with double quotes:.
Finally, there are other cases when the strings must be quoted, no matter if you're using single or double quotes:. When a string contains line breaks, you can use the literal style, indicated by the pipeto indicate that the string will span several lines. In literals, newlines are preserved:. Notice the two spaces before each line in the previous examples. They won't appear in the resulting PHP strings.
Booleans in YAML are expressed with true and false. A YAML file is rarely used to describe a simple scalar. Most of the time, it describes a collection. There is one important thing you need to remember when using indentation in a YAML file: Indentation must be done with one or more spaces, but never with tabulators.
YAML can also use flow styles for collections, using explicit indicators rather than indentation to denote scope. A sequence can be written as a comma separated list within square brackets  :. Comments can be added in YAML by prefixing them with a hash mark :. Comments are ignored by the YAML parser and do not need to be indented according to the current level of nesting in a collection.
Disneyland Paris Dec. Lille France February 28 Paris France TBA. Warszawa Poland October Berlin Germany Oct. Maintained 3. In some cases, they can also be unquoted: 1 2 3 4 5. Note Notice the two spaces before each line in the previous examples. Sequences use a dash followed by a space: 1 2 3.
PHP : 5. Note In a mapping, a key can be any valid scalar. Comment on a line "symfony 1. Note Comments are ignored by the YAML parser and do not need to be indented according to the current level of nesting in a collection.It includes a catalog of all supported YAML capabilities and the available options.
The best way to get started with YAML pipelines is to read the quickstart guide. After that, to learn how to configure your YAML pipeline for your needs, see conceptual topics like Build variables and Jobs. Stages are the major divisions in a pipeline. The stages "Build this app," "Run these tests," and "Deploy to preproduction" are good examples. A stage is one or more jobs, which are units of work assignable to the same machine.
You can arrange both stages and jobs into dependency graphs. Examples include "Run this stage before that one" and "This job depends on the output of that job. A job is a linear series of steps. Steps can be tasks, scripts, or references to external templates.
Simple pipelines don't require all of these levels. For example, in a single-job build you can omit the containers for stages and jobs because there are only steps. And because many options shown in this article aren't required and have good defaults, your YAML definitions are unlikely to include all of them. A job is a unit of work assignable to the same machine. You can arrange jobs into dependency graphs like "This job depends on the output of that job. For single-job pipelines, you can omit the jobs container because there are only steps.
Unsupported features include anchors, complex keys, and sets. Also, unlike standard YAML, Azure Pipelines depends on seeing stagejobtaskor a task shortcut like script as the first key in a mapping. If you have a single stageyou can omit the stages keyword and directly specify the jobs keyword:. If you have a single stage and a single job, you can omit the stages and jobs keywords and directly specify the steps keyword:. If you have a single job, you can omit the jobs keyword and directly specify the steps keyword:.
A stage is a collection of related jobs. By default, stages run sequentially. Each stage starts only after the preceding stage is complete. Use approval checks to manually control when a stage should run. These checks are commonly used to control deployments to production environments.
Checks are a mechanism available to the resource owner. They control when a stage in a pipeline consumes a resource. As an owner of a resource like an environment, you can define checks that are required before a stage that consumes the resource can start.GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Already on GitHub? Sign in to your account.
First off, merge keys for objects use regular YAML syntax. In YAML 1. It will become an optional feature. Programatic features should not have ever been encouraged. Depending on your loader implementation you might be able to hook into the loading process to do that. Hi ingydotnetthanks for your explanation.
Much appreciated. To what end? It's absolutely acceptable to want to say "hey, this config over here is the same as the one over there, except toss this in too. Please reconsider this decision. Yaml is used in many places where one has no control over the parsing side. It's special meaning is enabled by applying a schema. That means the parser does not know anything about merging.
It is not syntax. Only the loader knows what to do with the scalar elements. It also decides if it should convert the string TRUE to a boolean or not. First, this is already valid syntax. Second, to support this, we would also have to invent a completely new syntax element.
YAML syntax is already too complex, and suggestions for 1. From experience we know that the complex syntax and the absence of a test suite resulted in many parser differences. There are suggestions on how to get more generic programmatic features into YAML that would just add one new syntax element set and leave the implementation to a higher level. I can confirm, this is happening to me. I personally understand that it would be useful to have a standard way to do this, and new features in YAML 1.
Your description of an array of string is correct, but the parameter definition misses the name property to be valid. Try the online editor to check your OpenAPI fka.YAML: text blocks
I have created a swagger issue as the help provided by Arnaud, although is valid yaml, will give you NPE exceptions when trying to generate. You will need to provide an object like the following:. Note, the issue has been fixed in version 2. The answer with the most votes got me in the right direction.
I just needed an example of an array of objects where each one of them had a property which was an array of strings with more than one value in the strings array.
Thanks to the documentation I got it working like this:. One thing to keep in mind is that indentation is of paramount importance to swagger. If you don't indent things well, swagger will give you strange error messages. None of the answers worked for me. As it is stated in the following Baeldung article :. To better document the API and instruct the user, we can use the example label of how to insert values.
You can check how the Example Value is now better informed in the Swagger editor. Learn more. Asked 3 years, 7 months ago.
Active 3 months ago. Viewed 39k times. I would like to post an array of strings like [ "id1", "id2" ] to a Swagger based API. Achim Achim Active Oldest Votes. Here's a full working example: swagger: "2. Arnaud Lauret Arnaud Lauret 3, 1 1 gold badge 14 14 silver badges 24 24 bronze badges. It should be noted with the latest swagger codegen this construct will give a null pointer exception.