Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ public ModelsMap postProcessModels(ModelsMap objs) {
addedFmtImport = true;
}

if (model.hasRequired) {
if (generateUnmarshalJSON && model.hasRequired) {
if (!model.isAdditionalPropertiesTrue &&
(model.oneOf == null || model.oneOf.isEmpty()) &&
(model.anyOf == null || model.anyOf.isEmpty())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,27 @@ public void testVendorExtensionSkipGenerateUnmarshalJson() throws IOException {
"func (o *BaseItem) UnmarshalJSON(data []byte) (err error) {");
}

@Test
public void testNoImportsWithoutUnmarshal() throws IOException {
Map<String, Object> properties = new HashMap<>();
properties.put(CodegenConstants.GENERATE_UNMARSHAL_JSON, false);

File output = Files.createTempDirectory("test").toFile();
output.deleteOnExit();

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("go")
.setAdditionalProperties(properties)
.setInputSpec("src/test/resources/3_0/petstore.yaml")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));

DefaultGenerator generator = new DefaultGenerator();
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
files.forEach(File::deleteOnExit);

TestUtils.assertFileNotContains(Paths.get(output + "/model_pet.go"), "bytes");
}

@Test
public void testAdditionalPropertiesWithGoMod() throws Exception {
File output = Files.createTempDirectory("test").toFile();
Expand Down
Loading