Skip to content

Commit

Permalink
Merge pull request #125 from mrjono1/unknown
Browse files Browse the repository at this point in the history
Unknown
  • Loading branch information
mrjono1 authored Jul 7, 2021
2 parents 9607f78 + f4cf6c7 commit ad38bee
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 7 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ This will allow you to reuse a Joi Schema that validates your [Hapi](https://git

For generating Open Api/Swagger this project works with

- [joi-to-swagger](https://github.com/Twipped/joi-to-swagger) using `.meta({className:''})` looking like a better approach
- [hapi-swagger](https://github.com/glennjones/hapi-swagger) using `.label('')` this has been well tested and used in production
- [joi-to-swagger](https://github.com/Twipped/joi-to-swagger) using `.meta({className:''})` limited testing but this is looking like a better approach

Version 2, why the move to `.meta({className:'')` from `.label('')`? `Joi.label()` is intended to be used for meaningful error message, using it for another purpose makes the Joi loose a standard feature, this is especially noticeable for frontend usages of Joi. The choice of the property `className` is because this property is used by joi-to-swagger making this project work with other projects is important.

Expand Down Expand Up @@ -210,10 +210,9 @@ export interface Settings {
- .alternatives()
- .allow('') - will be ignored on a string
- .allow(null) - will add as an optional type eg `string | null`
- .unknown(true) - will add a property `[x: string]: any;`
- .unknown(true) - will add a property `[x: string]: unknown;`
- .example() - jsdoc

Joi Features not listed here will probably be ignored
Any many others

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion 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.0.2",
"version": "2.1.0",
"author": "Jono Clarnette",
"keywords": [
"joi",
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/__tests__/joiExtensions/joiExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const ExtendedJoi = Joi.extend(joi => {
base: joi.string().meta({ baseType: 'string' })
};
return ext;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}).extend((joi: any) => {
const ext: Joi.Extension = {
type: 'dollars',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/unknown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface TestSchema {
/**
* Unknown Property
*/
[x: string]: any;
[x: string]: unknown;
}`);
});

Expand Down
2 changes: 2 additions & 0 deletions src/joiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { Describe } from './joiDescribeTypes';
* @param details - the schema details
* @returns the values for the given field
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getMetadataFromDetails(field: string, details: Describe): any[] {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const metas: any[] = details?.metas ?? [];
return metas.filter(entry => entry[field]).map(entry => entry[field]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ function parseObjects(details: ObjectDescribe, settings: Settings): TypeContent

if (details?.flags?.unknown === true) {
const unknownProperty = {
content: 'any',
content: 'unknown',
interfaceOrTypeName: '[x: string]',
required: true,
jsDoc: { description: 'Unknown Property' }
Expand Down

0 comments on commit ad38bee

Please sign in to comment.