Skip to content

[BUG] Stackoverflow in toExampleValue() #8052

@fbl100

Description

@fbl100

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
    Expected output is not crashing
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When processing recursive data structures, the PythonClientCodeGen throws a StackOverflowException in toExampleValue().

openapi-generator version

5.0.0-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: 01.01.00
  title: APITest API documentation.
  termsOfService: http://api.apitest.com/party/tos/
servers:
  - url: https://api.apitest.com/v1
paths:
  /geojson:
    post:
      summary: Add a GeoJson Object
      operationId: post-geojson
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: string
                description: GeoJson ID
        '400':
          description: Bad Request
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GeoJsonGeometry'
      parameters: []
components:
  schemas:
    GeoJsonGeometry:
      title: GeoJsonGeometry
      description: GeoJSON geometry
      oneOf:
        - $ref: '#/components/schemas/Point'
        - $ref: '#/components/schemas/GeometryCollection'
      discriminator:
        propertyName: type
        mapping:
          Point: '#/components/schemas/Point'
          GeometryCollection: '#/components/schemas/GeometryCollection'
      externalDocs:
        url: http://geojson.org/geojson-spec.html#geometry-objects
    Point:
      title: Point
      type: object
      description: GeoJSON geometry
      externalDocs:
        url: http://geojson.org/geojson-spec.html#id2
      properties:
        coordinates:
          title: Point3D
          type: array
          description: Point in 3D space
          externalDocs:
            url: http://geojson.org/geojson-spec.html#id2
          minItems: 2
          maxItems: 3
          items:
            type: number
            format: double
        type:
          type: string
          default: Point
      required:
        - type
    GeometryCollection:
      title: GeometryCollection
      type: object
      description: GeoJSon geometry collection
      required:
        - type
        - geometries
      externalDocs:
        url: http://geojson.org/geojson-spec.html#geometrycollection
      properties:
        type:
          type: string
          default: GeometryCollection
        geometries:
          type: array
          items:
            $ref: '#/components/schemas/GeoJsonGeometry'
Generation Details

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i [yaml file] -g python -o python-test

Steps to reproduce

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i [yaml file] -g python -o python-test

Related issues/PRs

#5229
#7532
OpenAPITools/openapi-json-schema-generator#31

Suggest a fix

Add a new Set to the toExampleValueRecursive() method. This set would represent the models that have already been processed. When the modelName is already contained in this set, then the recursion can stop and an example value can be generated. Otherwise, add the model to the set so that future calls can check for termination.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions