MuleSoft RAML: Invalid schema for content type application/xml - mulesoft

I've created a raml file which is compiled successfully in Design Center and published to exchanges. Getting below error while trying to test in exchange. There were no spaces, special characters in raml file.
mediaType : application/xml
Input xml:
<?xml version="1.0" encoding="UTF-8"?>
<TransactionNotificationRequest>
<envelope>
<header></header>
<body>
<notifications>
<organizId>00D2i0000000o9YEAQ</organizId>
<ActionId>04k2i0000008PW8AAM</ActionId>
<SessionId>00D2i0000000o9Y</SessionId>
<EnterpriseUrl>fmcna-healthcloud--qa1.my.sales.com</EnterpriseUrl>
<PartnerUrl>fmcna-healthcloud--qa1.my.sales.com</PartnerUrl>
<Notification>
<Id>04l2i00000Bz7W0AAJ</Id>
<sObject>
<fieldsToNull>lastName</fieldsToNull>
<Id>0032i00001Ma7tlAAB</Id>
<Account_Name__c>TestingPatientQA5</Account_Name__c>
<Email>testingpatientqa5#outlook.com</Email>
<Phonec>123456789</Phonec>
</sObject>
</Notification>
</notifications>
</body>
</envelope>
</TransactionNotificationRequest>
"message": "Invalid schema for content type application/xml. Errors: cvc-complex-type.2.3: Element 'organizId' cannot have character [children], because the type's content type is element-only.. "
#%RAML 1.0 DataType
type: object
properties:
envelope:
type: object
properties:
header:
type: object | nil
body:
type: object
properties:
notifications:
type: object
properties:
organizId:
type: string | nil
ActionId:
type: string | nil
SessionId:
type: string | nil
EnterpriseUrl:
type: string | nil
PartnerUrl:
type: string | nil
Notification:
properties:
Id:
type: string | nil
sObject:
properties:
fieldsToNull:
type: string | nil
Id:
type: string | nil
Account_Name__c:
type: string | nil
Email:
type: string | nil
Phonec:
type: string | nil
any inputs to fix this issue.

Related

How do I get a series of documents from Firestore and return them all in an array?

