Merge pull request #2170 from wing328/feature_all_models_postprocess

Add postProcessAllModels to default generator
This commit is contained in:
wing328 2016-02-18 16:53:43 +08:00
commit eecce8d2d0
6 changed files with 65 additions and 4 deletions

View File

@ -119,6 +119,8 @@ public interface CodegenConfig {
void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations);
Map<String, Object> postProcessAllModels(Map<String, Object> objs);
Map<String, Object> postProcessModels(Map<String, Object> objs);
Map<String, Object> postProcessOperations(Map<String, Object> objs);

View File

@ -109,12 +109,19 @@ public class DefaultCodegen {
}
}
// override with any special post-processing for all models
@SuppressWarnings("static-method")
public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
return objs;
}
// override with any special post-processing
@SuppressWarnings("static-method")
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
return objs;
}
// override with any special post-processing
@SuppressWarnings("static-method")
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {

View File

@ -183,6 +183,10 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
sortedModelKeys = updatedKeys;
}
// store all processed models
Map<String,Object> allProcessedModels = new HashMap<String, Object>();
// process models only
for (String name : sortedModelKeys) {
try {
//don't generate models that have an import mapping
@ -195,6 +199,26 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
modelMap.put(name, model);
Map<String, Object> models = processModels(config, modelMap, definitions);
models.putAll(config.additionalProperties());
allProcessedModels.put(name, models);
} catch (Exception e) {
throw new RuntimeException("Could not process model '" + name + "'", e);
}
}
// post process all processed models
allProcessedModels = config.postProcessAllModels(allProcessedModels);
// generate files based on processed models
for (String name: allProcessedModels.keySet()) {
Map<String, Object> models = (Map<String, Object>)allProcessedModels.get(name);
try {
//don't generate models that have an import mapping
if(config.importMapping().containsKey(name)) {
continue;
}
allModels.add(((List<Object>) models.get("models")).get(0));

View File

@ -298,7 +298,7 @@ module Petstore
# http body (model)
post_body = nil
auth_names = ['api_key']
auth_names = ['api_key', 'petstore_auth']
data, status_code, headers = @api_client.call_api(:GET, path,
:header_params => header_params,
:query_params => query_params,
@ -550,7 +550,7 @@ module Petstore
# http body (model)
post_body = nil
auth_names = ['api_key']
auth_names = ['api_key', 'petstore_auth']
data, status_code, headers = @api_client.call_api(:GET, path,
:header_params => header_params,
:query_params => query_params,

View File

@ -122,7 +122,7 @@ module Petstore
# http body (model)
post_body = @api_client.object_to_http_body(opts[:'body'])
auth_names = []
auth_names = ['test_api_client_id', 'test_api_client_secret']
data, status_code, headers = @api_client.call_api(:POST, path,
:header_params => header_params,
:query_params => query_params,
@ -182,7 +182,7 @@ module Petstore
# http body (model)
post_body = nil
auth_names = []
auth_names = ['test_api_key_header', 'test_api_key_query']
data, status_code, headers = @api_client.call_api(:GET, path,
:header_params => header_params,
:query_params => query_params,

View File

@ -157,6 +157,13 @@ module Petstore
# Returns Auth Settings hash for api client.
def auth_settings
{
'test_api_key_header' =>
{
type: 'api_key',
in: 'header',
key: 'test_api_key_header',
value: api_key_with_prefix('test_api_key_header')
},
'api_key' =>
{
type: 'api_key',
@ -164,6 +171,27 @@ module Petstore
key: 'api_key',
value: api_key_with_prefix('api_key')
},
'test_api_client_secret' =>
{
type: 'api_key',
in: 'header',
key: 'x-test_api_client_secret',
value: api_key_with_prefix('x-test_api_client_secret')
},
'test_api_client_id' =>
{
type: 'api_key',
in: 'header',
key: 'x-test_api_client_id',
value: api_key_with_prefix('x-test_api_client_id')
},
'test_api_key_query' =>
{
type: 'api_key',
in: 'query',
key: 'test_api_key_query',
value: api_key_with_prefix('test_api_key_query')
},
'petstore_auth' =>
{
type: 'oauth2',