forked from swagger-api/swagger-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move common functionality to new model base class
Fixes "additional comment swagger-api#2" in swagger-api#2044. Saves memory by not repeating the `toJson` method in every model class. The new `ApiModel` base class may also be useful for other purposes in the future.
- Loading branch information
Showing
9 changed files
with
532 additions
and
473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
modules/swagger-codegen/src/main/resources/Javascript/ApiModel.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(function(root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define([], factory); | ||
} else if (typeof module === 'object' && module.exports) { | ||
// CommonJS-like environments that support module.exports, like Node. | ||
module.exports = factory(); | ||
} else { | ||
// Browser globals (root is window) | ||
if (!root.{{moduleName}}) { | ||
root.{{moduleName}} = {}; | ||
} | ||
root.{{moduleName}}.ApiModel = factory(); | ||
} | ||
}(this, function() { | ||
'use strict'; | ||
/** | ||
Base class for all generated model classes, | ||
containing common functionality. | ||
**/ | ||
var ApiModel = function(){} | ||
ApiModel.prototype.toJson = function() { | ||
return JSON.stringify(this); | ||
} | ||
|
||
if (module) { | ||
module.ApiModel = ApiModel; | ||
} | ||
|
||
return ApiModel; | ||
|
||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(function(root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define([], factory); | ||
} else if (typeof module === 'object' && module.exports) { | ||
// CommonJS-like environments that support module.exports, like Node. | ||
module.exports = factory(); | ||
} else { | ||
// Browser globals (root is window) | ||
if (!root.SwaggerPetstore) { | ||
root.SwaggerPetstore = {}; | ||
} | ||
root.SwaggerPetstore.ApiModel = factory(); | ||
} | ||
}(this, function() { | ||
'use strict'; | ||
|
||
var ApiModel = function(){} | ||
ApiModel.prototype.toJson = function() { | ||
return JSON.stringify(this); | ||
} | ||
|
||
if (module) { | ||
module.ApiModel = ApiModel; | ||
} | ||
|
||
return ApiModel; | ||
|
||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.