-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
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?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Issue 8052 fixed a bug with example values for models with circular references. The test case provided was a minimal representation of GeoJSON. While it is unclear what has changed, a full representation of the GeoJson Specification now causes an infinite recursion in python-experimental. The full GeoJson Specification "works" in the legacy generator, in that it doesn't get into an infinite loop.
openapi-generator version
6.0.1+
OpenAPI declaration file content or url
The GeoJsonGeometry used in the prior test was not exactly right and may have masked the true nature of this bug. This spec is not the full GeoJson, but it is sufficient to cause the bug. Essentially a GeoJsonGeometry is either a Point, or a GeometryCollection, and a GeometryCollection can have more GeoJsonGeometry objects. The full spec includes lines, polygons, and a few more types, but this is the minimal subset that causes the issue.
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
Steps to reproduce
This test (if placed into PythonExperimentalClientTest) will recreate the bug. Note that in my testing environment, I added the GeoJson spec (above) to the prior yaml.
@Test(description = "tests RecursiveToExample")
public void testRecursiveToExample() throws IOException {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_8052_recursive_model.yaml");
final PythonExperimentalClientCodegen codegen = new PythonExperimentalClientCodegen();
codegen.setOpenAPI(openAPI);
final Operation operation = openAPI.getPaths().get("/geojson").getPost();
Schema schema = ModelUtils.getSchemaFromRequestBody(operation.getRequestBody());
String exampleValue = codegen.toExampleValue(schema, null);
// you never get here
}Related issues/PRs
Suggest a fix
I would be happy to attempt to fix it, but I could use a little guidance from @spacether. It looks like the new generator is attempting to detect cycles, and it's unclear what about the full GeoJson specification is causing the issue. Hopefully the provided yaml and test case will shed some light on this.