-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Adding OpenAPI v3.0 Support #57
base: master
Are you sure you want to change the base?
[WIP] Adding OpenAPI v3.0 Support #57
Conversation
lib/generators/index.js
Outdated
@@ -5,9 +5,15 @@ const Randexp = require('randexp').randexp; | |||
|
|||
const mock = (schema, useExample) => { | |||
let mock; | |||
|
|||
// Parameters and responses live inside the schema keyword now | |||
if (schema.schema) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty proud of this one. 😅
Actually, im going to have to leave this right here I'm affraid. My approach to mocking for now is going to be trying to help Prism upgrade to v3.0. If you'd like to continue this, there is a great article on v3.0 differences. https://dev.to/mikeralphson/comparing-openapiswagger-20-and-300-rc1 A lot of these test failures are down to your tests asserting very v2.0 specific things, so changing this is mostly changing the tests. The collectionFormat stuff is tricky too, as that changed a lot. No more explicit delimeters, and there's a whole matrix of options to support, and objects should be supported instead of just arrays. That's about where I left this work on Friday. https://swagger.io/specification/#style-values Best of luck to ya! |
const Format = require('./format'); | ||
const Randexp = require('randexp').randexp; | ||
|
||
const mock = (node, useExample) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
if (schema) { | ||
let type = schema.type || findType(schema); | ||
let example = schema.examples || schema.example || schema.default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added default as an example, which the spec says can be used if no examples exist.
This schema.example || ...
might give funny results if example is 0 or false.
@@ -34,7 +34,7 @@ | |||
"chance": "^1.0.3", | |||
"moment": "^2.13.0", | |||
"randexp": "^0.4.2", | |||
"swagger-parser": "^3.4.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bit gets you a version of Swagger Parser which understands OpenAPI v3.0.
@@ -13,7 +13,7 @@ describe('Parameter Mock generator', () => { | |||
path: '/store/order/{orderId}', | |||
operation: 'get' | |||
}, (err, mock) => { | |||
Assert.ok(!err, 'No error'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing as Swagger Parser supports OpenAPI v3.0 it should be pretty much free to upgrade.
It's taking a bit of work but I'll get there.