-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Labels
Milestone
Description
Description
I'm using a definition, where parameter is marked as required. Though, the generated code looks like:
type Object struct {
Param1 string `json:"param1,omitempty"`
}Swagger-codegen version
2.2.1
2.2.2-SNAPSHOT
Swagger declaration file content or url
swagger: '2.0'
info:
title: dummy
version: "1.0.0"
host: dummy
paths:
/dummy:
get:
definitions:
Object:
type: object
required:
- param1
properties:
param1:
type: stringCommand line used for generation
java -jar codegen.jar generate -i collection-format-test.yaml --lang go --output test-generated
Steps to reproduce
Use the provided yaml and the command line to generate to go sources and then compile.
Related issues
Suggest a Fix
The problem can be fixed by modified the model.mustache template using the following patch:
--- go/orig/model.mustache 2016-08-08 15:53:46.000000000 +0000
+++ go/model.mustache 2017-01-27 11:58:55.000000000 +0000
@@ -9,7 +9,7 @@
type {{classname}} struct {
{{#vars}}{{#description}}
// {{{description}}}{{/description}}
- {{name}} {{{datatype}}} `json:"{{baseName}},omitempty"`
+ {{name}} {{{datatype}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"`
{{/vars}}
}
{{/model}}{{/models}}
\ No newline at end of fileReactions are currently unavailable