Skip to content

Commit a4a24a8

Browse files
authored
[typescript-fetch] Rework fix infinite recursion with self-referencing discriminator mappings (#22149)
* Prevent ConcurrentModificationException * Update typescript-fetch samples * Add fixture sample * Update samples
1 parent cbb2716 commit a4a24a8

File tree

42 files changed

+6178
-30
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+6178
-30
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
generatorName: typescript-fetch
2+
outputDir: samples/client/others/typescript-fetch/infinite-recursion-issue
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/typescript-fetch/infinite-recursion-issue.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/typescript-fetch
5+
additionalProperties:
6+
enumPropertyNaming: "original"
7+
enumUnknownDefaultCase: true

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,11 +1605,13 @@ public ExtendedCodegenModel(CodegenModel cm) {
16051605
if (this.discriminator != null) {
16061606
Set<CodegenDiscriminator.MappedModel> mappedModels = this.discriminator.getMappedModels();
16071607
for(CodegenDiscriminator.MappedModel mappedModel : mappedModels) {
1608-
if(mappedModel.getModelName().equals(cm.classname)){
1609-
this.discriminator.getMappedModels().remove(mappedModel);
1610-
this.selfReferencingDiscriminatorMapping=mappedModel;
1608+
if(mappedModel.getModelName().equals(cm.classname)) {
1609+
this.selfReferencingDiscriminatorMapping = mappedModel;
16111610
}
16121611
}
1612+
if(this.selfReferencingDiscriminatorMapping != null) {
1613+
this.discriminator.getMappedModels().remove(this.selfReferencingDiscriminatorMapping);
1614+
}
16131615
}
16141616
}
16151617

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Minimal
4+
description: Api to reproduce bug
5+
version: 0.5.1-SNAPSHOT.0
6+
tags:
7+
- name: test
8+
servers:
9+
- url: http://localhost:8080
10+
paths:
11+
/api/v1/test:
12+
get:
13+
tags:
14+
- test
15+
operationId: test
16+
responses:
17+
"200":
18+
description: test operation
19+
content:
20+
application/json:
21+
schema:
22+
type: array
23+
items:
24+
$ref: "#/components/schemas/TestBaseDto"
25+
26+
components:
27+
schemas:
28+
TestObjectType:
29+
type: string
30+
enum:
31+
- TEST1
32+
- TEST2
33+
TestBaseDto:
34+
type: object
35+
properties:
36+
something:
37+
type: string
38+
testObjectType:
39+
$ref: "#/components/schemas/TestObjectType"
40+
discriminator:
41+
propertyName: testObjectType
42+
mapping:
43+
TEST2: '#/components/schemas/ExtendDto'
44+
TEST1: '#/components/schemas/TestBaseDto'
45+
ExtendDto:
46+
allOf:
47+
- $ref: '#/components/schemas/TestBaseDto'
48+
- type: object
49+
properties:
50+
someItems:
51+
type: array
52+
items:
53+
$ref: '#/components/schemas/TestBaseDto'

samples/client/echo_api/typescript/build/.openapi-generator/FILES

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/echo_api/typescript/build/docs/AuthApi.md

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)