Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Commit

Permalink
catch exception when generating models #77
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuales committed Jun 22, 2017
1 parent f98cc71 commit a5cb55c
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions src/scripts/swagger-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,19 @@ angular
* generates a sample JSON string (request body or response body)
*/
this.generateSampleJson = function(swagger, schema) {
var json,
obj = getSampleObj(swagger, schema);
try {
var json,
obj = getSampleObj(swagger, schema);

if (obj) {
json = angular.toJson(obj, true);
if (obj) {
json = angular.toJson(obj, true);
}
return json;

} catch (ex) {
console.error('failed to generate sample json', schema, ex);
return 'failed to generate sample json';
}
return json;
};

/**
Expand Down Expand Up @@ -196,27 +202,33 @@ angular
* generate a model and its submodels from schema
*/
this.generateModel = function(swagger, schema, operationId) {
schema = resolveAllOf(swagger, schema);
var model = [],
subModelIds = {},
subModels = {};
try {
schema = resolveAllOf(swagger, schema);
var model = [],
subModelIds = {},
subModels = {};

if (schema.properties) {
// if inline model
subModels[getInlineModelName()] = schema;
subModels = angular.merge(subModels, findAllModels(swagger, schema, subModelIds));
} else {
subModels = findAllModels(swagger, schema, subModelIds);
}
if (schema.properties) {
// if inline model
subModels[getInlineModelName()] = schema;
subModels = angular.merge(subModels, findAllModels(swagger, schema, subModelIds));
} else {
subModels = findAllModels(swagger, schema, subModelIds);
}

if (!schema.$ref && !schema.properties) {
// if array or map/dictionary or simple type
model.push('<strong>', getModelProperty(schema, subModels, subModelIds, operationId), '</strong><br><br>');
}
angular.forEach(subModels, function(schema, modelName) {
model.push(getModelMaybeFromCache(swagger, schema, modelName, subModels, subModelIds, operationId));
});
return model.join('');

if (!schema.$ref && !schema.properties) {
// if array or map/dictionary or simple type
model.push('<strong>', getModelProperty(schema, subModels, subModelIds, operationId), '</strong><br><br>');
} catch (ex) {
console.error('failed to generate model', schema, ex);
return 'failed to generate model';
}
angular.forEach(subModels, function(schema, modelName) {
model.push(getModelMaybeFromCache(swagger, schema, modelName, subModels, subModelIds, operationId));
});
return model.join('');
};

/**
Expand Down

0 comments on commit a5cb55c

Please sign in to comment.