swagger-api / swagger-api/swagger-codegen
Same object not allowed within same api-request
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
If the same object are placed in several places within an API request there will only one occurrence produced by the ExampleGenerator.
There is an infinite loop in the Junit test for ExampleGenerator that is inhibited by allowing only one occurence of an object within an example.
Swagger-codegen version
2.2.2-SNAPSHOT
Swagger declaration file content or url
```
QueryUserGroups:
type: object
title: QueryUserGroups
properties:
status:
type: string
data:
type: object
title: QueryUserGroups
properties:
userGroups:
type: array
items:
type: string
required:
- userGroups
required:
- status
Command line used for generation
java -jar swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -l jaxrs-cxf -i api.yaml
Steps to reproduce
Related issues
Suggest a Fix
In DefaultGenerator.java:
public Object resolveModelToExample(String name, String mediaType, Model model, Set processedModels) {
// if (processedModels.contains(name)) {
// return "";
// }
In ExampleGeneratorTest.java:
@@ -26,11 +27,17 @@ public class ExampleGeneratorTest {
final String JSON = "application/json";
final String XML = "application/xml";
final String nodeType = "Node";
-
final RefProperty ref = new RefProperty(nodeType);
-
final String nodeTypeParent = "NodeParent"; -
final String nodeTypeChild = "NodeChild"; -
final RefProperty refParent = new RefProperty(nodeTypeParent); -
final RefProperty refChild = new RefProperty(nodeTypeChild); -
final Model node = new ModelImpl().name(nodeType).property("name", new StringProperty())
-
.property("parent", ref) -
.property("children", new ArrayProperty(ref)) -
.property("wrappedChildren", new ArrayProperty(ref).xml(new Xml().wrapped(true)));
-
.property("parent", refParent) -
.property("children", new ArrayProperty(refChild)) -
.property("wrappedChildren", new ArrayProperty(refChild).xml(new Xml().wrapped(true))); final String pairType = "Pair"; final ModelImpl pair = new ModelImpl().name(pairType); for (Map.Entry<String, String> item : ImmutableMap.of("first", "First", "second", "Second").entrySet()) {
In XmlExampleGenerator.java:
@@ -170,6 +169,9 @@ public class XmlExampleGenerator {
sb.append(closeTag(name));
}
}
-
if(sb.toString().equals("null")){ -
return "";
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 resolveModelToExample in DefaultGenerator.java and the related cases in ExampleGeneratorTest.java; then inspect the XML path in XmlExampleGenerator.java. Run the ExampleGenerator tests and reproduce the nested repeated-object case from the issue. Done means repeated object references are represented in the generated example without an infinite loop, with regression coverage for the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100