Skip to content

Commit 6f81f99

Browse files
committed
Major refactor (part 2) towards FUTURE.md
1 parent 6345d6d commit 6f81f99

File tree

121 files changed

+520
-1476
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+520
-1476
lines changed

src/service/analysis/form-model.builder.ts renamed to src/analysis/form-model.builder.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { FormProperty, Resource, SwaggerDefinition } from "../../core/types.js";
2-
import { SwaggerParser } from "../../core/parser.js";
3-
import { camelCase, getTypeScriptType, pascalCase, singular } from "../../core/utils.js";
4-
import { mapSchemaToFormControl } from "../emit/admin/form-control.mapper.js";
5-
import { FormAnalysisResult, FormControlModel, PolymorphicOptionModel } from "./form-types.js";
1+
import { FormProperty, Resource, SwaggerDefinition } from "@src/core/types/index.js";
2+
import { SwaggerParser } from '@src/core/parser.js';
3+
import { getTypeScriptType, pascalCase, singular } from "@src/core/utils/index.js";
4+
import { mapSchemaToFormControl } from "@src/generators/angular/admin/form-control.mapper.js";
5+
6+
import { FormAnalysisResult, FormControlModel } from "./form-types.js";
67

78
export class FormModelBuilder {
89
private parser: SwaggerParser;
@@ -27,7 +28,7 @@ export class FormModelBuilder {
2728
if (oneOfProp) {
2829
this.result.isPolymorphic = true;
2930
this.result.discriminatorPropName = oneOfProp.schema.discriminator!.propertyName;
30-
this.analyzePolymorphism(oneOfProp, resource.modelName);
31+
this.analyzePolymorphism(oneOfProp);
3132
}
3233

3334
// 2. Build Top Level Controls & Interfaces
@@ -183,7 +184,7 @@ export class FormModelBuilder {
183184
return controls;
184185
}
185186

186-
private analyzePolymorphism(prop: FormProperty, rootModelName: string) {
187+
private analyzePolymorphism(prop: FormProperty) {
187188
const options = this.parser.getPolymorphicSchemaOptions(prop.schema);
188189
this.result.discriminatorOptions = options.map(o => o.name);
189190
this.result.polymorphicOptions = [];
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SwaggerDefinition } from "../../core/types.js";
1+
import { SwaggerDefinition } from "@src/core/types/index.js";
22

33
export type ControlType = 'control' | 'group' | 'array';
44

src/service/analysis/list-model.builder.ts renamed to src/analysis/list-model.builder.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { FormProperty, Resource } from "../../core/types.js";
2-
import { camelCase, pascalCase } from "../../core/utils.js";
1+
import { Resource } from "@src/core/types/index.js";
2+
import { pascalCase } from "@src/core/utils/index.js";
3+
34
import { ListAction, ListColumn, ListViewModel } from "./list-types.js";
45

56
export class ListModelBuilder {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ResourceOperation } from "../../core/types.js";
1+
import { ResourceOperation } from "@src/core/types/index.js";
22

33
export interface ListColumn {
44
key: string; // Property name (e.g. 'email')

src/service/analysis/service-method-analyzer.ts renamed to src/analysis/service-method-analyzer.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import {
33
Parameter,
44
PathInfo,
55
SwaggerDefinition
6-
} from '../../core/types.js';
6+
} from '@src/core/types/index.js';
77
import {
88
camelCase,
99
getTypeScriptType,
1010
isDataTypeInterface
11-
} from '../../core/utils.js';
12-
import { SwaggerParser } from '../../core/parser.js';
11+
} from '@src/core/utils/index.js';
12+
import { SwaggerParser } from '@src/core/parser.js';
1313
import { OptionalKind, ParameterDeclarationStructure } from 'ts-morph';
1414
import { BodyVariant, ParamSerialization, ServiceMethodModel } from './service-method-types.js';
1515

@@ -39,10 +39,10 @@ export class ServiceMethodAnalyzer {
3939
const serialization: ParamSerialization = {
4040
paramName: this.isXmlContent(p) ? `${paramName}Serialized` : paramName,
4141
originalName: p.name,
42-
style: p.style,
4342
explode: p.explode ?? (p.in === 'cookie' ? true : false), // Cookie default explode is true
4443
allowReserved: p.allowReserved ?? false,
45-
serializationLink: this.isJsonContent(p) ? 'json' : undefined
44+
serializationLink: this.isJsonContent(p) ? 'json' : undefined,
45+
...(p.style != null && {style: p.style})
4646
};
4747

4848
switch (p.in) {
@@ -96,10 +96,10 @@ export class ServiceMethodAnalyzer {
9696
queryParams,
9797
headerParams,
9898
cookieParams,
99-
body,
10099
security: effectiveSecurity,
101100
hasServers: !!basePath,
102-
basePath
101+
...(body != null && { body }),
102+
...(basePath != null && { basePath })
103103
};
104104
}
105105

@@ -141,7 +141,7 @@ export class ServiceMethodAnalyzer {
141141
name: camelCase(param.name),
142142
type: paramType,
143143
hasQuestionToken: !param.required,
144-
leadingTrivia: param.deprecated ? [`/** @deprecated */ `] : undefined
144+
...(param.deprecated && {leadingTrivia: [`/** @deprecated */ `]})
145145
});
146146
});
147147

File renamed without changes.

src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import * as fs from 'node:fs';
55
import * as path from 'node:path';
66
import yaml from 'js-yaml';
77
import { generateFromConfig } from './index.js';
8-
import { GeneratorConfig, GeneratorConfigOptions } from './core/types.js';
9-
import { isUrl } from './core/utils.js';
8+
import { GeneratorConfig, GeneratorConfigOptions } from "@src/core/types/index.js";
9+
import { isUrl } from "@src/core/utils/index.js";
1010

1111
const packageJsonPath = new URL('../package.json', import.meta.url);
1212
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));

src/component/emit.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/component/parse.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/core/generator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Project } from 'ts-morph';
2-
import { SwaggerParser } from './parser.js';
2+
33
import { GeneratorConfig } from './types/config.js';
4+
import { SwaggerParser } from './parser.js';
45

56
/**
67
* Abstract contracts for framework-specific generators.

0 commit comments

Comments
 (0)