In OpenAPI, both example and enum can be defined with type: string, such as:
type: string
example:
- FOOD
- WATER
type: string
enum:
- FOOD
- WATER
What difference does it make in terms of validation using any of the above structure? Can the above be used interchangeably?
enum and example have different meaning and are used for different purposes.
enum specifies possible values for an instance (in other words, it limits possible values). It's an analog of enums in C#, Java, and other programming languages. For example, enum: [FOOD, WATER] means that the value can be either "FOOD" or "WATER", and nothing else.
example specifies an example value for documentation or other purposes (but not for validation). Say, if you have the User schema with the username property, you can specify demoUser as an example username. But the example value is not the only possible value for the property, it can have other values.
User:
type: object
property:
username:
type: string
example: demoUser
A schema can have both enum and example:
type: string
enum:
- FOOD
- WATER
example: WATER
Unlike enum, example does not affect validation. However, tools like code generators and documentation generators may expect that the example values match their schemas. Such tools would flag the example in your question as invalid, because the schema is defined as string, but the example value is an array (i.e. a different data type).
type: string
# Incorrect
example:
- FOOD
- WATER
# Correct
example: FOOD
Related
I'm trying to create a shacl based on the ontology that my organization is developing (in dutch): https://wegenenverkeer.data.vlaanderen.be/
The objects described have attributes (properties), that have a specified datatype. The datatype can a primitive (like string or decimal) or complex, which means the property will have properties itself (nested properties). For example: an asset object A will have an attribute assetId which is a complex datatype DtcIdentificator, which consists of two properties itself. I have succesfully created a shacl that validates objects by creating multiple shapes and nesting them.
I now run into the problem of what we call union datatypes. These are a special kind of complex datatypes. They are still nested datatypes: the attribute with the union datatypes will have multiple properties but only exactly zero or one of those properties may have a value. If the attribute has 2 properties with values, it is invalid. How can I create such a constraint in shacl?
Example (in dutch): https://wegenenverkeer.data.vlaanderen.be/doc/implementatiemodel/union-datatypes/#Afmeting%20verkeersbord
A traffic sign (Verkeersbord, see https://wegenenverkeer.data.vlaanderen.be/doc/implementatiemodel/signalisatie/#Verkeersbord) can have a property afmeting (size) of the datatype DtuAfmetingVerkeersbord.
If an asset A of this type would exist, I could define its size as (in dotnotation):
A.afmeting.rond.waarde = 700
-or-
A.afmeting.driehoekig.waarde = 400
Both are valid ways of using the afmeting property, however, if they are both used for the same object, this becomes invalid, as only one property of A.afmeting may have a value.
I have tried using the union constraint in shacl, but soon found out that that has nothing to do with what we call "union datatypes"
I think the reason you are struggling is because this kind of problem is usually modelled differently. Basically you have different types of Traffic signs and these signs can have measurements. With the model as you described, A.afmeting.rond.waarde captures 2 ideas using 1 property: (a) the type and (b) the size. From your question, this seems to be the intend. However, this is usually not how this kind of problem is addressed.
A more intuitive design is for Traffic sign to have 2 different properties: (a) type and (b) a measurement. The Traffic sign types are achthoekig, driehoekig, etc. Then you can use SHACL to check that a traffic sign has either both or no properties for a traffic sign.
what is the correct way to break a very long list of enum values in the swagger 2.0 file?
I have a parameter with a very long list of enum values, spanning more than 80 character line, which decreases the code readability and maintainability. is there a way to break them down into multiple lines?
swagger: "2.0"
.
.
.
parameters:
- in: query
name: meta
description: indicates the meta data type being requested
type: string
enum: [very, long, list, of, enum, values]
required: true
looks like it is possible by defining multiple array like below
parameters:
- in: query
name: meta
description: indicates the meta data type being requested
type: string
enum:
- long, list, of, enum, values
- another, long, list, of, enum, values
required: true
I have a use-case which consist in storing several maps under an attribute. It's the equivalent JSON list:
[
{"tel": "+33123456789", "type": "work"},
{"tel": "+33600000000", "type": "mobile"},
{"tel": "+79001234567", "type": "mobile"}
]
Also, I'd like to have it searchable at the object level. For instance:
- search entries that have a mobile number
- search entries that have a mobile number and whose number starts with the string "+7"
Since Riak doesn't support sets of maps (but only sets of registers), I was wondering if there is a trick to achieve it. So far I've had 2 ideas
Map of maps
The idea is to generate (randomly?) keys for the objects, and store each object of the list in a parent map whose keys are the ones generated for this only purpose to have a key.
It seems to me that it doesn't allow to search the object (maps inside the parent map) because Riak Solr search requires the full path to the attribute. One cannot simply write the following Solr query: phone_numbers.*.tel:+7*. Also composed search (eg. search entries that have a mobile number and whose number starts with the string "+7") seem hard to achieve.
Sets with simulated multi-valued attributes
This solution consists in using a set and insert all the values of the object as a single string, with separators between them. Yes, it's a hack. An attribute value would look like: $tel:+79001234567$type:mobile$ with : as the attribute name-value separator and $ as the attribute separator.
Search could be feasible using the * wildcard (ugly, but still), except the problem with escaping the separators: what if the type attribute includes a :? Are they some separators that are accepted by Riak and would not be acceptable in a string (I'm thinking of control characters)?
In a nutshell
I'm looking for a solution whatever the hackiness of it, as long as it works. Any idea is welcome.
I have a JDOQL/DataNucleus storage layer which stores values that can have multiple primitive types in a varchar field. Some of them are numeric, and I need to compare (</>/...) them with numeric constants. How does one achieve that? I was trying to use e.g. (java.lang.)Long.parse on the field or value (e.g. java.lang.Long.parseLong(field) > java.lang.Long.parseLong(string_param)), supplying a parameter of type long against string field, etc. but it doesn't work. In fact, I very rarely get any errors, for various combinations it would return all values or no values for no easily discernible reasons.
Is there documentation for this?
Clarification: the field is of string type (actually a string collection from which I do a get). For some subset of values they may store ints, e.g. "3" string, and I need to do e.g. value >= 2 filters.
I tried using casts, but not much, they do produce errors, let me investigate some more
JDO has a well documented set of methods that are valid for use with JDOQL, upon which DataNucleus JDO adds some additional ones and allows users to add on support for others as per
http://www.datanucleus.org/products/accessplatform_3_3/jdo/jdoql.html#methods
then you also can use JDOQL casts (on the same page as that link).
I have a scenario in a web based application where a user selects a Country from a dropdown list. Once the country is selected, the localized fields beneath the country listbox appears as well correspoding to that country. Here i also need to have that country pre-selected and dropdowns pre-populated based on the locale of that country.
Let me illustrate this with examples:
EXAMPLES:
Country: United States
Corresponding Fields:
State:
Zip Code:
Time:
Currency:
Date:
Country: United Kingdom
Corresponding Fields:
County:
Postal Code:
Time:
Currency:
Date:
Country: India
Corresponding Fields:
Province:
District:
PO Box:
Currency:
Date:
Time:
How can i achieve this dinamically in ASP.Net (3.5 or 4.0)?
Wonder if we can use a Google Web Service API for this requirement?
Looking forward to seek answers with proven experience. Thanks
I can see that number of fields for country 'India' is 1 more than the others. Is this intended ? If yes, you can setup fields related to a country in database and their localized text be stored in other 'linked' table. Number of fields may differ in number for each country.
If the fields are going to be same, you can create resource files specific to locales and add different text to it. When you change the selection in drop-down, just set System.Threading.Thread.CurrentThread.CurrentUICulture to relevant locale code.
Making use of resource files to store the translated texts will provide you more flexibility in the long run.
Do check out the following links on how to make use of resource files:
http://www.codeproject.com/Articles/334820/Using-Globalization-and-Localization-in-ASP-NET
http://www.codeproject.com/Articles/14818/ASP-NET-2-0-Globalization-Localization-solution
This is not so much about localization but about market-specific standards. Specifically, international address formats. I'm not aware of an off-the-shelf solution for this but you can find existing resources that define these formats (for example on MSDN here: http://msdn.microsoft.com/en-us/library/cc195167.aspx).
I suppose you could define the formats using your preferred approach (perhaps XML, perhaps hardcoded data definitions) for each market to define its adequate "structure" (by structure I mean which fields and in which order) and use standard localization to translate each of the corresponding labels.
Edit:
Regarding Date, Time and Currency, you can make use of the .NET Framework's culture definitions, which can be accessed through CultureInfo's DateTimeFormat and NumberFormat properties (MSDN link). I'm not sure whether you want to display Date, Time and Currency through an example (such as today's date or the current time) or the format itself (such as mm/dd/yy and hh:mm:ss). For the former, you instantiate a CultureInfo and pass it in to the ToString overrides that take an IFormatProvider. A good example for Date and Time is shown on this MSDN page. The same applies to currency formatting (MSDN link). It works like this:
CultureInfo cultureInfo = new CultureInfo("en-GB"); // Change en-GB to the desired culture name
DateTime now = DateTime.Now;
string sampleTime = now.ToString("T", cultureInfo); // Result: 5:04:32 PM
string sampleDate = now.ToString("d", cultureInfo); // Result: 13/3/2012
double value = 16325.62901;
string sampleCurrency = value.ToString("C", cultureInfo); // Result: £16,325.63
If on the other hand you want to show the format, you can get this data by taking the relevant properties of DateTimeFormatInfo and NumberFormatInfo. For example:
CultureInfo cultureInfo = new CultureInfo("en-GB");
string shortDatePattern = cultureInfo.DateTimeFormat.ShortDatePattern; // Result: d/M/yyyy
string shortTimePattern = cultureInfo.DateTimeFormat.ShortTimePattern; // Result: h:mm tt
string currencySymbol = cultureInfo.NumberFormat.CurrencySymbol; // Result: £