How do I combine 'nil' and an !Included datatype? - mule-studio

I am defining a RAML 1.0 datatype with property that can be 'nil.' The type of that property is an !included datatype which, whilst not giving any errors in the datatype definition causes the root object to throw a "Unresolved reference '!includereference-data.raml' at libraries/types/personal-details.raml (10, 12)'
I've tried converting the DataType to a library to try and implement a "uses" or "types" but that impacts all the other objects that include this data type.
#%RAML 1.0 DataType
properties:
DateOfBirth: datetime
FirstName: string
FamilyName: nil | string
PreferredName: nil | string
PreviousNames: nil | string
Title: !include reference-data.raml
Gender: nil | !include reference-data.raml
The 'Title' property is working as expected, the error is thrown against the Gender property - I actually want both to be nillable.

The datatype to hold nillable properties here is "name_block.raml"
#%RAML 1.0 DataType
uses:
lib: base_types.raml
type: object
properties:
FirstName: lib.string30
MiddleName: lib.nstring30
LastName: lib.string150
The included library (base_types.raml) is defined as
#%RAML 1.0 Library
types:
string30:
type: string
minLength: 0
maxLength: 30
string150:
type: string
minLength: 0
maxLength: 150
nstring30:
type: string | nil
If anyone knows of a better way - It would be great to see it.

Related

Convert UUID to String representation eg: 1816 to Cycling Speed And Cadence

I'm connecting to a Cycling Speed and Cadence service via bluetooth and am saving the peripheral into an array (for tableview).
I have implemented this struct
struct BTPeripheral: Identifiable {
let id: Int
let name: String
let uuid: UUID
let desc: String
}
and am calling is as
discoveredBTDevices.append(BTPeripheral.init(
id: discoveredBTDevices.count,
name: peripheral.name!,
uuid: peripheral.identifier,
desc: service.uuid.uuidstring) // trying service.uuid results in error
)
which results in this output
id: 0,
name: "Wahoo CADENCE 1DE8",
uuid: E98F3843-1C6A-E4DE-6EF3-76B013950007,
desc: "1816"
The description is the string 1816 (which is the UUID of the cycle Speed & Cad service)
let serviceCyclingSpeedAndCadenceUUID = CBUUID(string: "1816")
How can I convert the 1816 into the string "Cycling Speed and Cadence" which is what gets printed out
print(service.uuid) // this results in "cycling Speed and Cadence"
As noted above, putting service.uuid results in an error Cannot convert value of type 'CBUUID' to expected argument type 'String'
You can just get its description (which, IIRC, is what print will do eventually, as CBUUID conforms to CustomStringConvertible):
service.uuid.description
Or use a string interpolation:
"\(service.uuid)"
debugDescription produces the same result too, but I wouldn't use this unless this is actually for debugging.

YYYYMMDD Date format on yaml definition

I have a requirement where the request pass date in YYYYMMDD format. Based on swagger documentation, date filed defined under string type. However, it follows RFC 3339, section 5.6, documentation (ex.2018-03-20 as format)
below code doesn't work with yaml.
dateOfBirth:
type: string
minLength: 8
maxLength: 8
format: date
example: 19000101
description: Birth date of the member in YYYYMMDD format.
How to define YAML definition for the date format of YYYYMMDD.
According to documentation for type string you can add regex pattern to define the date format YYYYMMDD :
pattern: '^\d{4}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])$'
Also let me suggest you to update your example date format with a date like 20190317 to easily understand the expected date format.
definitions:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
dateOfBirth:
type: string
minLength: 8
maxLength: 8
format: date
pattern: '^\d{4}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])$'
example: 20190816
description: Birth date of the member in YYYYMMDD format.

fliend createdAt in Prisma schema returns a null value when createUser() is called

When including a createdAt field in my datamodel.prisma schema the DateTime! returns a null value.
I am raising this on here so that if anyone else has the same problem, hopefully they will be able to find this post.
// in datamodel.prisma
type User {
id: ID! #id
trade_no: String!
name: String!
email: String!
createdAt: DateTime!
}
Error message looks like this "Reason: 'createdAt' Expected non-null value, found null."
In mongoDB the createdAt must be written as
type User {
id: ID! #id
trade_no: String!
name: String!
email: String!
created_at: DateTime! #createdAt
}
when used with Prisma (don't know if this is the case for other databases). Also, bear in mind that the #relation directive must have link: INLINE as an argument (the relationship is stored in the record, not in a separate table). Took me a while to work this out so I thought I'd put it here.
It's worth having a look at https://www.prisma.io/docs/releases-and-maintenance/features-in-preview/mongodb-b6o5/ for other specificities with Prisma & mongoDB.

Mongoose array required in schema validation not working

In my schema I need to have a propery that is an array that must be always not null and not undefined.
So I defined it required, but the validation is not working as I expected, because if I omit the property no error is throw.
In case of simple property (not an array) this work as I expected
const nodeSchema = new Schema({
address: { type: String, required: true },
outputs: { type: [String], required: true }
})
I think you can fix it adding a custom validator like this:
const nodeSchema = new Schema({
address: { type: String, required: true },
outputs: {
type: [String],
required: true,
validate: [(value) => value.length > 0, 'No outputs'],
}
})
I hope it helps you.
Arrays implicitly have a default value of [] (empty array).
This was the problem
Array implicitly have a default value of [] (empty array).
if you add default: undefined it will fix the issue.

Swift HKCategorySample

How do I create an HKCategorySample? I'm following the docs but it errors with
Cannot invoke 'init' with an argument list of type '(type: HKCategoryType, value: Int, startDate: NSDate, endDate: NSDate)'
The docs seem to indicate that those are the correct argument types to pass it, so what is it actually complaining about?
The code I'm using is:
let sample = HKCategorySample(
type: HKCategoryTypeIdentifierSleepAnalysis as HKCategoryType,
value: HKCategoryValueSleepAnalysis.Asleep as Int,
startDate: start,
endDate: end)
where both start and end are NSDates
You have 2 problems in your code:
HKCategoryTypeIdentifierSleepAnalysis is just a identifier String, you must instantiate it with HKObjectType.categoryTypeForIdentifier()
HKCategoryValueSleepAnalysis is enum, you cannot cast it to Int. To extract Int from it, you have to use .rawValue property.
Try:
let sample = HKCategorySample(
type: HKObjectType.categoryTypeForIdentifier(HKCategoryTypeIdentifierSleepAnalysis),
value: HKCategoryValueSleepAnalysis.Asleep.rawValue,
startDate: start,
endDate: end
)