Closed
Description
Problem statement
go-swagger chokes when trying to generate code for certain expansions that occur during the flattening process.
Swagger specification
7097
h2>
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: '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
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