Some swagger 1.2 migration cleanup.
- Added array items definition. - Ignored body when specified via arg.http.source.
This commit is contained in:
parent
2f8506c81b
commit
67bb10b6a4
|
@ -73,6 +73,7 @@ function Swagger(remotes, options) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the class definition matching this route.
|
||||||
classDef = classes.filter(function (item) {
|
classDef = classes.filter(function (item) {
|
||||||
return item.name === split[0];
|
return item.name === split[0];
|
||||||
})[0];
|
})[0];
|
||||||
|
@ -81,12 +82,14 @@ function Swagger(remotes, options) {
|
||||||
route.accepts = (route.accepts || []).concat(classDef.sharedCtor.accepts);
|
route.accepts = (route.accepts || []).concat(classDef.sharedCtor.accepts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filter out parameters that are generated from the incoming request or body,
|
||||||
|
// or generated by functions that use those resources.
|
||||||
route.accepts = (route.accepts || []).filter(function(arg){
|
route.accepts = (route.accepts || []).filter(function(arg){
|
||||||
if (!arg.http) return true;
|
if (!arg.http) return true;
|
||||||
// Don't show derived arguments.
|
// Don't show derived arguments.
|
||||||
if (typeof arg.http === 'function') return false;
|
if (typeof arg.http === 'function') return false;
|
||||||
// Don't show arguments set to the incoming http request.
|
// Don't show arguments set to the incoming http request or body.
|
||||||
if (arg.http.source === 'req') return false;
|
if (arg.http.source === 'req' || arg.http.source === 'body') return false;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -200,22 +203,26 @@ function generateModelDefinition(aClass) {
|
||||||
'min': 'minimum',
|
'min': 'minimum',
|
||||||
'max': 'maximum'
|
'max': 'maximum'
|
||||||
};
|
};
|
||||||
|
|
||||||
// Iterate through each property in the model definition.
|
// Iterate through each property in the model definition.
|
||||||
// Types are defined as constructors (e.g. String, Date, etc.)
|
// Types are defined as constructors (e.g. String, Date, etc.)
|
||||||
// so we convert them to strings.
|
// so we convert them to strings.
|
||||||
Object.keys(def.properties).forEach(function(key) {
|
Object.keys(def.properties).forEach(function(key) {
|
||||||
var prop = def.properties[key];
|
var prop = def.properties[key];
|
||||||
// Required props sit in a different array.
|
|
||||||
|
// Eke a type out of the constructors we were passed.
|
||||||
|
prop.type = getPropType(prop.type);
|
||||||
|
if (prop.type === 'array') {
|
||||||
|
prop.items = {
|
||||||
|
type: getPropType(prop.type[0])
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Required props sit in a per-model array.
|
||||||
if (prop.required || prop.id) {
|
if (prop.required || prop.id) {
|
||||||
required.push(key);
|
required.push(key);
|
||||||
}
|
}
|
||||||
// Eke a type out of the constructors we were passed.
|
|
||||||
if (typeof prop.type === "function") {
|
|
||||||
prop.type = prop.type.name.toLowerCase();
|
|
||||||
} else if(Array.isArray(prop.type)) {
|
|
||||||
prop.type = 'array';
|
|
||||||
// prop.items.type = prop.type[0] ? prop.type[0].name.toLowerCase(): 'any';
|
|
||||||
}
|
|
||||||
// Change mismatched keys.
|
// Change mismatched keys.
|
||||||
Object.keys(keyTranslations).forEach(function(LDLKey){
|
Object.keys(keyTranslations).forEach(function(LDLKey){
|
||||||
var val = prop[LDLKey];
|
var val = prop[LDLKey];
|
||||||
|
@ -239,6 +246,21 @@ function generateModelDefinition(aClass) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a propType (which may be a function, string, or array),
|
||||||
|
* get a string type.
|
||||||
|
* @param {*} propType Prop type description.
|
||||||
|
* @return {String} Prop type string.
|
||||||
|
*/
|
||||||
|
function getPropType(propType) {
|
||||||
|
if (typeof propType === "function") {
|
||||||
|
propType = propType.name.toLowerCase();
|
||||||
|
} else if(Array.isArray(propType)) {
|
||||||
|
propType = 'array';
|
||||||
|
}
|
||||||
|
return propType;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts from an sl-remoting-formatted "Route" description to a
|
* Converts from an sl-remoting-formatted "Route" description to a
|
||||||
* Swagger-formatted "API" description.
|
* Swagger-formatted "API" description.
|
||||||
|
@ -247,8 +269,6 @@ function generateModelDefinition(aClass) {
|
||||||
function routeToAPI(route) {
|
function routeToAPI(route) {
|
||||||
var returnDesc = route.returns && route.returns[0];
|
var returnDesc = route.returns && route.returns[0];
|
||||||
|
|
||||||
console.log(route);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path: convertPathFragments(route.path),
|
path: convertPathFragments(route.path),
|
||||||
operations: [{
|
operations: [{
|
||||||
|
|
Loading…
Reference in New Issue