forked from loafle/openapi-generator-original
Merge pull request #2170 from wing328/feature_all_models_postprocess
Add postProcessAllModels to default generator
This commit is contained in:
commit
eecce8d2d0
@ -119,6 +119,8 @@ public interface CodegenConfig {
|
|||||||
|
|
||||||
void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations);
|
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> postProcessModels(Map<String, Object> objs);
|
||||||
|
|
||||||
Map<String, Object> postProcessOperations(Map<String, Object> objs);
|
Map<String, Object> postProcessOperations(Map<String, Object> objs);
|
||||||
|
@ -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
|
// override with any special post-processing
|
||||||
@SuppressWarnings("static-method")
|
@SuppressWarnings("static-method")
|
||||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||||
return objs;
|
return objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// override with any special post-processing
|
// override with any special post-processing
|
||||||
@SuppressWarnings("static-method")
|
@SuppressWarnings("static-method")
|
||||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||||
|
@ -183,6 +183,10 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
sortedModelKeys = updatedKeys;
|
sortedModelKeys = updatedKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// store all processed models
|
||||||
|
Map<String,Object> allProcessedModels = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
// process models only
|
||||||
for (String name : sortedModelKeys) {
|
for (String name : sortedModelKeys) {
|
||||||
try {
|
try {
|
||||||
//don't generate models that have an import mapping
|
//don't generate models that have an import mapping
|
||||||
@ -195,6 +199,26 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
modelMap.put(name, model);
|
modelMap.put(name, model);
|
||||||
Map<String, Object> models = processModels(config, modelMap, definitions);
|
Map<String, Object> models = processModels(config, modelMap, definitions);
|
||||||
models.putAll(config.additionalProperties());
|
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));
|
allModels.add(((List<Object>) models.get("models")).get(0));
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ module Petstore
|
|||||||
# http body (model)
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
auth_names = ['api_key']
|
auth_names = ['api_key', 'petstore_auth']
|
||||||
data, status_code, headers = @api_client.call_api(:GET, path,
|
data, status_code, headers = @api_client.call_api(:GET, path,
|
||||||
:header_params => header_params,
|
:header_params => header_params,
|
||||||
:query_params => query_params,
|
:query_params => query_params,
|
||||||
@ -550,7 +550,7 @@ module Petstore
|
|||||||
# http body (model)
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
auth_names = ['api_key']
|
auth_names = ['api_key', 'petstore_auth']
|
||||||
data, status_code, headers = @api_client.call_api(:GET, path,
|
data, status_code, headers = @api_client.call_api(:GET, path,
|
||||||
:header_params => header_params,
|
:header_params => header_params,
|
||||||
:query_params => query_params,
|
:query_params => query_params,
|
||||||
|
@ -122,7 +122,7 @@ module Petstore
|
|||||||
# http body (model)
|
# http body (model)
|
||||||
post_body = @api_client.object_to_http_body(opts[:'body'])
|
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,
|
data, status_code, headers = @api_client.call_api(:POST, path,
|
||||||
:header_params => header_params,
|
:header_params => header_params,
|
||||||
:query_params => query_params,
|
:query_params => query_params,
|
||||||
@ -182,7 +182,7 @@ module Petstore
|
|||||||
# http body (model)
|
# http body (model)
|
||||||
post_body = nil
|
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,
|
data, status_code, headers = @api_client.call_api(:GET, path,
|
||||||
:header_params => header_params,
|
:header_params => header_params,
|
||||||
:query_params => query_params,
|
:query_params => query_params,
|
||||||
|
@ -157,6 +157,13 @@ module Petstore
|
|||||||
# Returns Auth Settings hash for api client.
|
# Returns Auth Settings hash for api client.
|
||||||
def auth_settings
|
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' =>
|
'api_key' =>
|
||||||
{
|
{
|
||||||
type: 'api_key',
|
type: 'api_key',
|
||||||
@ -164,6 +171,27 @@ module Petstore
|
|||||||
key: 'api_key',
|
key: 'api_key',
|
||||||
value: api_key_with_prefix('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' =>
|
'petstore_auth' =>
|
||||||
{
|
{
|
||||||
type: 'oauth2',
|
type: 'oauth2',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user