zallek / swagger-diff

Compute the diff between two swagger API specifications.
https://zallek.github.io/swagger-diff/
58 stars 30 forks source link

Regarding a Slight CHange in Output #10

Closed Gurleen-Singh closed 8 years ago

Gurleen-Singh commented 8 years ago

Hiii.. We want to change the Output from rule-centric to path-centric. It will simplify the output and make it easy to understand. Any help in doing this is much appreciated.

TIA,

zallek commented 8 years ago

Hi,

Option 1: The easy dirty way

Groupby the ouput messages by message.exec(/^(.*)\s\-\s.*$/)[0] as message output is always <path> - <message>

Option 2: The better way

Rules should returns an array an object containing message, path and some more metadata.

function rule(diff: RawDiff) : String

to

function rule(diff: RawDiff) : Object{message: String, path: String, ...}

Rules are only used there, so it shouldn't be hard to change (most of rules are tested) https://github.com/zallek/swagger-diff/blob/master/src/workflow/applyRules.js#L29 https://github.com/zallek/swagger-diff/blob/master/src/workflow/applyRules.js#L46

So at those lines, turn object shape from

Diff {
  ruleId: String,
  message: String, // Would be better to keep the message property as-is in order to not introduce any interface breaking
  path: String,
  shortMessage: String,  // Any idea fot a better property name ? :p 
}

Example:

{
  ruleId: 'add-required-param',
  message: '/users/{username}/ (get) - Required param username added',
  path: '/users/{username}/ (get)',
  shortMessage: 'Required param username added',
}

Maybe you could improve something about the path too. Your inputs would be appreciated. Thx :)

zallek commented 8 years ago

done