Skip to content

Commit

Permalink
Support namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
akhromets committed May 8, 2024
1 parent 36a27ef commit 88df3ba
Show file tree
Hide file tree
Showing 15 changed files with 472 additions and 16 deletions.
21 changes: 21 additions & 0 deletions .snapshot/all/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export interface ICategory {
name: $types.TypeOrUndefinedNullable<string>;
}

export interface IMyProduct.Core.Models.Feedback {
name: $types.TypeOrUndefinedNullable<string>;
}

export interface IProduct {
category: $types.TypeOrUndefinedNullable<ICategory>;
colors: $types.TypeOrUndefined<string[]>;
Expand Down Expand Up @@ -57,6 +61,23 @@ export class Category {
}
}

export class MyProduct.Core.Models.Feedback {
public name: $types.TypeOrUndefinedNullable<string> = undefined;
private __myProduct.Core.Models.Feedback!: string;

public static toDTO(model: Partial<MyProduct.Core.Models.Feedback>): IMyProduct.Core.Models.Feedback {
return {
name: model.name,
};
}

public static fromDTO(dto: IMyProduct.Core.Models.Feedback): MyProduct.Core.Models.Feedback {
const model = new MyProduct.Core.Models.Feedback();
model.name = dto.name;
return model;
}
}