My Firestore data has the following structure:
topics collection containing documents with the following structure:
id: string
name: string
tag: string
infoID: string
these map to an ITopic interface:
interface ITopic {
id: string
name: string
tag: string
infoID: string
}
infos collection containing documents with the following structure:
id: string
content: string
topicID: string or null
which map to:
interface IInfo {
id: string
content: string
topicID: string | null
}
So each topic document has an associated info document, and vice-versa (ie a one-to-one mapping).
I've retrieved all my topic documents from the database and now I want to get the associated info for each one, all in an array. So each item in the array would be an object with topic and info fields:
interface ITopicInfo {
topic: ITopic
info: IInfo
}
I've tried this (topics is the existing array of all my topics):
async function getTopicsInfo(db: Firestore, topics:Array<ITopic>) {
try {
let topicsInfo:Array<ITopicInfo> = topics.map((topic) => {
const infoRef = doc(db, 'infos', topic.infoID);
const infoSnap = await getDoc(infoRef);
if (infoSnap.exists()) {
const result = infoSnap.data();
const newTopicInfo:ITopicInfo = {
topic: topic,
info: {
id: result.id
content: result.content
topicID: result.topicID
},
};
return newTopicInfo;
} else return null;
});
return topicsInfo;
} catch (error) {
throw error;
}
}
However, I'm getting a TypeScript error saying
Type '(Promise<ITopicTree | null> | null)[]' is not assignable to type '(ITopicTree | null)[]'.
it looks like it's returning the Promise rather than the result, basically. How do I fix this?
did you try to return map directly :
instead of doing this :
let topicsInfo:Array<ITopicInfo> = topics.map((topic) => { ...
Just do this :
return topics.map((topic) => { ...
UPDATE :
async function getTopicsInfo(db: Firestore, topics:Array<ITopic>): ITopicInfo[] { ...

Formik and yup validation on string type using latest release 0.29.3

I have the following phone number validation using yup but I am getting TS error after upgrading
"yup": ^0.27.0 to "yup": "^0.29.3"
and
"#types/yup": "^0.26.27" to "#types/yup": "^0.29.7"
const ValidationSchema = Yup.object().shape<ICreateUserForm>({
phone: Yup.string()
.required("Required")
.test("countryCode", "Must include country code", (phone?: string) => {
return !!phone && phone.startsWith("+")
})
.test("isValidNumber", "Must be valid phonenumber", (phone?: string) => {
const parsedNumber = !!phone && parsePhoneNumberFromString(phone)
return parsedNumber && parsedNumber.isValid() ? true : false
})
})
Error
No overload matches this call.
Overload 1 of 4, '(name: string, message: TestOptionsMessage<{}, any>, test: TestFunction<string | null | undefined, object>): StringSchema<string, object>', gave the following error.
Argument of type '(phone?: string | undefined) => boolean' is not assignable to parameter of type 'TestFunction<string | null | undefined, object>'.
Types of parameters 'phone' and 'value' are incompatible.
Type 'string | null | undefined' is not assignable to type 'string | undefined'.
Type 'null' is not assignable to type 'string | undefined'.
Overload 2 of 4, '(name: string, message: TestOptionsMessage<{}, any>, test: AssertingTestFunction<string, object>): StringSchema<string, object>', gave the following error.
Argument of type '(phone?: string | undefined) => boolean' is not assignable to parameter of type 'AssertingTestFunction<string, object>'.
Signature '(phone?: string | undefined): boolean' must be a type predicate. TS2769
Following is the Type definition of phone
type AvailableLanguage = "fi" | "en"
export interface CreateUserForm {
firstName: string
lastName: string
email: string
phone: string
language: AvailableLanguage
}
Since there are bo breaking changes in the recent changelog. I am not sure what has happened behind the scenes
https://github.com/jquense/yup/blob/master/CHANGELOG.md
https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/yup
The problem is in how you declare the type of the argument in the function passed to .test.
You are passing (phone?: string) but it needs to be (phone?: string | null) as the error mentions.
Here is how it should work
const ValidationSchema = Yup.object().shape<ICreateUserForm>({
phone: Yup.string()
.required("Required")
.test("countryCode", "Must include country code", (phone?: string | null) => {
return !!phone && phone.startsWith("+")
})
.test("isValidNumber", "Must be valid phonenumber", (phone?: string | null) => {
const parsedNumber = !!phone && parsePhoneNumberFromString(phone)
return parsedNumber && parsedNumber.isValid() ? true : false
})
})
I'm not sure if the property phone should allow undefined (using ?), but I think you can also pass it as a string only like (phone: string).
Maybe you are wondering:
Why I'm getting this typescript error after upgrading?
Probably because the old version didn't support typescript that good and in the new version they "fixed" or made something better with typescript.
I had a similar problem and solved it by installing the latest version of the Yup package and #types/yup packages.
npm i -S yup#0.32.8
npm i -D # types/yup#0.29.11
I did a test on Repl.it:
[https://repl.it/join/ytnxoyno-jefferson1919]

Is recursive array types possible in union discrimination?

I'm just starting discovering TypeScript and I'm testing the limits. What I'm looking for is a way to make an interface that as fields depending on the value of one of it's property.
For example:
type type RecursiveArray<T> = T | RecursiveArray<T>[];
type allowedTypesString = 'string' | 'email' | 'date' | 'id' | 'number' | 'boolean' | 'object';
interface IOptions {
type: RecursiveArray<allowedTypesString>,
required?: boolean,
defaultValue?: PROVIDED_TYPE,
expected?: PROVIDED_TYPE[],
transform?: (value: PROVIDED_TYPE) => any,
validate?: (value: PROVIDED_TYPE) => boolean,
regexp?: RegExp,
min?: number,
max?: number,
params?: object,
}
I want IOptions to have:
regex property only if type is "string" or "email" .
params only if type is "object".
min and max only if type is "number, etc...
I saw that I could use discriminated unions like in this thread, but as you can see, the type property is a RecursiveArray<allowedTypesString> which means that it can be a single string, an array of string, an array of array of string, etc...
With unions, I could declare :
interface IOptionsString {
type: string,
defaultValue?: string,
expected?: string[],
regexp?: RegExp,
}
that will be called if the type is a string. But what if I'm receiving an array of string or an array of array of string ?
Is what I'm doing possible ? Otherwise I'll just handle single array but I want to know if what I'm thinking of is possible in TypeScript.
Thanks for your help !
You can do what you want with conditional types if you parameterize IOptions with the actual type and then turn into an intersection of common types and special ones that depend on the type.
To go back to the original types (i.e. PROVIDED_TYPE in your example) you need to change allowedTypesString into a map from string types to actual types and then use conditional types to reify (i.e. convert from value to type).
type RecursiveArray<T> = T | RecursiveArray<T>[];
interface TypeStringMap {
'string': string;
'email': string;
'date': Date;
'id': string;
'number': number;
'boolean': boolean;
'object': object;
}
type RecursiveTypes = RecursiveArray<keyof TypeStringMap>;
type HasRegexp<T extends RecursiveTypes> =
T extends RecursiveArray<'string' | 'email'> ? { regexp: RegExp } : {}
type HasMinMax<T extends RecursiveTypes> =
T extends RecursiveArray<'number'> ? { min: number, max: number } : {}
type ReifyRecursiveType<T> =
T extends keyof TypeStringMap ? TypeStringMap[T]
: (T extends (infer U)[] ? ReifyRecursiveType<U>[] : never)
type IOptions<T extends RecursiveTypes> = {
type: T;
expected?: ReifyRecursiveType<T>[];
defaultValue?: ReifyRecursiveType<T>,
transform?: <TResult>(value: ReifyRecursiveType<T>) => TResult,
validate?: (value: ReifyRecursiveType<T>) => boolean,
} & HasRegexp<T> & HasMinMax<T>
type IStringOptions = IOptions<'string'>; // has `regexp` field
type IStringOrEmailOptions = IOptions<('string' | 'email')>; // has `regexp` field
type IEmailArrayArrayOptions = IOptions<'email'[][]>; // has `regexp` field
type INumberOptions = IOptions<'number'>; // has `min` and `max` fields

flutter: type 'int' is not a subtype of type 'String' error even if the data structure is correct for model

I have a reward model. which looks like below:
class RewardModel {
String id, status;
DateTime createdAt, updatedAt;
RewardModel({
#required this.id,
#required this.status,
#required this.createdAt,
#required this.updatedAt,
});
}
on the Provide side, I have the following code:
try {
data['collection']['userData']['rewards'].forEach((result){
print(result);
_rewards.add(
RewardModel(
id: result['id'].toString(),
status: status(result['status_id']),
createdAt: DateTime.parse(result['created_at']),
updatedAt: DateTime.parse(result['updated_at']),
)
);
});
} catch (e) {
print(e);
}
I do get the data from the request made and is as followed:
flutter: {id: 1, user_id: 1, status_id: 4, created_at: 2019-12-23 20:54:43, updated_at: 2019-12-23 20:54:43}
flutter: type 'int' is not a subtype of type 'String'
but on the very next line, I get the error. Whats wrong with this?
also below answers are no use to me:
flutter http post "type 'int' is not a subtype of type 'String' in type cast"
type 'int' is not subtype of type 'String' on Flutter
this error happens when you parse int value to String variable
Simply change this line
from
status: status(result['status_id']),
to
status: status(result['status_id'].toString()),
or change this line
from
String status
to
int status

Element implicitly has an 'any' type because type ... has no index signature when accessing the object which key is an enum

I have an object in state and I need to dynamically access its values inside the input component,
var selectedLangTab has a number type
I am trying to get a value by following:
value={userInput.translations[selectedLangTab].title
Error:
Element implicitly has an 'any' type because type '{ 0: { title: string; additionalInfo: string; content: string; language: Language; }; 1: { title: string; additionalInfo: string; content: string; language: Language; }; }' has no index signature.
translations: {
[Language.CS]: {
title: 'Title CZ',
additionalInfo: '',
content: '',
language: Language.CS
},
[Language.EN]: {
title: 'Title EN',
additionalInfo: '',
content: '',
language: Language.EN
}
}
interface of translations:
translations: {
[key in Language]: {
title: string;
additionalInfo: string;
content: string;
language: Language;
}
};
interface of Language:
export enum Language {
CS,
EN
}
The problem is that translations has the two properties (0 and 1) that come from the enum if you are indexing with selectedLangTab which is number there is no guarantee that the number will be in this range, hence the error.
You can defined selectedLangTab to be of type 0 | 1 or Language to make the error go away:
let selectedLangTab: 0 | 1 = 1;
userInput.translations[selectedLangTab].title
Playground link
Or you can use a type assertion to tell the compiler you are sure the number is in teh appropriate range:
let selectedLangTab: number = 1;
userInput.translations[selectedLangTab as Language].title
Playground link

Resources