Skip to content

Commit

Permalink
feat: add lat and long fake
Browse files Browse the repository at this point in the history
Signed-off-by: hxtree <[email protected]>
  • Loading branch information
hxtree committed Nov 1, 2023
1 parent 2161c42 commit 2509e8c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
26 changes: 24 additions & 2 deletions libraries/faker-factory/src/__tests__/get-json-schemas.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line max-classes-per-file
import { Type } from 'class-transformer';
import { IsString, ValidateNested } from 'class-validator';
import { IsLongitude, IsString, ValidateNested } from 'class-validator';
import { IsDiceNotation } from '@cats-cradle/validation-schemas';
import { getJsonSchemas } from '../get-json-schemas';

Expand Down Expand Up @@ -39,7 +39,7 @@ describe('getJsonSchemas', () => {
@IsDiceNotation()
public property: string;
}
const testClass = new TestClass();

const schemas = getJsonSchemas();

expect(schemas).toMatchObject({
Expand All @@ -55,4 +55,26 @@ describe('getJsonSchemas', () => {
},
});
});

it('should get accurate pattern for schemas', async () => {
class Place {
@IsLongitude()
public property: string;
}

const schemas = getJsonSchemas();

expect(schemas).toMatchObject({
Place: {
properties: {
property: {
format: 'longitude',
type: 'string',
},
},
type: 'object',
required: ['property'],
},
});
});
});
4 changes: 4 additions & 0 deletions libraries/faker-factory/src/__tests__/sample-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ValidateNested,
IsOptional,
Type,
IsLongitude,
} from '@cats-cradle/validation-schemas';

export enum SampleEnum {
Expand Down Expand Up @@ -53,6 +54,9 @@ export class SampleClass {
@IsFQDN()
public site: string;

@IsLongitude()
public longitude: string;

@IsString()
@Length(1, 10)
public min: string;
Expand Down
13 changes: 9 additions & 4 deletions libraries/faker-factory/src/get-json-schemas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'reflect-metadata';
import { ValidationTypes } from '@cats-cradle/validation-schemas';
import { validationMetadatasToSchemas } from 'class-validator-jsonschema';
import { defaultMetadataStorage } from 'class-transformer/cjs/storage';
import { SchemasObject } from 'openapi3-ts';
Expand All @@ -14,10 +15,14 @@ export function getJsonSchemas(): SchemasObject {
* {@link} https://www.npmjs.com/package/class-validator-jsonschema
*/
additionalConverters: {
// [ValidationTypes.IS_STRING]: {
// description: 'A string value',
// type: 'string',
// },
isLongitude: {
format: 'longitude',
type: 'string',
},
isLatitude: {
format: 'latitude',
type: 'string',
},
},
});
}
1 change: 1 addition & 0 deletions libraries/validation-schemas/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export {
IsInstance,
IsLatitude,
IsLongitude,
ValidationTypes,
} from 'class-validator';

// work around for validating nested types
Expand Down

0 comments on commit 2509e8c

Please sign in to comment.