export class Product {
public category: $types.TypeOrUndefinedNullable<Category> = undefined;
public colors: string[] = [];
Expand Down
3 changes: 2 additions & 1 deletion .snapshot/all/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ export class FeedbackService extends BaseHttpService {
super(getBasePath('', '/api/feedback'), http);
}

public postFeedback(): Observable<void> {
public postFeedback(myProduct.Core.Models.Feedback: $models.IMyProduct.Core.Models.Feedback): Observable<void> {
return this.post<void>(
``,
myProduct.Core.Models.Feedback,
);
}
}
Expand Down
117 changes: 117 additions & 0 deletions .snapshot/joinNamespace/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { Guid } from './Guid';
import { toDateIn, toDateOut } from './date-converters';
import type * as $types from './types';

export enum ProductStatus {
InStock = 0,
OutOfStock = -1,
UnderTheOrder = 1
}

export interface ICategory {
name: $types.TypeOrUndefinedNullable<string>;
}

export interface IMyProductCoreModelsFeedback {
name: $types.TypeOrUndefinedNullable<string>;
}

export interface IProduct {
category: $types.TypeOrUndefinedNullable<ICategory>;
colors: $types.TypeOrUndefined<string[]>;
expireDate: $types.TypeOrUndefined<string>;
externalId: $types.TypeOrUndefinedNullable<string>;
id: $types.TypeOrUndefined<string>;
modifyDates: $types.TypeOrUndefined<string[]>;
name: $types.TypeOrUndefinedNullable<string>;
status: $types.TypeOrUndefined<ProductStatus>;
}

export interface IProductIdentityDTO {
id: $types.TypeOrUndefined<string>;
}

export class ProductIdentityDTO {
public id: Guid;
private __productIdentityDTO!: string;

constructor(id?: $types.TypeOrUndefined<Guid | string>) {
this.id = new Guid(id);
}

public static toDTO(id: Guid): IProductIdentityDTO {
return { id: id.toString() };
}
}

export class Category {
public name: $types.TypeOrUndefinedNullable<string> = undefined;
private __category!: string;

public static toDTO(model: Partial<Category>): ICategory {
return {
name: model.name,
};
}

public static fromDTO(dto: ICategory): Category {
const model = new Category();
model.name = dto.name;
return model;
}
}

export class MyProductCoreModelsFeedback {
public name: $types.TypeOrUndefinedNullable<string> = undefined;
private __myProductCoreModelsFeedback!: string;

public static toDTO(model: Partial<MyProductCoreModelsFeedback>): IMyProductCoreModelsFeedback {
return {
name: model.name,
};
}

public static fromDTO(dto: IMyProductCoreModelsFeedback): MyProductCoreModelsFeedback {
const model = new MyProductCoreModelsFeedback();
model.name = dto.name;
return model;
}
}

export class Product {
public category: $types.TypeOrUndefinedNullable<Category> = undefined;
public colors: string[] = [];
public expireDate: $types.TypeOrUndefined<Date> = undefined;
public externalId: $types.TypeOrUndefinedNullable<Guid> = undefined;
public id: $types.TypeOrUndefined<Guid> = undefined;
public modifyDates: Date[] = [];
public name: $types.TypeOrUndefinedNullable<string> = undefined;
public status: $types.TypeOrUndefined<ProductStatus> = undefined;
private __product!: string;

public static toDTO(model: Partial<Product>): IProduct {
return {
category: model.category ? Category.toDTO(model.category) : undefined,
colors: model.colors,
expireDate: toDateOut(model.expireDate),
externalId: model.externalId ? model.externalId.toString() : null,
id: model.id ? model.id.toString() : Guid.empty.toString(),
modifyDates: model.modifyDates ? model.modifyDates.map(toDateOut) : undefined,
name: model.name,
status: model.status,
};
}

public static fromDTO(dto: IProduct): Product {
const model = new Product();
model.category = dto.category ? Category.fromDTO(dto.category) : undefined;
model.colors = dto.colors ? dto.colors : [];
model.expireDate = toDateIn(dto.expireDate);
model.externalId = dto.externalId ? new Guid(dto.externalId) : null;
model.id = new Guid(dto.id);
model.modifyDates = dto.modifyDates ? dto.modifyDates.map(toDateIn) : [];
model.name = dto.name;
model.status = dto.status;
return model;
}
}
117 changes: 117 additions & 0 deletions .snapshot/truncateNamespace/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { Guid } from './Guid';
import { toDateIn, toDateOut } from './date-converters';
import type * as $types from './types';

export enum ProductStatus {
InStock = 0,
OutOfStock = -1,
UnderTheOrder = 1
}

export interface ICategory {
name: $types.TypeOrUndefinedNullable<string>;
}

export interface IFeedback {
name: $types.TypeOrUndefinedNullable<string>;
}

export interface IProduct {
category: $types.TypeOrUndefinedNullable<ICategory>;
colors: $types.TypeOrUndefined<string[]>;
expireDate: $types.TypeOrUndefined<string>;
externalId: $types.TypeOrUndefinedNullable<string>;
id: $types.TypeOrUndefined<string>;
modifyDates: $types.TypeOrUndefined<string[]>;
name: $types.TypeOrUndefinedNullable<string>;
status: $types.TypeOrUndefined<ProductStatus>;
}

export interface IProductIdentityDTO {
id: $types.TypeOrUndefined<string>;
}

export class ProductIdentityDTO {
public id: Guid;
private __productIdentityDTO!: string;

constructor(id?: $types.TypeOrUndefined<Guid | string>) {
this.id = new Guid(id);
}

public static toDTO(id: Guid): IProductIdentityDTO {
return { id: id.toString() };
}
}

export class Category {
public name: $types.TypeOrUndefinedNullable<string> = undefined;
private __category!: string;

public static toDTO(model: Partial<Category>): ICategory {
return {
name: model.name,
};
}

public static fromDTO(dto: ICategory): Category {
const model = new Category();
model.name = dto.name;
return model;
}
}

export class Feedback {
public name: $types.TypeOrUndefinedNullable<string> = undefined;
private __feedback!: string;

public static toDTO(model: Partial<Feedback>): IFeedback {
return {
name: model.name,
};
}

public static fromDTO(dto: IFeedback): Feedback {
const model = new Feedback();
model.name = dto.name;
return model;
}
}

export class Product {
public category: $types.TypeOrUndefinedNullable<Category> = undefined;
public colors: string[] = [];
public expireDate: $types.TypeOrUndefined<Date> = undefined;
public externalId: $types.TypeOrUndefinedNullable<Guid> = undefined;
public id: $types.TypeOrUndefined<Guid> = undefined;
public modifyDates: Date[] = [];
public name: $types.TypeOrUndefinedNullable<string> = undefined;
public status: $types.TypeOrUndefined<ProductStatus> = undefined;
private __product!: string;

public static toDTO(model: Partial<Product>): IProduct {
return {
category: model.category ? Category.toDTO(model.category) : undefined,
colors: model.colors,
expireDate: toDateOut(model.expireDate),
externalId: model.externalId ? model.externalId.toString() : null,
id: model.id ? model.id.toString() : Guid.empty.toString(),
modifyDates: model.modifyDates ? model.modifyDates.map(toDateOut) : undefined,
name: model.name,
status: model.status,
};
}

public static fromDTO(dto: IProduct): Product {
const model = new Product();
model.category = dto.category ? Category.fromDTO(dto.category) : undefined;
model.colors = dto.colors ? dto.colors : [];
model.expireDate = toDateIn(dto.expireDate);
model.externalId = dto.externalId ? new Guid(dto.externalId) : null;
model.id = new Guid(dto.id);
model.modifyDates = dto.modifyDates ? dto.modifyDates.map(toDateIn) : [];
model.name = dto.name;
model.status = dto.status;
return model;
}
}
3 changes: 2 additions & 1 deletion .snapshot/withRequestOptions/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ export class FeedbackService extends BaseHttpService {
super(getBasePath('', '/api/feedback'), http);
}

public postFeedback(options?: $types.TypeOrUndefined<IAngularHttpRequestOptions>): Observable<void> {
public postFeedback(myProduct.Core.Models.Feedback: $models.IMyProduct.Core.Models.Feedback, options?: $types.TypeOrUndefined<IAngularHttpRequestOptions>): Observable<void> {
return this.post<void>(
``,
myProduct.Core.Models.Feedback,
options,
);
}
Expand Down
82 changes: 77 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ gengen g --all
### Options
| Option | Description | Type | Default value |
| ---------------------- | ------------------------------------------------------------------------------------------ | ------- | ---------------------------------------------- |
|------------------------|--------------------------------------------------------------------------------------------|---------|------------------------------------------------|
| **all** | Generate all | boolean | false |
| **url** | Location of swagger.json | string | https://localhost:5001/swagger/v1/swagger.json |
| **file** | Local path to swagger.json | string | |
| **output** | Output directory | string | ./src/generated |
| **configOutput** | Output directory using in 'Generate a part of API' scenario | string | ./.generated |
| **aliasName** | Specify prefix for generated filenames. [more info](#aliasName) | string | |
| **withRequestOptions** | Allows to pass http request options to generated methods. [more info](#withRequestOptions) | boolean | false |
| **utilsRelativePath** | Relative path to utils files. It may be useful when you have multiple generation sources | string | |
| **unstrictId** | Disable converting 'id' properties to strong Guid type. [more info](#unstrictId) | boolean | false |
| **withRequestOptions** | Allows to pass http request options to generated methods. [more info](#withRequestOptions) | boolean | false |
| **utilsRelativePath** | Relative path to utils files. It may be useful when you have multiple generation sources | string | |
| **unstrictId** | Disable converting 'id' properties to strong Guid type. [more info](#unstrictId) | boolean | false |
| **truncateNamespace** | Generate schema object name with truncating namespace [more info](#fixNamespace) | boolean | false |
| **joinNamespace** | Join schema object name by dot [more info](#fixNamespace) | boolean | false |
| |
### Option details
Expand Down Expand Up @@ -144,8 +146,78 @@ public static fromDTO(dto: IProduct): Product {
}
```
#### fixNamespace
By default, GenGen generates model names with dots if any.
Example:
Object name in `Schemas` definition:
`MyProduct.Core.Models.Product`
Default behavior:
```ts
export interface IMyProduct.Core.Models.Product {}
export class MyProduct.Core.Models.Product {
private __myProduct.Core.Models.Product!: string;
public static toDTO(model: Partial<MyProduct.Core.Models.Product>): IMyProduct.Core.Models.Product {
return {};
}
public static fromDTO(dto: IMyProduct.Core.Models.Product): MyProduct.Core.Models.Product {
const model = new MyProduct.Core.Models.Product();
return model;
}
}
```
You can truncate or join namespace for the model name by using these options:
1. With `truncateNamespace` option enabled:
```ts
export interface IProduct {}
export class Product {
private __product!: string;
public static toDTO(model: Partial<Product>): IProduct {
return {
};
}
public static fromDTO(dto: IProduct): Product {
const model = new Product();
return model;
}
}
```
2. With `joinNamespace` option enabled:
```ts
export interface IMyProductCoreModelsProduct {}
export class MyProductCoreModelsProduct {
private __myProductCoreModelsProduct!: string;
public static toDTO(model: Partial<MyProductCoreModelsProduct>): IMyProductCoreModelsProduct {
return {};
}
public static fromDTO(dto: IMyProductCoreModelsProduct): MyProductCoreModelsProduct {
const model = new MyProductCoreModelsProduct();
return model;
}
}
```
# License and copyright
Copyright (c) 2020-2023 Luxoft
Copyright (c) 2020-2024 Luxoft
Licensed under the MIT license
Loading

0 comments on commit 88df3ba

Please sign in to comment.