Closed ootkin closed 10 months ago
@ootkin thank you for using our library and sorry for the delayed response. December was very busy.
I can share some tips on what we've done in our project as an executable script (removed quite a lot of code for simplicity of what should be achived):
#!/usr/bin/env node
/* some other imports*/
// Import the generator function
const { generateOpenAPI } = require(generatorPath);
// Needed so that the route endpoints are "build" and registered into the OpenAPI generator
require(`${__dirname}/../path/to/entry/point/of/the/project/index.js`);
const defaultOutputFile = path.join(__dirname, '..', 'swagger.json');
const document = generateOpenAPI();
// Write data into file
const { components, ...rest } = document;
const jsonData = JSON.stringify({ ...rest, components });
const buildOutputFile = path.join(__dirname, '..', 'build', 'swagger.json');
shell.ShellString(jsonData).to(buildOutputFile);
the key part here is the fact that you've imported the entry point file to load up all definitions (through the exported registry) and only called the generateOpenAPI
function after the definitions are all loaded.
So basically following your example you would need to keep registry
and generateOpenAPI
in that file but move the writeFileSync
into a separate file for the CI part that is only called with the present defnitions.
I hope that helps. Let me know if you need more info or face other problems
Hi All,
after spending like 2 days searching for a good api spec generator, I finally end here.
The problem is that I cannot find a way to structure my project for an easy maintenace.
My structure is like this:
Inside the
*.dto.ts
files I specify all of my zod schema and inopenapi.ts
I've got:How can I do that?
The goal is to call this script in a CI pipeline