Skip to content

Commit

Permalink
Merge pull request #95 from Luxoft/develop
Browse files Browse the repository at this point in the history
Release candidate 7
  • Loading branch information
aleshchev authored Nov 15, 2021
2 parents 3d5899b + 9b017fa commit 62d330a
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .snapshot/all/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface IProduct {
expireDate: $types.TypeOrUndefined<string>;
externalId: $types.TypeOrUndefinedNullable<string>;
id: $types.TypeOrUndefined<string>;
modifyDates: $types.TypeOrUndefined<string[]>;
name: $types.TypeOrUndefinedNullable<string>;
status: $types.TypeOrUndefined<ProductStatus>;
}
Expand Down Expand Up @@ -60,6 +61,7 @@ export class Product {
public expireDate: $types.TypeOrUndefined<Date> = undefined;
public externalId: $types.TypeOrUndefinedNullable<Guid> = undefined;
public id: $types.TypeOrUndefined<Guid> = undefined;
public modifyDates: $types.TypeOrUndefined<Date[]> = undefined;
public name: $types.TypeOrUndefinedNullable<string> = undefined;
public status: $types.TypeOrUndefined<ProductStatus> = undefined;
private __product!: string;
Expand All @@ -70,6 +72,7 @@ export class Product {
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,
};
Expand All @@ -81,6 +84,7 @@ export class Product {
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;
Expand Down
14 changes: 12 additions & 2 deletions __tests__/swagger/OpenAPITypesGuard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,18 @@ describe('OpenAPITypesGuard tests', () => {
});
});

test('isString', () => {
expect(guard.isString({ type: 'string' })).toBeTruthy();
describe('isString', () => {
test('date', () => {
expect(guard.isString({ type: 'string', format: 'date-time' })).toBeFalsy();
});

test('guid', () => {
expect(guard.isString({ type: 'string', format: 'uuid' })).toBeFalsy();
});

test('string', () => {
expect(guard.isString({ type: 'string' })).toBeTruthy();
});
});

test('isDate', () => {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luxbss/gengen",
"version": "1.0.0-rc.6",
"version": "1.0.0-rc.7",
"description": "Tool for generating models and Angular services based on OpenAPIs and Swagger's JSON",
"bin": {
"gengen": "./bin/index.js"
Expand Down
8 changes: 8 additions & 0 deletions src/generators/ModelsGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ export class ModelsGenerator {

switch (property.kind) {
case PropertyKind.Date:
if (property.isCollection) {
return `${modelProperty} ? ${modelProperty}.map(toDateOut) : ${UNDEFINED_STRING}`;
}

return `toDateOut(${modelProperty})`;

case PropertyKind.Guid:
Expand Down Expand Up @@ -208,6 +212,10 @@ export class ModelsGenerator {

switch (property.kind) {
case PropertyKind.Date:
if (property.isCollection) {
return `${dtoProperty} ? ${dtoProperty}.map(toDateIn) : []`;
}

return `toDateIn(${dtoProperty})`;

case PropertyKind.Guid:
Expand Down
10 changes: 5 additions & 5 deletions src/swagger/OpenAPITypesGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class OpenAPITypesGuard {
}

public isGuid(schema: SchemaType): schema is IOpenAPI3GuidSchema {
return this.isString(schema) && (schema as IOpenAPI3GuidSchema)?.format === 'uuid';
return (schema as IOpenAPI3StringSchema)?.type === 'string' && (schema as IOpenAPI3GuidSchema)?.format === 'uuid';
}

public isCollection(schema: SchemaType): schema is IOpenAPI3ArraySchema {
Expand Down Expand Up @@ -56,18 +56,18 @@ export class OpenAPITypesGuard {
}

public isString(schema: SchemaType): schema is IOpenAPI3StringSchema {
return (schema as IOpenAPI3StringSchema)?.type === 'string';
return (schema as IOpenAPI3StringSchema)?.type === 'string' && (schema as { format: string | undefined })?.format === undefined;
}

public isDate(schema: SchemaType): schema is IOpenAPI3DateSchema {
return this.isString(schema) && (schema as IOpenAPI3DateSchema)?.format === 'date-time';
return (schema as IOpenAPI3StringSchema)?.type === 'string' && (schema as IOpenAPI3DateSchema)?.format === 'date-time';
}

public isBoolean(schema: SchemaType): schema is IOpenAPI3BooleanSchema {
return (schema as IOpenAPI3BooleanSchema)?.type === 'boolean';
}

public isSimple(schema: SchemaType): schema is OpenAPI3SimpleSchema {
return this.isGuid(schema) || this.isNumber(schema) || this.isString(schema) || this.isDate(schema) || this.isBoolean(schema);
return this.isGuid(schema) || this.isNumber(schema) || this.isDate(schema) || this.isString(schema) || this.isBoolean(schema);
}
}
}
8 changes: 8 additions & 0 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,14 @@
"type": "string",
"format": "date-time"
},
"modifyDates": {
"type": "array",
"items": {
"type": "string",
"format": "date-time"
},
"nullable": true
},
"category": {
"$ref": "#/components/schemas/Category"
},
Expand Down

0 comments on commit 62d330a

Please sign in to comment.