Allows execution of the apiblueprint-springmvc generator, to generate SpringMVC source files from an apiblueprint specification.
This plugin requires Grunt. It also assumes that you have an understanding of API Blueprint, so that you can write apib files for this plugin to process!
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-apiblueprint-springmvc --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-apiblueprint-springmvc');
In your project's Gruntfile, add a section named apiblueprint_springmvc
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
apiblueprint_springmvc: {
options: {
// Your options options go here.
},
files: {
'destinationPath': ['src/*.apib']
}
}
});
Default: process.cwd()
If your apib files use the aglio include directive, files will be included relative to this path.
Default: true
If true, tabs will be replaced with 4 spaces prior to processing, and windows newlines converted to linux (required, since APIB doesn't support tabs or windows).
Default: utf8
The encoding of input .apib files.
Default: api
The java package that will be inserted to the top of each java file.
Default: []
An array of strings, which will be inserted at the top of the java Controllers and Service Interface. Each string should be a full java class name, or other valid value for an import statement.
Example: ['api.rest.model.response.','api.rest.model.request.']
Default: []
An array of model names that should not have java files created for them, in the models directory. This is useful if you do not want to generate files for some types that are defined in the apib (foe example, they are defined already in the java project elsewhere)
Default: false
If true, instead of using class inheritance, models will be flattened to contain all parent model fields.
Default: []
An array of objects that you can use to add extra annotations, or parameters to a controller method.
Each array entry contains a matching rule (exact match or regular expression) to determine which controller methods should have the modifier applied. The method name against which the rule matches is in the format ControllerName.methodName
The modifier itself can apply an annotation to the method itself, or add (optionally) annotated parameters to the method signature (either at the beginning, or end, of the parameter list.)
The modifier definition is as follows:
{
pattern: /MyController\..+/,
methodAnnotations: ['@AnnoOne', '@AnnoTwo("someArg")'],
prependedParameters: [ { type: 'HttpServletRequest', name: 'prefixedParam' } ],
appendedParameters: [ { annotation: '@NotNull', type: 'HttpServletResponse', name: 'suffixedParam' } ]
}
This would result in the following output (assuming it matched a method with a single parameter, original)
@AnnoOne
@AnnoTwo("someArg")
@RequestMapping("/someMethod{original}")
public ReturnObject someMethod(HttpServletRequest prefixedParam, @PathVariable String original, @NotNull HttpServletResponse suffixedParam) {
return delegateService.someMethod(prefixedParam, original, suffixedParam);
}
pattern is either a string (for exact match) or a regular expression.
methodAnnotations contains a list of strings; each which is inserted verbatim above the method definiton.
prependedParameters contains a list of objects. Mandatory fields are type and name ; however annotation is optional.
appendedParameters contains a list of objects. Mandatory fields are type and name ; however annotation is optional.
In this example, the most commonly used options are specified. This will
grunt.initConfig({
apiblueprint_springmvc: {
options: {
includePath: 'src',
packagePrefix: 'my.package.rest',
extraImports: ['my.package.rest.model.response.*','my.package.rest.model.request.*'],
skipModelNames: ['ReadSingleResponse', 'ReadListResponse', 'OperationResponse', 'FilterableRequest']
},
files: {
'destinationPath': ['src/*.apib']
},
},
})
Some things I would like to add
Pull requests are welcome!
(Nothing yet)
Copyright (c) 2015 Lewis Weaver. Licensed under the MIT license.