|
35 | 35 | import static org.openapitools.codegen.utils.StringUtils.camelize; |
36 | 36 |
|
37 | 37 | public class GoServerCodegen extends AbstractGoCodegen { |
38 | | - |
| 38 | + public static final String STRICT_RESPONSE_DECODING = "strictResponseDecoding"; |
| 39 | + protected boolean strictResponseDecoding = true; |
39 | 40 | /** |
40 | 41 | * Name of additional property for switching routers |
41 | 42 | */ |
42 | 43 | private static final String ROUTER_SWITCH = "router"; |
| 44 | + |
| 45 | + |
43 | 46 |
|
44 | 47 | /** |
45 | 48 | * Description of additional property for switching routers |
46 | 49 | */ |
47 | 50 | private static final String ROUTER_SWITCH_DESC = "Specify the router which should be used."; |
48 | | - |
| 51 | + |
49 | 52 | /** |
50 | 53 | * List of available routers |
51 | 54 | */ |
52 | 55 | private static final String[] ROUTERS = {"mux", "chi"}; |
53 | | - |
| 56 | + |
54 | 57 | private final Logger LOGGER = LoggerFactory.getLogger(GoServerCodegen.class); |
55 | | - |
| 58 | + |
56 | 59 | @Setter protected String packageVersion = "1.0.0"; |
57 | 60 | @Setter protected int serverPort = 8080; |
58 | 61 | protected String projectName = "openapi-server"; |
@@ -92,6 +95,7 @@ public GoServerCodegen() { |
92 | 95 | // set the output folder here |
93 | 96 | outputFolder = "generated-code/go"; |
94 | 97 |
|
| 98 | + cliOptions.add(new CliOption(STRICT_RESPONSE_DECODING, "If true, server JSON decoders call DisallowUnknownFields").defaultValue("true")); |
95 | 99 | cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC) |
96 | 100 | .defaultValue(sourceFolder)); |
97 | 101 |
|
@@ -132,6 +136,9 @@ public GoServerCodegen() { |
132 | 136 | optOutputAsLibrary.setType("bool"); |
133 | 137 | optOutputAsLibrary.defaultValue(outputAsLibrary.toString()); |
134 | 138 | cliOptions.add(optOutputAsLibrary); |
| 139 | + |
| 140 | + cliOptions.add(new CliOption(STRICT_RESPONSE_DECODING, "If true, responses are decoded with DisallowUnknownFields (strict); " + "if false, unknown JSON fields are ignored (permissive)").defaultValue("true")); |
| 141 | + |
135 | 142 | /* |
136 | 143 | * Models. You can write model files using the modelTemplateFiles map. |
137 | 144 | * if you want to create one template for file, you can do so here. |
@@ -192,6 +199,9 @@ public void processOpts() { |
192 | 199 | * Additional Properties. These values can be passed to the templates and |
193 | 200 | * are available in models, apis, and supporting files |
194 | 201 | */ |
| 202 | + if (additionalProperties.containsKey(STRICT_RESPONSE_DECODING)){ |
| 203 | + strictResponseDecoding = Boolean.parseBoolean(additionalProperties.get(STRICT_RESPONSE_DECODING).toString()); |
| 204 | + } |
195 | 205 | if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) { |
196 | 206 | setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME)); |
197 | 207 | } else { |
@@ -268,6 +278,7 @@ public void processOpts() { |
268 | 278 | routers.put(router, router.equals(propRouter)); |
269 | 279 | } |
270 | 280 | additionalProperties.put("routers", routers); |
| 281 | + additionalProperties.put("strictResponseDecoding", strictResponseDecoding); |
271 | 282 |
|
272 | 283 | modelPackage = packageName; |
273 | 284 | apiPackage = packageName; |
|
0 commit comments