8000 Codegen generates invalid go code for `additionalProperties: true` · Issue #1198 · go-swagger/go-swagger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Codegen generates invalid go code for additionalProperties: true #1198
Closed
@rabisg

Description

@rabisg

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0