Swagger - property name convention - swagger

In the past when I designed APIs , for both 2.0 and 3.0 version, I used camel case convention for property names. This time I could have the necessity of use embedded underscore and capital letter for property name. Is this allowed by openapi? Can I use mix mode?
I searched for naming convention of property name but I' havent found.
Thanks

As far as I know any valid string is allowed. Quoting and escaping is possible to create a valid string.
all this works:
foo-bar:
type: string
foo_bar:
type: string
'foo-bar':
type: string
'foo_bar':
type: string
"foo_bar":
type: string
"foo bar":
type: string
foo bar:
type: string
"foo: bar":
type: string

Related

dart: Instance variable of type String with only certain values

is there a way in dart to define an instance variable of type String to only hold certain values.
For example in TypeScript one can achieve this as follows:
class Test {
name: string;
type: 'Unit' | 'Integration';
}
I've already considered defining an enum, however as far as I'm concerned you can't provide enums with custom values in dart.

Swagger definition: $ref and required

so, I want to write a definition like this:
components:
accuracy::
$ref: '#/definitions/accuracy'
required: false
and 'override' a required property. But the documentation says:
Any sibling elements of a $ref are ignored. This is because $ref works
by replacing itself and everything on its level with the definition it
is pointing at.
So, is there any way to achieve this behavior?
required is not a property attribute, it's an object attribute containing a list of required properties. So you should use:
MyObject:
type: object
properties:
accuracy:
$ref: '#/definitions/accuracy'
required:
- accuracy

What's the difference between String and string in Dart?

I can't understand why in some docs the String method is capitalized, but in some docs the same method is not. string vs String.
What is difference?
The difference is that String is a type and string is not.
For more details it depends on the context.

Can you have a custom attribute in yang schema?

I wanted to know if we could define a custom field or attribute in one of the elements leaf,list etc. For eg: Is this possible? How can we define such fields if its possible.
model Animal{
leaf amphibian{
type String;
custom "Frog"; // Custom field which has a value "Frog"
}
}
An "attribute" as in a "new YANG keyword"
If by "attribute" you are referring to a new YANG keyword, that has special meaning to you, then yes. YANG supports extensions. From RFC6020:
The "extension" statement allows the definition of new statements
within the YANG language. This new statement definition can be
imported and used by other modules.
The statement's argument is an identifier that is the new keyword for
the extension and must be followed by a block of substatements that
holds detailed extension information. The purpose of the "extension"
statement is to define a keyword, so that it can be imported and used
by other modules.
The extension can be used like a normal YANG statement, with the
statement name followed by an argument if one is defined by the
extension, and an optional block of substatements. The statement's
name is created by combining the prefix of the module in which the
extension was defined, a colon (":"), and the extension's keyword,
with no interleaving whitespace.
extension custom {
argument object;
description "A new YANG keyword that carries special semantics.";
}
prefix:custom "Frog"; // usage of an extension
The argument keyword in the above example is an optional substatement to an extension keyword and is used to indicate that the new keyword takes (mandates) an argument (a string, such as "Frog").
The "argument" statement, which is optional, takes as an argument a
string that is the name of the argument to the keyword. If no
argument statement is present, the keyword expects no argument when
it is used.
7.17.2
Why do you need a named argument for the new keyword? YANG may be mapped to YIN, the alternative syntax expressed as XML and that is where this name becomes important.
The argument's name is used in the YIN mapping, where it is used as
an XML attribute or element name, depending on the argument's "yin-
element" statement.
7.17.2
You cannot restrict the value space of this argument per se - a YANG compiler will always recognize it as a string. But there is nothing stopping you from requiring implementations to expect certain values - you are defining the meaning of the new keyword after all.
extension custom {
argument value;
description
"The value of "custom" statement's argument MUST be an integer
in the range from 1 to 5.";
}
prefix:custom 3;
Description statements contain normative text, so if your extension contains a description substatement, stating that "value of this statement's argument MUST be an integer", then an implementation will have to respect this text.
An "attribute" as in an "XML attribute" (or a JSON equivalent)
If you meant an "attribute" in instance documents (XML, JSON,...) modeled with YANG, then the answer is no - for the most part. Pure YANG does not support modeling attributes.
However, there is a published specification for a YANG extension that allows such attributes to be defined. You can read more about that here (RFC7952). The extension is called annotation and is used to define YANG metadata, additional information that augments data that may already be modeled with YANG. Here's an example:
module using-annotation {
namespace "org:example:using-annotation";
prefix "ua";
import ietf-yang-metadata {
prefix "md";
}
md:annotation my-annotation {
type string;
description "This is my annotation.";
}
container top {
leaf some-leaf {
type string;
}
}
}
This would be a valid XML instance according to the above model:
<ua:top xmlns:ua="org:example:using-annotation">
<ua:some-leaf ua:my-annotation="Yay!">foo</ua:some-leaf>
</ua:top>
It allows an XML attribute to become valid almost anywhere.
Reading RFC7952 may also be useful for learning how the extension statement actually works and how to properly define a YANG extension.

Grails: TypeMismatchException - Provided id of the wrong type - Expected: class java.lang.Integer, got class java.lang.Long

I have the following domain model class:
class UserSettings
{
static mapping = {
id name: 'pid', generator: 'assigned'
}
Integer pid
}
And I'm trying to get an instance of the user settings like this:
UserSettings.get(new Integer("12345"))
However, I get the following error
Provided id of the wrong type for class UserSettings. Expected: class java.lang.Integer, got class java.lang.Long
I've also tried passing it a basic int type, and I get the same error. It's like somewhere along the way the "get" method casts my Integer into a Long. Changing the type of the "pid" property in the UserSettings domain class to Long fixes things, however, since I'm integrating with a legacy database, I need the ID to be an Integer not a Long.
In general don't use new Integer, new Long, new Boolean, etc. Use literals and let Java autobox the values for you. If you look at the source of the Integer and Long you'll see that their valueOf methods (which are used when autoboxing) keep a cache of 256 of the smaller values. This won't result in a significant savings but is a good idea, and since you get the same thing with the constructor and valueOf, it's best to always use valueOf.
Further, GORM will convert the input id to the correct type for the domain class. This is why SomeDomainClass.get(params.id) works in controllers - even though all params are strings, GORM can easily convert from a string to a numeric type.
So your best bet here is to work less:
UserSettings.get("12345")

Resources