This repository is no longer maintained. The schema has been diverged from Swagger 2.0 standard as a result of requirement change in the internal project which used this library.
Generate Javascript model class code from swagger definition and convert between JSON and model instance
npm install swagger-model --save-dev
(for class file generation)
bower install swagger-model
(for runtime)
Generate Javascript class files from swagger definition
- swaggerDefinition: JSON of Swagger definition
- outPath: Output path string OR option: Detailed options
option: {
outPath: 'Output path',
filters: [
'Array of regular expression strings, generate if class name matches the regexp. eg: "^includeThisClass$"'
'Skip class if class name matches expression begins with `!`. eg: "!^skipThisClass$"'
]
}
Register a swagger model class so when converting from JSON or to JSON the library knows where to find the class
- className: String of class name
- definition: Constractor function of a model class
Check if a model class has been registered
Build model instance from JSON object
- object: A JSON object
- className: The model class name you are mapping to
- options:
{
// Specify property name of the objectID
// Json with same objectID will share same object in model instance
objectID: 'ID'
}
Build JSON object from model instance
- object: Model object
Determine if object is a model instance
Make deep clone of a model instance
npm test