Is there a way to mark the end of a method in RAML? - yaml

I'm writing some RAML in an API designer and I have the following code:
/users:
/{id}:
/tags:
description: Personal tags of a user
get:
description: A list of the user's personal tags
responses:
200:
body:
application/json:
example: |
{
tags: [
{...},
...
]
}
/{slug}:
description: A personal tag
put:
The parser is throwing an error at /{slug} because it thinks that I'm trying to use it as a property of the get: method. However, /{slug} needs to be indented to make it subordinate to /tags.
Is there a way in RAML (or YAML, since RAML is supposed to be an instance of YAML), to mark the end of a map? Or do you have any other suggestions?

RAML doesn't (AFAIK) support explicit termination of maps, but we also don't need that to solve your problem :-).
Since in YAML the whitespace is semantic, what's happening is that your GET method is currently indented such that it's a method on the /users/{id} level, so even though it looks like /{slug} is subordinate to tags, it thinks it is in the definition of /users/{id} Really, we should probably throw an error here, since the method definition comes after you've defined a sub-resource (thanks for finding this case).
To solve, all you need to do is indent your description and get definition for /users/{id}/tags one additional level, and it should all parse fine. Updated RAML is below.
/users:
/{id}:
/tags:
description: Personal tags of a user
get:
description: A list of the user's personal tags
responses:
200:
body:
application/json:
example: |
{
tags: [
{...},
...
]
}
/{slug}:
description: A personal tag
put:

Related

Swagger doesn't generate object from yaml file

I'm new in swagger.
I have a few yaml files and I try to genetare code, using swagger plugin in Intellij.
When I generate it, I have errors cannot find symbol. The symbol that he can't find is
TS29510NnrfNFManagementYamlcomponentsschemasFqdn
But this is wrong. Really he is looking for symbol
$ref: TS29510_Nnrf_NFManagement.yaml#/components/schemas/Fqdn
Fqdn is not generated (I think because it's type is not object).
But why generator can't find this symbol?
In yaml Fqdn looks like this:
Fqdn:
type:
- string
- array
items: {}
You basically answered yourself. Object Fqdn is invalid that's why it can't generated or referenced. Simply change object declaration and enjoy working code :)
Fqdn:
type: object
properties:
items:
type: array
items:
type: string

Enum support for swagger doc

I am a little confused by Swagger's enum support for OpenAPI3.0. My point here being that there have been new improvements in swagger doc where there is support for re-usable enums as
documented here:
https://swagger.io/docs/specification/data-models/enums/
where support for reusable enums is stated using $ref. However, when I post my swagger.json to swagger editor/validator which looks like following
in: query
name: prop-name
description: something
type: array
items:
$ref: '#/definitions/mytype'
which is further defined below:
mytype:
enum:
- Item1
type: string
Swagger editor throws an error and says should NOT have additional properties
additionalProperty: $ref
Now, this is not a problem when loading the swagger page and attaining the functionality but it is an issue when it comes to using swagger-gen and generating clients using it. the swagger-gen CLI also throws the same error causing us to now being able to generate a client for this page correctly.
Is there anything wrong with this swagger.json? I there any extra information that I can provide to shed light on this issue?
In OpenAPI 2.0, array parameter schemas cannot use $ref. You must define the enum inline:
- in: query
name: prop-name
description: something
type: array
items:
type: string
enum:
- Item1

YAML Local Anchor?

I'm trying to simplify this data:
farm:
- pets:
- type: fish
breedtype: fish
name: dory
- type: dog
breedtype: dog
name: lassie
Basically type and breedtype are always the same, unfortunately this is the case.
I've tried to simplify this by somehow using anchors
base: &base
type: &type fish
breedtype: *type
farm:
type: &type dog
<<: *base
I want the *base to inherit &type from &type dog.
I'm not sure if this is the right approach or if there's an easier way, am I looking at the problem wrong?
While it is true that YAML defines a << type, be aware that this is not part of the specification, but part of the type repository which is based on the outdated YAML version 1.1 and has not been updated since. A YAML implementation is not required to support this type. Moreover, it does not do what you think it does, because the alias *type is resolved in the context where it occurs and will always link to the value fish.
Be aware that YAML is pure data. It is not capable of nor designed to enforce rules like type always must match breedtype. The schema used for loading the data is defined by the one loading it. If in your data schema, type always equals breedtype, you can just leave out breedtype in YAML, because when loading it into an application, you can set its value from type.

RAML: Specifying arbitrary queryParameters

I'm trying to model a GET request in my RAML that has an arbitrary list of URL parameters. 2 parameters are known, but the remainder are name/value pairs that are chosen from the response data from other request types. I tried to use additionalParameters: true in my queryParameters list, but I get an error message from osprey-mock-service when it attempts to parse the RAML:
each query parameter must be a map
The relevant snippet from my RAML is:
/statistics:
/{statisticId}:
get:
description: Get the stastic data
queryParameters:
start:
displayName: Start Time
type: integer
description: The timstamp in milliseconds indicating the beginning of the collection of timeseries data
example: 1380601800000
required: false
end:
displayName: End Time
type: integer
description: The timstamp in milliseconds indicating the end of the collection of timeseries data
example: 1380601800000
required: false
additionalParameters: true
responses:
200:
body:
application/json:
schema: statistic
example: !include ../dto/statistic.sample
The error message goes away when I remove the line:
additionalParameters: true
I have not found a reference that indicates that you can use additionalParameters with queryParameters, but it seems to make sense that you could.
I don't necessarily need to resolve the error message, but I would like to have URL parameters like the following:
?start=23010030&end=23011470&content=abc.com&node=siteA
Where content and node are not predefined parameter names.
Is this possible?
additionalParameters is currently not supported by RAML: it is nowhere to be found in version 0.8 of the specification.
This said, this (very important) topic is under discussion in the RAML forums
So for the moment, I see only two options:
Do not specify these parameters, the caveat being that tools, like RAML Tester, will report request violations if you use these parameters.
Specify all the possible parameters with required: false, the caveat being that you need to know all these parameters beforehand.

Kwalify YAML Validation - Use regexes in key names?

I'm using Kwalify for schema validation. One part of the YAML document actually does want to allow for key names of a certain type in a mapping.
I see that Kwalify support regexes for the values in a mapping, but I see no such mention of support for using regexes in the keys in a mapping. Here's what I'd like to support validating:
test-element:
sub-element-1: test
sub-element-2:
element-with-pattern-1: test1
element-with-pattern-2: test2
So I don't know what some key names will exactly be in advance (shown here with the fake names "element-with-pattern-*", but I do know that they should correspond to a pattern defined by a regex.
Is this possible to validate using Kwalify?
To check this:
parent_key:
random_key1: url1
random_key2: url2
you should use "Default of Mapping", here is schema example:
type: map
mapping:
"parent_key":
type: map
mapping:
"=":
type: str
http://www.kuwata-lab.com/kwalify/ruby/users-guide.02.html#tips-default
I do not believe it's possible given the current state of the code.
I'm actually in a similar situation, which I found out (the hard way) does not work well for validation in the Kwalify context. I've begun migrating away from flexible key names into a paradigm where I can specifically define the schema.
For example, I migrated this:
parent_key:
random_key1: url1
random_key2: url2
To:
parent_key:
- name: random_key1
url: url1
- name: random_key2
url: url2
With the latter syntax, you can validate like this:
"parent_key":
type: seq
sequence:
- type: map
mapping:
"name":
type: str
required: yes
"url":
type: str
required: yes
Within that context, you can add a pattern regex validators to either name or url that should allow you to achieve your goal.

Resources