I have a JAR which contains an application.yml. That YAM file contains an array, e.g.:
things:
- name: one
color: red
I need to adjust this array at runtime by adding an additional application.yml file in the same directory as the JAR. However, I'm not sure how to append to the array, because the follow config seems to replace the config in the built-in YAML file in the JAR:
things:
- name: red
color: blue
In the end, during runtime, I need this:
things:
- name: one
color: red
- name: two
color: blue
There looks like a similar question was asked. Doesn't sound like it's supported. Looking through docs, I've found is some older docs show it's not supported.
When a collection is specified in multiple profiles, the one with highest priority is used (and only that one):
foo:
list:
- name: my name
description: my description
- name: another name
description: another description
---
spring:
profiles: dev
foo:
list:
- name: my another name
In the example above, considering that the dev profile is active, FooProperties.list will contain one MyPojo entry (with name “my another name” and description null).
A newer 2.6.0 snapshot doc mentions the same but seems to encourage you name your keys as their own objects. You might not have access to the beans bringing them in but it might be good to structure others in this way if you can.
Consider the following configuration:
my:
map:
key1:
name: "my name 1"
description: "my description 1"
---
spring:
config:
activate:
on-profile: "dev"
my:
map:
key1:
name: "dev name 1"
key2:
name: "dev name 2"
description: "dev description 2"
If the dev profile is not active, MyProperties.map contains one entry with key key1 (with a name of my name 1 and a description of my description 1). If the dev profile is enabled, however, map contains two entries with keys key1 (with a name of dev name 1 and a description of my description 1) and key2 (with a name of dev name 2 and a description of dev description 2).
Related
I am using cloudformation to deploy my code. In my yml file I ahve this DependsOn attribute for which I am trying to add value as "AppApiv1Stage". I have tried multiple things, everytime it gives different errors not sure what I am doing wrong. In the below code snippet first I added it in double quotes like this:"AppApiv1Stage" then it showed error. Again I tried with below code, then it showed me error as "DependsOn must be a string or list of strings"
Parameters:
ApiStageSecondDeploymentName:
Description: API Stage name to use
Type: String
Default: v1
Resources:
AppAPI:
Type: AWS::Serverless::Api
DependsOn: AuthFunction
Properties:
Name: !Sub ${AWS::StackName}
StageName: !Ref ApiStageSecondDeploymentName
Variables:
LocalTLD: local # Deploys a Dev stage to use for tests and development
MethodSettings:
- LoggingLevel: ERROR
MetricsEnabled: True
DataTraceEnabled: True
HttpMethod: '*'
ResourcePath: '/*'
ThrottlingBurstLimit: !Ref ApiBurstLimit
ThrottlingRateLimit: !Ref ApiRateLimit
ApiMapping:
DependsOn: !Sub AppAPI !Ref ${ApiStageSecondDeploymentName}Stage
Type: AWS::ApiGateway::BasePathMapping
Properties:
BasePath: !Ref ApiStageSecondDeploymentName
DomainName:
Fn::ImportValue: !Sub ${CustomDomainStack}-DNSName
RestApiId: !Ref AppAPI
I also tried with Join! but showing error again.
not sure what I am doing wrong
DependsOn, as the error says, must be a string, or list of strings. Not an intrinsic function (Sub, Ref).
What's more, intrinsic functions can be only used in few places in a template, none of which is DependsOn. From docs:
You can use intrinsic functions only in specific parts of a template. Currently, you can use intrinsic functions in resource properties, outputs, metadata attributes, and update policy attributes. You can also use intrinsic functions to conditionally create stack resources.
I have a simple requirement of converting input JSON to flat file in Mule 4 but I am unable to find any solid examples online. I started of creating sample schema as follows but it's not working.
test.ffd schema:
form: FLATFILE
id: 'test'
tag: '1'
name: Request Header Record
values:
- { name: 'aa', type: String, length: 10 }
- { name: 'bb', type: String, length: 8 }
- { name: 'cc', type: String, length: 4 }
dataweave:
%dw 2.0
output application/flatfile schemaPath='test.ffd'
---
{
aa : payload.a,
bb : payload.b,
cc : payload.c
}
Input JSON:
{
"a": "xxx",
"b": "yyy",
"c": "zzz"
}
But it fails saying
Message : "java.lang.IllegalStateException - Need to specify structureIdent or schemaIdent in writer configuration, while writing FlatFile at
4| {
| ...
8| }
How do I do this correctly?
Error message tells you what is missed.
Need to specify structureIdent or schemaIdent in writer configuration
Add one of them and it flatfile or fixedwidth should work fine.
For example, add segmentIdent:
%dw 2.0
output application/flatfile schemaPath = "test1.ffd",
segmentIdent = "test1"
---
payload map (a, index) -> {
aa: a.a,
bb: a.b,
cc: a.c
}
Here is example how to use FIXEDWIDTH properly https://simpleflatservice.com/mule4/FixedWidthSchemaTransformation.html
Assuming you are trying to output a fixed width file, which it looks like you are, change
form: FLATFILE
to
form: FIXEDWIDTH
Keep in mind using this FFD will only work if you have a single structure. You could pass in:
payload map {
aa: $.a,
...
}
If you had a set and it would still work, but if you needed multiple structures you won't be able to use the shorthand schema.
And to explain why you were getting this error, take a look at these docs, reading "Writer properties (for Flat File)":
https://docs.mulesoft.com/mule-runtime/4.2/dataweave-formats#writer_properties_flat_file
I want to put my page addresses in the yml file, but I have a problem with this.
path:
api.v1.0: /api/v1.0
api.v1.0:
register: ${path.api.v1.0}/register
register:
token: ${path.api.v1.0.register}/token/{token}
during the compilation it gets such a mistake
Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing MappingNode
in 'reader', line 5, column 5:
register: ${path.api.v1.0}/register
^
Duplicate key: register
in 'reader', line 39, column 1:
Why does it not work?
PS: Is this a good way to place addresses in yml or properties file? Is it professional?
Whether it is good or not depends on the intended uses so I can't add much value there. But the duplication is because your objects have duplicate keys. You might want to consider an array as a data structure:
paths:
-
name: api.v1.0
path: /api/v1.0
paths:
-
name: register
path: "${path.api.v1.0}/register"
-
name: register-token
path: "${path.api.v1.0.register}/token/{token}"
Generating server code for this minimal example using spring or jaxrs-spec creates 2 model classes: Pet.java and InlineResposne200.java. Except for the class name, they are identical.
The controller that responds to /pets returns a List<InlineResponse200> instead of List<Pet> and the class Pet is actually never used anywhere, even though the yaml definition uses $ref: "#/definitions/Pet". Why is this happening?
---
swagger: "2.0"
info:
version: "1.0.0"
title: "Swagger Petstore"
description: "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification"
termsOfService: "http://swagger.io/terms/"
contact:
name: "Swagger API Team"
license:
name: "MIT"
host: "petstore.swagger.io"
basePath: "/api"
schemes:
- "http"
consumes:
- "application/json"
produces:
- "application/json"
paths:
/pets:
get:
description: "Returns all pets from the system that the user has access to"
produces:
- "application/json"
responses:
"200":
description: "A list of pets."
schema:
type: "array"
items:
$ref: "#/definitions/Pet"
definitions:
Pet:
type: "object"
required:
- "id"
- "name"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
tag:
type: "string"
I tried replicating this with swagger-codegen v2.2.2 using both spring and jaxrs-spec, but I was not able to get the InlineResponse200.java.
However, having done some more digging, I have found that this issue was recently reported as a bug. It has not yet been fixed, but the InlineResponse200.java isn't meant to be there.
This file seems to be incorrectly generated when using Swagger Editor v3. I'm guessing that's how you generated your file?
Whilst Swagger Editor v2 does not have this problem, my suggestion for the time being for you would be to install and use the latest stable version of swagger-codegen to generate your code from your Swagger.yaml file.
Hope this helps.
For given groupId, artifactId, version, classifier and type, how can I download the corresponding artifact using REST?
use the gavc search to get the URL and from there you can download the artefact:
GAVC Search
Description: Search by Maven coordinates: GroupId, ArtifactId, Version
& Classifier. Search must contain at least one argument. Can limit
search to specific repositories (local and remote-cache). Since: 2.2.0
Security: Requires a privileged user (can be anonymous) Usage: GET
/api/search/gavc?[g=groupId][&a=artifactId][&v=version][&c=classifier][&repos=x[,y]]
Headers (Optionally): X-Result-Detail: info (To add all extra
information of the found artifact), X-Result-Detail: properties (to
get the properties of the found artifact), X-Result-Detail: info,
properties (for both). Produces:
application/vnd.org.jfrog.artifactory.search.GavcSearchResult+json
Sample Output:
GET /api/search/gavc?g=org.acme&a=artifact&v=1.0&c=sources&repos=libs-release-local
{
"results": [
{
"uri": "http://localhost:8080/artifactory/api/storage/libs-release-local/org/acme/artifact/1.0/artifact-1.0-sources.jar"
},{
"uri": "http://localhost:8080/artifactory/api/storage/libs-release-local/org/acme/artifactB/1.0/artifactB-1.0-sources.jar"
}
]
}
Taken from the API-Documenation.
In the Artifactory docs about their REST service you have an example here: https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-RetrieveArtifact