Skip to content

add multifile arg#46

Open
OzBob wants to merge 1 commit intoverizonconnect:mainfrom
OzBob:ozbob/filePerEndPoint
Open

add multifile arg#46
OzBob wants to merge 1 commit intoverizonconnect:mainfrom
OzBob:ozbob/filePerEndPoint

Conversation

@OzBob
Copy link
Copy Markdown

@OzBob OzBob commented Jul 28, 2022

Support multiple output files

One file per key in the spec definitions.

Discovered feature: works fine on PetStor, but the SwaggerParser library does not show results when the swagger file is large (>10000 lines)

support multiple output files

One file per key in the spec definitions.

The SwaggerParser library does not show results when the swagger file is large (>10000 lines)
Copy link
Copy Markdown
Contributor

@martinmcwhorter martinmcwhorter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a some work

Comment thread demo/swagger.json
},
"definitions": {
"AddressModel": {
"required": ["firstName", "lastName", "address", "city", "postalCode", "emailAddress", "country"],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are losing the validation rules here.

Comment thread .vscode/launch.json
@@ -0,0 +1,17 @@
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exclude this file in the .gitignore

Comment thread demo/README.md

Run the following from the `/demo` directory:

open https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't wan't manual steps here.

The petstore swagger is lacking in validation rules, making it inadequate for the demo.

Comment thread swaggerPet3.yaml
@@ -0,0 +1,819 @@
openapi: 3.0.2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is here, accidental commit?

Comment thread src/generator-cli.ts
description: 'Generated file name',
type: 'string'
})
.option('multiplefiles', {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be hyphenated multiple-files

Comment thread src/generator-cli.ts
.alias('help', 'h').argv;

const spec = await loadSpec(argv['input-spec']);
const args = new Args(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A factory literal is probably better than a class here.

const args = { inputSpec: argv['input-spec'], output: argv.output, fileName: argv['fileName'], multipleFiles: argv['multiple-files'] }; 

If you want to use a class, keep it simple:

export class Args {
  constructor(
    public inputSpec: string, 
    public output: string, 
    public fileName: string, 
    public multipleFiles: string
    ) {}
}

Actually, we shouldn't need to do any of this. Yargs returns a static type for us https://github.com/yargs/yargs/blob/main/docs/typescript.md

Comment thread src/generator-cli.ts
);
//const inputfile=args.inputspec;
const inputfile=argv['input-spec'];
console.log('start load spec(' + inputfile + ') ...');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too busy on the console.logs

Comment thread src/generator-cli.ts
}

await saveFile(file, fileName);
console.log((success)?'Completed.':'Finished with errors.');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would never get here on an error. Did you mean to do a try/catch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants