8000 server generation chokes on flattened definitions · Issue #1388 · go-swagger/go-swagger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
server generation chokes on flattened definitions #1388
Closed
@macrael

Description

@macrael

Problem statement

go-swagger chokes when trying to generate code for certain expansions that occur during the flattening process.

Swagger specification
swagger: '2.0'
info:
  description: A Problem Document
basePath: /api/v1
consumes:
  - application/json
produces:
  - application/json
paths:
  /issues:
    post:
      summary: Create a new issue
      description: Issues represent problems or suggestions for the app, this creates a new one.
      operationId: createIssue
      tags:
        - issues
      parameters:
        - in: body
          name: createIssuePayload
          required: true
          schema:
            $ref: '#/definitions/CreateIssuePayload'
      responses:
        201:
          description: created issue
          schema:
            $ref: '#/definitions/IssuePayload'
        400:
          description: invalid request
    get:
      summary: List all issues
      description: List all issues
      operationId: indexIssues
      tags:
        - issues
      responses:
        200:
          description: list of issues
          schema:
            $ref: '#/definitions/IndexIssuesPayload'
        400:
          description: invalid request

definitions:
  CreateIssuePayload:
    type: object
    properties:
      description:
        type: string
        example: This is a test issue
    required:
      - description
  IndexIssuesPayload:
    type: array
    items:
      $ref: '#/definitions/IssuePayload'
  IssuePayload:
    allOf:
      - $ref: '#/definitions/CreateIssuePayload'
      - type: object
        properties:
          id:
            type: string
            format: uuid
            example: c56a4180-65aa-42ec-a945-5fd21dec0538
          created_at:
            type: string
            format: date-time
          updated_at:
            type: string
            format: date-time
        required:
          - id
          - created_at
          - updated_at

Steps to reproduce

swagger generate server -f swagger.yaml -t /pkg/gen --model-package messages --exclude-main -A badtime

Results

I expected the swagger generate command to succeed and generate server code.

Instead it printed the following output and exited early:

2018/01/25 14:57:44 building a plan for generation
2018/01/25 14:57:44 planning definitions
object has no key "issuePayloadAllOf1"

if you run swagger flatten it shows that in the flattening process it creates a new definition called "issuePayloadAllOf1" and changes the IssuePayload object to simply have allOf the CreateIssuePayload and the new issuePayloadAllOf1.

Also, I'd love advice on writing good swagger files, we are learning!

Environment

swagger version: 0.13.0
go version: go1.9.2 darwin/amd64
OS: macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugflattenRelated to spec flattening

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0