Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1499,11 +1499,16 @@ public class ExtendedCodegenModel extends CodegenModel {
public Set<String> oneOfArrays = new TreeSet<>();
@Getter @Setter
public Set<CodegenProperty> oneOfPrimitives = new HashSet<>();

@Getter @Setter
public CodegenDiscriminator.MappedModel selfReferencingDiscriminatorMapping;

public boolean isEntity; // Is a model containing an "id" property marked as isUniqueId
public String returnPassthrough;
public boolean hasReturnPassthroughVoid;


public boolean hasSelfReferencingDiscriminatorMapping(){
return selfReferencingDiscriminatorMapping != null;
}
public boolean isDateType() {
return isDate && "Date".equals(dataType);
}
Expand Down Expand Up @@ -1597,6 +1602,15 @@ public ExtendedCodegenModel(CodegenModel cm) {
this.setAdditionalProperties(cm.getAdditionalProperties());
this.setIsModel(cm.getIsModel());
this.setComposedSchemas(cm.getComposedSchemas());
if (this.discriminator != null) {
Set<CodegenDiscriminator.MappedModel> mappedModels = this.discriminator.getMappedModels();
for(CodegenDiscriminator.MappedModel mappedModel : mappedModels) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sermler latest CI shows the following errors:

[pool-1-thread-5] Generation failed for typescript-fetch: (RuntimeException) Could not process model 'InternalAuthenticatedUserDto'.Please make sure that your schema is correct!
java.lang.RuntimeException: Could not process model 'InternalAuthenticatedUserDto'.Please make sure that your schema is correct!
	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:519)
	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:444)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:1292)
	at org.openapitools.codegen.cmd.GenerateBatch$GenerationRunner.run(GenerateBatch.java:226)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.util.ConcurrentModificationException
	at java.base/java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1208)
	at java.base/java.util.TreeMap$KeyIterator.next(TreeMap.java:1262)
	at org.openapitools.codegen.languages.TypeScriptFetchClientCodegen$ExtendedCodegenModel.<init>(TypeScriptFetchClientCodegen.java:1607)
	at org.openapitools.codegen.languages.TypeScriptFetchClientCodegen.fromModel(TypeScriptFetchClientCodegen.java:564)
	at org.openapitools.codegen.languages.TypeScriptFetchClientCodegen.fromModel(TypeScriptFetchClientCodegen.java:48)
	at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1754)
	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:514)
	... 6 more

can you please review and ideally come up with a fix?

thanks again for the contribution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide a link to the CI-Job so i can see how to reproduce this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right.

or you can run ./bin/generate-samples.sh ./bin/configs/typescript-fetch-* locally (assuming you're using mac/linux or wsl under windows)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #22149

if(mappedModel.getModelName().equals(cm.classname)){
this.discriminator.getMappedModels().remove(mappedModel);
this.selfReferencingDiscriminatorMapping=mappedModel;
}
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole
return {{modelName}}FromJSONTyped(json, ignoreDiscriminator);
}
{{/discriminator.mappedModels}}
{{#hasSelfReferencingDiscriminatorMapping}}
if (json['{{discriminator.propertyBaseName}}'] === '{{selfReferencingDiscriminatorMapping.mappingName}}') {
return {{selfReferencingDiscriminatorMapping.modelName}}FromJSONTyped(json, true);
}
{{/hasSelfReferencingDiscriminatorMapping}}

}
{{/discriminator}}
return {
Expand Down