Merge pull request #15206 from abpframework/generate-proxy-null-check

Add null-check to api-definition.ts
pull/15207/head
Muhammed Altuğ 3 years ago committed by GitHub
commit 7eb487e194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -40,11 +40,11 @@ export interface Controller {
export interface InterfaceDef { export interface InterfaceDef {
type: string; type: string;
name: string; name: string;
methods: InterfaceMethodDef[]; methods?: InterfaceMethodDef[];
} }
export interface InterfaceMethodDef { export interface InterfaceMethodDef {
name: string; name: string;
parametersOnMethod: InterfaceParameterOnMethodDef[]; parametersOnMethod?: InterfaceParameterOnMethodDef[];
returnValue: { returnValue: {
type: string; type: string;
typeSimple: string; typeSimple: string;

@ -41,12 +41,12 @@ const sanitizeTypeName = (name: string) => name.replace(sanitizeTypeNameRegExp,
export function sanitizeControllerTypeNames( export function sanitizeControllerTypeNames(
controllers: Record<string, Controller>, controllers: Record<string, Controller>,
): Record<string, Controller> { ): Record<string, Controller> {
Object.values(controllers).forEach(controller => { Object.values(controllers || {}).forEach(controller => {
controller.interfaces.forEach(i => { controller.interfaces?.forEach(i => {
i.methods.forEach(m => { i.methods?.forEach(m => {
m.returnValue.type = sanitizeTypeName(m.returnValue.type); m.returnValue.type = sanitizeTypeName(m.returnValue.type);
m.returnValue.typeSimple = sanitizeTypeName(m.returnValue.typeSimple); m.returnValue.typeSimple = sanitizeTypeName(m.returnValue.typeSimple);
m.parametersOnMethod.forEach(p => { m.parametersOnMethod?.forEach(p => {
p.type = sanitizeTypeName(p.type); p.type = sanitizeTypeName(p.type);
p.typeAsString = sanitizeTypeName(p.typeAsString); p.typeAsString = sanitizeTypeName(p.typeAsString);
p.typeSimple = sanitizeTypeName(p.typeSimple); p.typeSimple = sanitizeTypeName(p.typeSimple);
@ -54,15 +54,15 @@ export function sanitizeControllerTypeNames(
}); });
}); });
Object.values(controller.actions).forEach(a => { Object.values(controller.actions || {}).forEach(a => {
a.returnValue.type = sanitizeTypeName(a.returnValue.type); a.returnValue.type = sanitizeTypeName(a.returnValue.type);
a.returnValue.typeSimple = sanitizeTypeName(a.returnValue.typeSimple); a.returnValue.typeSimple = sanitizeTypeName(a.returnValue.typeSimple);
a.parametersOnMethod.forEach(p => { a.parametersOnMethod?.forEach(p => {
p.type = sanitizeTypeName(p.type); p.type = sanitizeTypeName(p.type);
p.typeAsString = sanitizeTypeName(p.typeAsString); p.typeAsString = sanitizeTypeName(p.typeAsString);
p.typeSimple = sanitizeTypeName(p.typeSimple); p.typeSimple = sanitizeTypeName(p.typeSimple);
}); });
a.parameters.forEach(p => { a.parameters?.forEach(p => {
p.type = sanitizeTypeName(p.type); p.type = sanitizeTypeName(p.type);
p.typeSimple = sanitizeTypeName(p.typeSimple); p.typeSimple = sanitizeTypeName(p.typeSimple);
}); });

Loading…
Cancel
Save