-
Notifications
You must be signed in to change notification settings - Fork 370
Finish first pass at enhanced swagger-router mock mode #30
Comments
+1 |
I have a few ideas about this that I would like to discuss. One thing we need to do account for a response's
I'm looking for your thoughts on this if you have the time. |
I like taking into account the In addition, I'm facing 2 custom use cases that the swagger doesn't support so this is my 2 cents:
function mockNotEqualsTo (suggestedValue, object, notEqualsTo) {
// if string
return suggestedValue + ((object[notEqualsTo] === suggestedValue) ? 'suffix' : '');
...
} This function getting the suggested mock value, the mocked object, the value of the constraint ( properties:
name:
type: string
x-notEqualsTo: password
password:
type: string So maybe setting the custom "handlers" after the default mock is ready? Anyway, this function can be passed inside the handlers object with the key
properties:
id:
type: string
format objectId or uuid And the function will be: function mockObjectId (suggestedValue) {
return suggestedValue.length === 24 ? suggestedValue : 'A23Fvde5h0rfDn71Hjnv9w5s';
} The issue here is naming the key in the handlers object so maybe combination of If passing these handlers to the router so I guess it will look like this: swaggerMiddleware.swaggerRouter({
useStubs: true,
mockHandlers: {
notEqualsTo: function mockNotEqualsTo (suggestedValue, object, notEqualsTo) {
// if string
return suggestedValue + ((object[notEqualsTo] === suggestedValue) ? 'suffix' : '');
...
},
string_objectId: function mockObjectId (suggestedValue) {
return suggestedValue.length === 24 ? suggestedValue : 'A23Fvde5h0rfDn71Hjnv9w5s';
}
}
}) I'm working only with json so no idea what to do with other formats :) I hope I understood what are you asking about :) |
That's a cool idea. You'd have a registry of mock handlers that can be used to create the values with formats unknown. Seems reasonable. But this doesn't help with the non-JSON formats. Maybe this is a good enough step in the right direction. I'll give it some thought. |
I am going to close this and create a better explanation of what is needed. |
swagger-router mock mode needs to implement support for the following:
The text was updated successfully, but these errors were encountered: