Skip to content

Commit

Permalink
Merge pull request #166 from mrjono1/update
Browse files Browse the repository at this point in the history
formatted all code
  • Loading branch information
mrjono1 authored Nov 22, 2021
2 parents a2c4793 + 449dbc6 commit c9a7ffd
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 333 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "joi-to-typescript",
"description": "Convert Joi Schemas to TypeScript interfaces",
"version": "2.2.2",
"version": "2.3.0",
"author": "Jono Clarnette",
"keywords": [
"joi",
Expand All @@ -22,7 +22,7 @@
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
"format": "prettier --write \"src/**/*.ts\"",
"lint": "eslint 'src/**'",
"test": "jest --config jest.config.js",
"coverage": "yarn test --coverage --silent",
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/allow/allow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export interface Parent {
test('Enum `allow()`', () => {
enum Test {
Option1 = 0,
Option2 = 1,
Option3 = 2
Option2 = 1,
Option3 = 2
}

const schema = Joi.object({
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/cast/schemas/OneSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import Joi from 'joi';

export const NumberSchema = Joi.object({
bool: Joi.boolean().cast('number').required(),
day: Joi.date().cast('number').required(),
day: Joi.date().cast('number').required()
}).meta({ className: 'Numbers' });

export const StringSchema = Joi.object({
num: Joi.number().cast('string').required()
}).meta({ className: 'Strings' })
}).meta({ className: 'Strings' });

export const StringType = Joi.number().cast('string')
export const StringType = Joi.number().cast('string');

export const NumberType = Joi.boolean().cast('number')
export const NumberType = Joi.boolean().cast('number');
4 changes: 1 addition & 3 deletions src/__tests__/concat/schemas/FooBarSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ export const BarSchema = Joi.object({
b: Joi.string()
}).meta({ className: 'Bar' });

export const FooBarSchema = FooSchema
.concat(BarSchema)
.meta({ className: 'FooBar' });
export const FooBarSchema = FooSchema.concat(BarSchema).meta({ className: 'FooBar' });
2 changes: 1 addition & 1 deletion src/__tests__/joiExtensions/joiExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ExtendedJoi = Joi.extend(joi => {
base: joi.string().meta({ baseType: 'string' })
};
return ext;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}).extend((joi: any) => {
const ext: Joi.Extension = {
type: 'dollars',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/unknown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export interface TestSchema {
name: Joi.string()
})
.meta({ className: 'TestSchema', unknownType: 'number' })
.description('a test schema definition').
pattern(Joi.string(), Joi.number());
.description('a test schema definition')
.pattern(Joi.string(), Joi.number());

const result = convertSchema({ sortPropertiesByName: false }, schema);
expect(result).not.toBeUndefined;
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function defaultSettings(settings: Partial<Settings>): Settings {
commentEverything: false,
ignoreFiles: [],
indentationChacters: ' ',
honorCastTo: [],
honorCastTo: []
},
settings
) as Settings;
Expand Down
8 changes: 4 additions & 4 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ export function parseSchema(
): TypeContent | undefined {
function parseHelper(): TypeContent | undefined {
// Convert type if a valid cast type is present
if (details.flags?.cast && validCastTo.includes(details.flags?.cast as ('number' | 'string'))) {
if (details.flags?.cast && validCastTo.includes(details.flags?.cast as 'number' | 'string')) {
// @NOTE - if additional values are added beyond 'string' and 'number' further transformation will
// be needed on the details object to support those types
details.type = details.flags?.cast as ('string' | 'number');
details.type = details.flags?.cast as 'string' | 'number';
}

switch (details.type) {
Expand Down Expand Up @@ -417,8 +417,8 @@ function parseObjects(details: ObjectDescribe, settings: Settings): TypeContent
parsedSchema.interfaceOrTypeName = /^[$A-Z_][0-9A-Z_$]*$/i.test(key || '') ? key : `'${key}'`;
return parsedSchema;
});
const isMap=details.patterns?.length===1&&details.patterns[0].schema.type==="string";
if (details?.flags?.unknown === true||isMap) {
const isMap = details.patterns?.length === 1 && details.patterns[0].schema.type === 'string';
if (details?.flags?.unknown === true || isMap) {
let unknownType = 'unknown';
const unknownTypes: string[] = getMetadataFromDetails('unknownType', details);
if (unknownTypes.length > 0) {
Expand Down
595 changes: 281 additions & 314 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit c9a7ffd

Please sign in to comment.