question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

More flexible API

See original GitHub issue

Hi there, first of all thanks for a great job so far!

The library works fine with a one directory that have only one directory with joi schemas But it is not really comfortable otherwise, especially if you have dozen of joi schemas and complex structure in your project

What about breaking major changes in API? why not to use glob in search joi schema files?

const defaultOutputFile = (srcPath: string, fileName: string) =>  path.join(
     srcPath, 
    `${path.basename(fileName, '.ts')}.type.ts`
)

export function convertFromDirectory({
    schemaFile,
    outputFile = defaultOutputFile,
    // ...
}{
    schemaFile: string | string[];
    outputFile?: (scrPath: string, fileName: string) => string
    // ...
}) {
    // ... implementation
} 

Benefits The usage is more flexible and fits more use cases. Below old options can be dropped from API because it could be done by this new realisation

  1. schemaFileSuffix
 convertFromDirectory({
    schemaFile: './src/**/*.schema.ts',
    outputFile: (srcPath: string, fileName: string) => path.join(srcPath, fileName.replace('.schema', '')),
}})
  1. flattenTree
convertFromDirectory({
    schemaFile: './src/**/*.schema.ts',
    outputFile: (srcPath: string, fileName: string) => path.join('./src/types', fileName),
}})
  1. rootDirectoryOnly
convertFromDirectory({
    schemaFile: './src/*.schema.ts',
}})
  1. ignoreFiles can be be done by glob in a variety of ways out of box

Caveats I am not sure about indexAllToRoot — it could be hard to implement

What do you think? Will you accept such PR?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mo4islonacommented, Sep 2, 2021

Sure.

Dont had much time for work but enough to implement basic features

https://github.com/mo4islona/joi-to-typescript/pull/1

the progress of tests

  • none ✅
  • primitives types ✅
  • multiple file - I ve stacked here 😩

I have a problem if schemas names will have a collisions (that i have in my own project) of external schemas names and physical file paths To resolve it we must known from what source file path is schema imported (which seems to be a very complicated)

Looking for a solution.

0reactions
mrjono1commented, Sep 2, 2021

Thankyou I’ll see if i can help

Read more comments on GitHub >

github_iconTop Results From Across the Web

3 Ways to Make Your API Responses Flexible - Zapier
Most APIs deliver their responses the exact same way to every client. That's by design; developers need to know what to expect.
Read more >
Designing a Usable, Flexible, Long-Lasting API - DZone
This DZone Guide article takes a look at how to design a usable, flexible, and long-lasting API. also explore best practices and also ......
Read more >
Flexible API - Flexie CRM
Easily integrate Flexie CRM through our RESTful API. Add leads, deals, contacts or accounts from your application without having to access Flexie. Edit...
Read more >
Designing and implementing flexible RESTful services - Medium
To clarify the problem a little further, I wanted to use the same client API for all data types e.g. mileage, user, company,...
Read more >
The art of creating simple but flexible APIs - Jos de Jong
While Underscores implementation is more flexible, Scott argues that Ramda's more limited implementation may be the better choice because of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found