Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7532
Closed
Open
Issue created Sep 28, 2020 by Administrator@rootContributor

[BUG][Python] Stackoverflow error when using required recursive properties

Created by: vincent-raman

Description

If we want to define a recursive type (like a tree), the client generation for python crashes with a StackOverflowError in the PythonClientCodegen.toExampleValueRecursive method.

openapi-generator version

4.3.1

OpenAPI declaration file content or url
{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Test swagger file"
  },
  "paths": {
    "/tree": {
      "post": {
        "description": "Create",
        "operationId": "createTree",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Tree"
              }
            }
          },
          "description": "The tree to create",
          "required": true
        },
        "tags": [
          "Test"
        ],
        "responses": {
          "200": {
            "description": "Successfully created the tree",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/Tree"
                }
              }
            }
          },
          "400": {
            "description": "Bad request"
          }
        }
      },
    }
  },
  "components": {
    "schemas": {
      "Tree": {
        "type": "object",
        "required": [
          "id",
          "name",
          "children"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "children": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Tree"
            }
          }
        }
      }
    }
  }
}
Generation Details

Generation of a client with language "python" and this schema definition

Steps to reproduce

Try to generate a python client

Suggest a fix

In the method PythonClientCodegen.toExampleValueRecursive, when treating an object (if (ModelUtils.isObjectSchema(schema)), the already treated properties are removed.

for (String toRemove : included_schemas) {
    if (reqs.contains(toRemove)) {
        reqs.remove(toRemove);
    }
}

But, just after, the "required" properties are added back, making this safeguard useless

if (null != schema.getRequired()) for (Object toAdd : schema.getRequired()) {
    reqs.add((String) toAdd);
}
Assignee
Assign to
Time tracking