File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
modules/openapi-generator/src
main/java/org/openapitools/codegen/languages
test/java/org/openapitools/codegen/go Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -520,7 +520,7 @@ public ModelsMap postProcessModels(ModelsMap objs) {
520520 addedFmtImport = true ;
521521 }
522522
523- if (model .hasRequired ) {
523+ if (generateUnmarshalJSON && model .hasRequired ) {
524524 if (!model .isAdditionalPropertiesTrue &&
525525 (model .oneOf == null || model .oneOf .isEmpty ()) &&
526526 (model .anyOf == null || model .anyOf .isEmpty ())) {
Original file line number Diff line number Diff line change @@ -354,6 +354,27 @@ public void testVendorExtensionSkipGenerateUnmarshalJson() throws IOException {
354354 "func (o *BaseItem) UnmarshalJSON(data []byte) (err error) {" );
355355 }
356356
357+ @ Test
358+ public void testNoImportsWithoutUnmarshal () throws IOException {
359+ Map <String , Object > properties = new HashMap <>();
360+ properties .put (CodegenConstants .GENERATE_UNMARSHAL_JSON , false );
361+
362+ File output = Files .createTempDirectory ("test" ).toFile ();
363+ output .deleteOnExit ();
364+
365+ final CodegenConfigurator configurator = new CodegenConfigurator ()
366+ .setGeneratorName ("go" )
367+ .setAdditionalProperties (properties )
368+ .setInputSpec ("src/test/resources/3_0/petstore.yaml" )
369+ .setOutputDir (output .getAbsolutePath ().replace ("\\ " , "/" ));
370+
371+ DefaultGenerator generator = new DefaultGenerator ();
372+ List <File > files = generator .opts (configurator .toClientOptInput ()).generate ();
373+ files .forEach (File ::deleteOnExit );
374+
375+ TestUtils .assertFileNotContains (Paths .get (output + "/model_pet.go" ), "bytes" );
376+ }
377+
357378 @ Test
358379 public void testAdditionalPropertiesWithGoMod () throws Exception {
359380 File output = Files .createTempDirectory ("test" ).toFile ();
You can’t perform that action at this time.
0 commit comments