Mermade / widdershins

OpenAPI / Swagger, AsyncAPI & Semoasa definitions to (re)Slate compatible markdown
https://mermade.github.io/reslate
MIT License
1.5k stars 322 forks source link

Default Options are different when running through node vs cli #379

Closed Kanna727 closed 4 years ago

Kanna727 commented 4 years ago

Describe the bug When running via CLI, if some default options are set, why aren't same defaults set when running via Node? Why should we worry about writing defaults manually? This will also be a problem when we are migrating from CLI to Node and poduces undesired outputs.

Following is my config file while running via CLI:

{
    "language_tabs": [],
    "verbose": false,
    "omitBody": true,
    "omitHeader": true,
    "codeSamples": false
}

And following is the options variable when running via node:

const options = {
    language_tabs: [],
    verbose: false,
    omitBody: true,
    omitHeader: true,
    codeSamples: false
}

I'm parsing the same OpenAPI 3.0 JSON file as input in both the cases. So I'm expecting the same output from both the methods. Instead the requestBody example are varying as follows:

requestBody example when running via CLI:

{
  "username": "user@example.com",
  "password": "pa$$word"
}

requestBody example when running via node:

{
  "type": "object",
  "required": [
    "username",
    "password"
  ],
  "properties": {
    "username": {
      "type": "string",
      "format": "email"
    },
    "password": {
      "type": "string",
      "format": "password"
    }
  }
}

I've checked your code flow and found out the final options variable are actually different for both the methods at following line: https://github.com/Mermade/widdershins/blob/07831f6d7a97b47cf3968a094458e43b9c8e6701/lib/index.js#L9

When running via CLI:

{
    codeSamples:false
    httpsnippet:false 
    maxDepth:10
    omitBody:true
    omitHeader:true 
    sample:true
    verbose:false
}

When running via Node:

{
    codeSamples:false
    omitBody:true
    omitHeader:true
    verbose:true
}

To Reproduce Steps to reproduce the behavior:

  1. My Config file for CLI
  2. My input file
  3. Command-line: widdershins ./docs/oas3sample.json -o ./docs/api-docs-cli.md -e ./config/conf.json
  4. CLI output file
  5. My Node file to generate md
  6. Node output file

Expected behavior Defaults should be same across CLI & Node

Kanna727 commented 4 years ago

I've gone through your code. Surprisingly in following files on git, there is defaults.sample = true line:

https://github.com/Mermade/widdershins/blob/a173d54046ca608aac5403a2dd9a94f389fd5996/lib/openapi3.js#L618 https://github.com/Mermade/widdershins/blob/a173d54046ca608aac5403a2dd9a94f389fd5996/lib/asyncapi1.js#L140 https://github.com/Mermade/widdershins/blob/a173d54046ca608aac5403a2dd9a94f389fd5996/lib/semoasa.js#L29

But I couldn't find any of these lines when installed via npm. Please find the below files which are directly from this package's folder in node_modules:

openapi3.js asyncapi1.js semoasa.js

I've installed latest version 4.0.1 via npm: npm install widdershins --save-dev

Please confirm if I've installed your package wrong

Kanna727 commented 4 years ago

Looks like PR #329 with following commit https://github.com/Mermade/widdershins/commit/588c1d3ae42da26980ed1274e3a33f8b3447fac5 has already resolved this but the fix has not been released yet. It has already been more than 4 months since the fix. Kindly trigger a release, so that people like us won't have to spend soo much time on resolved issues like this.

MikeRalphson commented 4 years ago

Please watch:releases for the next release or install from GitHub if you need unreleased fixes/features.