mrjono1 / joi-to-typescript

Convert Joi Schemas to TypeScript interfaces
MIT License
125 stars 39 forks source link

Fix an import-related bug introduced by the `omitIndexFiles` flag #353

Closed cmaster11 closed 1 year ago

cmaster11 commented 1 year ago

The bug would cause imports of generated types to point to the root generation directory (still expecting an index.ts file as if omitIndexFiles was false) instead of pointing to each individually generated file.

Given the custom scheme (in ./Inner.ts)

import Joi from 'joi';
export const InnerSchema = Joi.object({
  hello: Joi.string()
}).meta({ className: 'InnerInterface' });

Imported with (in ./FooBar.ts):

import Joi from 'joi';
import { InnerSchema } from './InnerSchema';

export const BarSchema = Joi.object({
  id: Joi.number().required().description('Id').example(1),
  inner: InnerSchema
}).meta({ className: 'Bar' });

Generates (in interfaces/FooBar.ts):

With bug (causing TS compilation issues):

import { InnerInterface } from '.'

After bug fix:

import { InnerInterface } from './Inner'
codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (28fb60e) 98.62% compared to head (16e2a27) 98.63%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #353 +/- ## ======================================= Coverage 98.62% 98.63% ======================================= Files 9 9 Lines 508 511 +3 Branches 194 197 +3 ======================================= + Hits 501 504 +3 Misses 7 7 ``` | [Files Changed](https://app.codecov.io/gh/mrjono1/joi-to-typescript/pull/353?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jono) | Coverage Δ | | |---|---|---| | [src/writeInterfaceFile.ts](https://app.codecov.io/gh/mrjono1/joi-to-typescript/pull/353?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jono#diff-c3JjL3dyaXRlSW50ZXJmYWNlRmlsZS50cw==) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.