swagger-api / swagger-api/swagger-codegen
swagger-codegen generate should detect an infinitely recursive type definition and error out with informative message
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
swagger-codegen generate should detect an infinitely recursive type definition and error out with informative message
Swagger-codegen version
current master; HEAD = 1c160df33897898da1c39f230c737eb6a313e6ba
Swagger declaration file content or url
swagger: '2.0'
info:
title: "sscce"
version: '1.0'
description: sscce
definitions:
Animal:
type: object
properties:
no_legs:
type: integer
Pet:
allOf:
- $ref: "#/definitions/Pet"
- type: object
properties:
name:
type: string
Cat:
allOf:
- $ref: "#/definitions/Pet"
- type: object
properties:
likes_water:
type: boolean
paths:
/foo:
post:
parameters:
- name: cat
in: body
schema: {$ref: "#/definitions/Cat"}
responses:
"200":
description: foo
type: string
Command line used for generation
JAR=".../swagger-codegen.git/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
java -jar "${JAR}" generate -i ~/sscce.yaml -l html2 -o foo
outputs:
[main] INFO io.swagger.parser.Swagger20Parser - reading from sscce.yaml
Exception in thread "main" java.lang.StackOverflowError
at java.util.HashMap.getNode(HashMap.java:571)
at java.util.LinkedHashMap.get(LinkedHashMap.java:440)
at io.swagger.codegen.DefaultCodegen.isDiscriminatorInInterfaceTree(DefaultCodegen.java:1410)
at io.swagger.codegen.DefaultCodegen.isDiscriminatorInInterfaceTree(DefaultCodegen.java:1416)
at io.swagger.codegen.DefaultCodegen.isDiscriminatorInInterfaceTree(DefaultCodegen.java:1416)
[snip] repeats about 1000 times. ... default java recursion limit I suppose.
If I accidantely hit this in real spec as opposed to when writing sscce for something else I'd be pretty lost. I'd have to apply the technique of halving the interval, which indeed I had to do several times (for different issues) when I was starting out.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with DefaultCodegen.isDiscriminatorInInterfaceTree, where the supplied stack trace shows recursion, and reproduce the issue using the YAML declaration and the html2 generation command. Done means the recursive definition is detected and generation reports an informative error instead of terminating with StackOverflowError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100