Convert RAML Data Types XSD - xsd

Raml website states that I can convert RAML 1.0 data types to XML Schema:
Data Types can be used in place of schemas and examples, letting you define one Data Type that can then be converted into an XML or JSON Schema on the fly - letting you simply define your data model, and letting RAML take care of the REST.
How can I do that? And what is the level of support for complex types with inheritance and string patterns?

The statement implies that you can use a XML data type to define a complex structure. This definition is logical and does not specify the physical format like a XML or JSON.
This is a definition of a Album Type:
#%RAML 1.0 DataType
type: AlbumSimple
displayName: Full Album Object
properties:
artists: ArtistSimple[] # would pull in ArtistSimple DataType
copyrights: Copyright[] # would pull in Copyright DataType
external_ids: ExternalId # would pull in ExternalId DataType
genres:
type: string[]
description: |
A list of the genres used to classify the album. If not yet classified,
the array is empty.
example: ["Prog Rock", "Post-Grunge"]
popularity:
type: integer
description: |
The popularity of the album. The value will be between 0 and 100,
with 100 being the most popular. The popularity is calculated from
the popularity of the album's individual tracks.
tracks:
type: Page # would pull in Page DataType
(pagedObject): TrackSimple
description: The tracks of the album.
That definition does not imply the physical format. You have to define in the body content-type:
get:
is: [ drm ]
responses:
201:
body:
application/json:
type: AlbumSimple

Related

SuiteScript - Search joining "Term" from "Vendor"

I am doing a search of vendors and want to join in the Term to have the Term's name. The vendor has a field called terms which has the internalid of the Term. Term has a field called name which contains what I'm looking for.
I've tried just about every combination of building the column but I always get an error:
An nlobjSearchColumn contains an invalid column join ID, or is not in proper syntax: name.
Example of how I'm building the column:
search.createColumn({
name: "name",
join: "terms", // or Term, or Terms, none of it works
label: "termname" // or leave this out or Term or Terms or anything else nothing works
}
What is the right way to create a search for vendor that also includes the term's name?
If you'll look at the Records Browser, terms is not listed as a join on the vendor record. Just get terms as a column (name: 'terms') then when you retrieve the result, use getText instead of getValue.
searchResults[i].getText({
name: 'terms'
});

Is there anything like SQLs Decimal in MongoDB?

There is great data type in MySQL Decimal, which is good to store prices like:
CREATE TABLE books( title VARCHAR(100), author VARCHAR(100), price DECIMAL(6,2));
So how can I create similar schema in MongoDB?
I can not find anything like DECIMAL there.
My code in node.js+mongoose looks like this so far:
const booksSchema = new Schema({
title: String,
author: String,
price: Number
});
There is data type called Decimal128, introduced in v3.4. So the database supports it.
https://docs.mongodb.com/manual/reference/bson-types/
But node.js/mongoose probably doesn't, given that all numbers in javascript are floats. see Stennie's comment below.

How to model a consitent database in alloy?

Alloy newbie here. I'm trying to model a medical database containing user and some medical information.
sig User{
name: one String,
surname: one String,
socialNumber: one String,
address: one String,
age: one Int,
registration: one UserCredential,
healthStatus: one HealthInformation
}{
age>0
}
sig UserCredential{
user: one String,
pass: one String,
mail: one String
}
sig HealthInformation{}
sig Data4Help{
users: some User,
}
pred show(d:Data4Help){
#d.users>1
}
run show for 10
The analyzer tell me the model is inconsistent:
Executing "Run show for 10"
Solver=sat4j Bitwidth=4 MaxSeq=7 SkolemDepth=1 Symmetry=20
5448 vars. 510 primary vars. 12578 clauses. 16ms.
No instance found. Predicate may be inconsistent. 0ms.
Can you guys tell me why? All I want is having the database "Data4Help" linked to some users, probably the definition of the relation is incorrect but I don't know why.
Thank you
The problem is that Alloy has some troubles with Strings. By default, the String signature defines an empty set of atoms. If you want to use Strings in your model, you will have to populate that set with "your own Strings".
See How to use String in Alloy?
In your model, you could add this simple fact
fact initPoolOfString{
String in "insert"+ "your"+"dummy" + "strings" + "here"
}

How does serde transform a the value inside a string into a Type

I've built an ECS (a simple one I think) and I've built a mechanism to load external data (entity templates) into my program the problem I'm having is how to transform the already loaded data into a type.
Since Serde does this I thought to look up how but I can't actually find the part that does this.
What I mean is, when you create a data structure like this:
person:
name: Bob
age: 34
and serde is able to transform it into a struct:
struct Person {
name: String,
age: i32
}
How does serde transform the string person into the type Person
EDIT:
To give an example in another language(ruby):
class Person
attr_accessor :name, :age
def initialize(name:, age:)
#name = name
#age = age
end
end
# pretend type was loaded in from the yaml example from the key
type = 'person'
# pretend person_data was loaded in from the yaml example form the value of the key
person_data = {
name: 'Bob',
age: 34
}
# and now we get the type and then initialize it
# Just like serde does
const_get(type.capitalize).new(person_data)
Now obviously Rust can't do this at runtime or does it like this but serde must do something to that ends up with the same result, with "person" transforming into Person.
You tell serde the type you want. It knows the types of the members from the Derive implementation.

What is the meaning `required` in mongoose Schema?

I am writing a mongoose schema, and I would like to understand the properties of the same.
Here is my schema:
var UserSchema = new Schema({
name: String,
username: { type: String, required: true, index: { unique: true }},
password: { type: String, required: true, select: false }
});
Why required is not declared for `name' - ?
Why required declared?
What is select - true/false -means?
When the index - should declared any why?
Why required is not declared for `name' - ?
Answer: When a field is mandatory to fill then in that case we mention it as required. So here "name" is not required or mandatory field.
Why `required' declared?
Answer: As mentioned above, When a field is mandatory to be filled then in that case we mention it as required.
What is select - true/false -means?
Answer: This means that it will not be returned by default in the data when you fetch the document. you can specify if this path should be included or excluded from query results by default.
Schema options
When the index - should declared any why?
Answer: Index should be declared when you are searching data on that field frequently so when you create indexing on that field in that case it do not search that field in all the collections it will search value for that field using index and will return result very quickly.
How indexes work in mongodb
Here, these act as model for your project. So, required is used as validation and index is working as index over that field
Now you have two ways :
either put validation over here in schemas/models
or just manually create validation for form at frontend using JS/Jquery and then long route
Now your answers:
Name is not compulsory to be filled in. That's why no required is put over there.
when there is mandatory to fill any value for that field. Then required is used in schemas.
True/False enables or disables the usage of validation over that field. If you are using false means filling in for that field isn't compulsion at all. But using false is considered a good practice.
Index is special data structure which are used for increasing performance during read/search operations. It increases the speed of operations and are stored in memory.
whenever we have to validate the particular field, so we used required.
required: true means you must fill that field.
required: false means you may or may not fill that field, but its a good practice.

Resources