Skip to content

Commit a580b51

Browse files
committed
working test-harness
1 parent bcd23dc commit a580b51

37 files changed

+3989
-228
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ See the [generator examples](#examples) section for a demo.
102102
```
103103

104104
-p <name> The name of the project to generate
105-
--projectName=<name> [default: generatedProject]
105+
--projectName=<name> [default: generated-javascript-project]
106106

107107
-b <dir> --baseDir=<dir> Directory to generate the project in.
108108
This directory must already exist.
@@ -161,7 +161,7 @@ as the pet returned by service.js does not match the response schema.
161161

162162
<a name="generatorExamples"></a>
163163
### Generator
164-
The folder [examples/generatedProject](examples/generatedProject) contains the result of running `openapi-glue -l --baseDir=examples examples/petstore/petstore-swagger.v2.yaml`. The generated code can be started using `npm start` in `examples/generatedProject` (you will need to run `npm i` in the generated folder first)
164+
The folder [examples/generated-javascript-project](examples/generated-javascript-project) contains the result of running `openapi-glue -l --baseDir=examples examples/petstore/petstore-swagger.v2.yaml`. The generated code can be started using `npm start` in `examples/generated-javascript-project` (you will need to run `npm i` in the generated folder first)
165165
<a name="Notes"></a>
166166
## Notes
167167
- the plugin ignores information in a v3 specification under `server/url` as there could be multiple values here, use the `prefix` [option](#pluginOptions) if you need to prefix your routes. See the [servers documentation](docs/servers.md) for more details.

bin/openapi-glue-cli.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import argvParser from "minimist";
77
import { exit } from "process";
88
const __filename = fileURLToPath(import.meta.url);
99

10+
const validTypes = new Set(["javascript", "standaloneJS"]);
11+
1012
function usage() {
1113
console.log(`
1214
Usage:
@@ -26,7 +28,7 @@ Options:
2628
2729
-t <type> --type=<type> Type of project to generate, possible options:
2830
javascript (default)
29-
standalone-js
31+
standaloneJS
3032
3133
The following options are only usefull for testing the openapi-glue plugin:
3234
-c --checksumOnly Don't generate the project on disk but
@@ -49,7 +51,6 @@ const argvOptions = {
4951
},
5052

5153
default: {
52-
projectName: "generatedProject",
5354
baseDir: process.cwd(),
5455
checksumOnly: false,
5556
localPlugin: false,
@@ -64,11 +65,17 @@ if (!argv.specification) {
6465
usage();
6566
}
6667

68+
if (!validTypes.has(argv.type)) {
69+
console.log(`Unknown type: ${argv.type}`);
70+
usage();
71+
}
72+
73+
const projectName = argv.projectName || `generated-${argv.type}-project`;
6774
const specPath = resolve(process.cwd(), argv.specification);
6875
const generator = new Generator(argv.checksumOnly, argv.localPlugin);
6976
const handler = (str) =>
7077
/* c8 ignore next */
71-
argv.checksumOnly ? JSON.stringify(str, null, 2) : str;
78+
argv.checksumOnly ? JSON.stringify(str, null, "\t") : str;
7279
if (generator.localPlugin) {
7380
console.log(`Using local plugin at: ${generator.localPlugin}
7481
`);
@@ -78,11 +85,7 @@ try {
7885
await generator.parse(specPath);
7986
console.log(
8087
handler(
81-
await generator.generateProject(
82-
argv.baseDir,
83-
argv.projectName,
84-
argv.type,
85-
),
88+
await generator.generateProject(argv.baseDir, projectName, argv.type),
8689
),
8790
);
8891
} catch (e) {

docs/securityHandlers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ will return errors originating from the securityHandlers as well in `err.errors`
4444

4545
You can use `err.errors` also to trigger other behaviour in a registered error handler.
4646

47-
For a more elaborate example see the [examples/generatedProject](/examples/generatedProject) folder.
47+
For a more elaborate example see the [examples/generated-javascript-project](/examples/generated-javascript-project) folder.

examples/generatedProject/README.md renamed to examples/generated-javascript-project/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# generatedProject
1+
# generated-javascript-project
22

33
This directory contains a fastify plugin that was autogenerated using
44
[fastify-openapi-glue](https://github.com/seriousme/fastify-openapi-glue) and

examples/generatedProject/index.js renamed to examples/generated-javascript-project/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Fastify plugin autogenerated by fastify-openapi-glue
2-
import openapiGlue from "fastify-openapi-glue";
2+
import openapiGlue from "../../lib/templates/index.js";
33
import { Service } from "./service.js";
44
import { Security } from "./security.js";
55
const localFile = (fileName) => new URL(fileName, import.meta.url).pathname;

0 commit comments

Comments
 (0)