Skip to content

Commit

Permalink
chore(spec): read version from package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
c100k committed Mar 25, 2024
1 parent b97752b commit 753168b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ You can play with it by loading it locally in [SwaggerUI](https://swagger.io/too

```sh
# Generate swagger.json (optional since it's already present in the repository)
docker run --rm \
-v $(pwd)/spec:/spec \
oven/bun run \
/spec/generate-swagger.ts
docker run --rm -v $(pwd):/app oven/bun run /app/spec/generate-swagger.ts
yarn lint

# Generate Go code with OpenAPI Generator
docker run --rm \
Expand Down
21 changes: 17 additions & 4 deletions spec/generate-swagger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { readFile } from 'fs/promises';
import { join } from 'path';

import { ExtendedSpecConfig, generateSpec } from 'tsoa';

const basePath = join('/spec');
const controllersPath = join(basePath, 'controllers', '**', '*Controller.ts');
const outputDirectory = join(basePath, '_generated');
const basePath = join('/app');

const pkgJsonPath = join(basePath, 'package.json');
const pkgJsonBuff = await readFile(pkgJsonPath);
const pkgJson = pkgJsonBuff.toString();
const { version }: { version: string } = JSON.parse(pkgJson);

const specBasePath = join(basePath, 'spec');
const controllersPath = join(
specBasePath,
'controllers',
'**',
'*Controller.ts',
);
const outputDirectory = join(specBasePath, '_generated');

const specOptions: ExtendedSpecConfig = {
basePath: '/',
Expand All @@ -24,7 +37,7 @@ const specOptions: ExtendedSpecConfig = {
},
},
specVersion: 3,
version: '0.1.0',
version,
};

await generateSpec(specOptions);

0 comments on commit 753168b

Please sign in to comment.