Closed
Description
Issue
On trying to generate code with the following yaml the model generated has invalid code. The root cause seems to be setting additionalProperties: <boolean>
instead of additionalProperties: <object>
.
There seems be some confusion regarding whether setting it to boolean is valid or not in 2.0 (but 3.0 mentions it as a possible value in its docs)
Relevant discussion: OAI/OpenAPI-Specification#668
Swagger specification
swagger: '2.0'
info:
version: 1.0.0
title: 'string-body-api'
paths:
/echo:
post:
summary: Post an object
parameters:
- name: body
in: body
schema:
$ref: "#/definitions/pet"
responses:
'200':
description: All is good
definitions:
pet:
type: object
required:
- date
properties:
date:
additionalProperties: true
type: object
description: Foo
Steps to reproduce
swagger generate client -f <file.yaml>
Generated code
type Pet struct {
// Foo
// Required: true
Date interface{} `json:"date"`
}
...
func (m *Pet) validateDate(formats strfmt.Registry) error {
if swag.IsZero(m.Date.DateAdditionalProperties) { // not required
return nil
}
return nil
}
Environment
swagger version: master
go version: go version go1.7.4 linux/amd64
OS: Centos