How to define a global variable in RAML - raml

I want to use a global variable in RAML file:
#%RAML 1.0
title: MyTitle
myVariable: http://example.com
version: v1
baseUri: {myVariable}/{version}
but it doesn't work.
Does RAML actually allow that?

No, it doesn't allow to level vars like that. However it does allow you to define baseUriParameters like so:
#%RAML 1.0
---
baseUri: http://{myVariable}.com
baseUriParameters:
myVariable:
type: string
enum: [ us-east, us-west, emea, apac ]
default: us-east

Related

How is $id and $ref values are used in device tree yaml binding file? and can I see it?

This has been a question I had for a long time.
I started to read https://docs.kernel.org/devicetree/bindings/writing-schema.html but it's hard to understand.
For example in linux-5.15.68, the file Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml starts like this.
# SPDX-License-Identifier: GPL-2.0
%YAML 1.2
---
$id: http://devicetree.org/schemas/pci/snps,dw-pcie.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: Synopsys DesignWare PCIe interface
maintainers:
- Jingoo Han <jingoohan1#gmail.com>
- Gustavo Pimentel <gustavo.pimentel#synopsys.com>
description: |
Synopsys DesignWare PCIe host controller
allOf:
- $ref: /schemas/pci/pci-bus.yaml#
properties:
compatible:
anyOf:
- {}
- const: snps,dw-pcie
How is the URI $id and $scmema used? and if I want to browse the file, how can I do it?
When I put http://devicetree.org/schemas/pci/snps,dw-pcie.yaml the browser says 'These are not the schemas you are looking for.'.

Variable in Namespace for ElasticBeanstalk CFT

I have a CloudFormation template yml file that passes OptionSettings for an ElasticBeanstalk applicaiton. I can hard code values, and I can pass values from Parameters. However, I am unable to determine how to pass Parameters or Variables as the namespace.
This works:
- Namespace: aws:elasticbeanstalk:environment:process:lbtargetgroup
OptionName: Port
Value: 3000
This works (where PORTNUMBER is a parameter)
Parameters:
PORTNUMBER:
Type: String
Description: Port number
ElasticBeanstalkConfig:
Properties:
OptionSettings:
- Namespace: aws:elasticbeanstalk:environment:process:lbtargetgroup
OptionName: Port
Value: !Ref PORTNUMBER
However, this does not work (where LBTARGETGROUP is a parameter):
Parameters:
LBTARGETGROUP:
Type: String
Description: Target Group Name
ElasticBeanstalkConfig:
Properties:
OptionSettings:
- Namespace: aws:elasticbeanstalk:environment:process:!Ref LBTARGETGROUP
OptionName: Port
Value: 3000
From what I have tried, you cannot use typical Variables in a CFT (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html#template-anatomy-sections). I have also tried mappings. But I can't seem to figure out how to pass the name as a parameter.
The answer is often very simple... the following works:
Parameters:
LBTARGETGROUP:
Type: String
Description: Target Group Name
ElasticBeanstalkConfig:
Properties:
OptionSettings:
- Namespace: !Join ["", ["aws:elasticbeanstalk:environment:process:", Ref: LBTARGETGROUP]]
OptionName: Port
Value: 3000

azure devops variables from task to templates

I need to pass the variables into templates. For example, the output of Small (found below) should be passed as input to medium. How is this possible?
template: windows-tests.yml
parameters:
integration_tests: ["Small", "Medium"]
check_status: "$(Powershell1.var)"
In addition to the above, I would like to add
o/p from build step will be stored in checkstatus variable and will be passed to template.
Powershell1.var will be used by small test and then generated a value which needs to be used by medium.
I need to pass the variables into templates.
You can refer to this document for instructions on how to pass variables in templates.
the output of Small (found below) should be passed as input to Medium.
Here is the script:
Template:
parameters:
- name: Medium
type: {data type of `Medium`}
default: {defualt value of `Medium`}
Pipeline:
extends:
template: {template file}
parameters:
Medium: $(Small)
I would like to add o/p from build step will be stored in checkstatus variable and will be passed to template.
Here is the script:
Template:
parameters:
- name: check_status
type: string
default: "$(Powershell1.var)"
Pipeline:
extends:
template: {template file}
parameters:
check_status: "$(Powershell1.var)"

How to use $ref for tags between files

I am using Open API 3.0, in A.yaml
# something above
tags:
- name: user
description: Operations about user
- name: user_stuff
description: API for user stuff
- name: another_user_stuff
description: API for another user stuff
# something below
Then, in B.yaml, I want to make reference to the tags in A.yaml, for example the tag of user. Suppose in B.yaml, we have
post:
tags:
$ref: <What are the things should be here?>
summary: do somthing
description: "do something"
requestBody:
# bla bla bla
required: true
responses:
"200":
description: uccessfully
x-swagger-router-controller: B
How can I make a reference from B.yaml to A.yaml?
The tags keyword does not support $ref. All tags must be defined inline.
# B.yaml
tags:
- name: foo
description: Operations to manage Foos.
paths:
/something:
post:
tags:
- foo
- bar
That said, you don't have to define tags in the global tags section in order to use them in operations. The global tags section is used only to define extra tag metadata, such as descriptions and externalDocs, or the tag order in documentation tools.

What is `<<` and `&` in yaml mean?

When I review the cryptogen(a fabric command) config file . I saw there symbol.
Profiles:
SampleInsecureSolo:
Orderer:
<<: *OrdererDefaults ## what is the `<<`
Organizations:
- *ExampleCom ## what is the `*`
Consortiums:
SampleConsortium:
Organizations:
- *Org1ExampleCom
- *Org2ExampleCom
Above there a two symbol << and *.
Application: &ApplicationDefaults # what is the `&` mean
Organizations:
As you can see there is another symbol &.
I don't know what are there mean. I didn't get any information even by reviewing the source code (fabric/common/configtx/tool/configtxgen/main.go)
Well, those are elements of the YAML file format, which is used here to provide a configuration file for configtxgen. The "&" sign mean anchor and "*" reference to the anchor, this is basically used to avoid duplication, for example:
person: &person
name: "John Doe"
employee: &employee
<< : *person
salary : 5000
will reuse fields of person and has similar meaning as:
employee: &employee
name : "John Doe"
salary : 5000
another example is simply reusing value:
key1: &key some very common value
key2: *key
equivalent to:
key1: some very common value
key2: some very common value
Since abric/common/configtx/tool/configtxgen/main.go uses of the shelf YAML parser you won't find any reference to these symbols in configtxgen related code. I would suggest to read a bit more about YAML file format.
in yaml if data is like
user: &userId '123'
username: *userId
equivalent yml is
user: '123'
username: '123'
or
equivalent json will is
{
"user": "123",
"username": "123"
}
so it basically allows to reuse data, you can also try with array instead of single value like 123
try converting below yml to json using any yml to json online converter
users: &users
k1: v1
k2: v2
usernames: *users

Resources