Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit e5bc774

Browse files
committed
v2 includes module name in ref class (#63)
* Uses new fromProperty, passes sourceJsonPath * Samples regenerated * Adds toRefClass for python, updates toModelDocFilename for python * Petstore regenerated, component doc filenames updated * Self references updated * Fixes readme links to models * Fixes model doc links for self references * Adds two self referenicng models * Updates toModelImport to use refClass * Updates discriminator and example code to handle complexType values in map * Adds import generation back in * Makes java variable * Petstore regen, fixes contains check for period * Uses complexClass in endpoint docs for inputs * Fixes tests in PythonClinteTest * FIxes more java tests * Fixes $refs in ObjectModelWithRefProps * Removes broken java defaultCodegen test * Adds TestSelfReferencingObjectModel * Adds TestSelfReferencingArrayModel * Fixes some java tests * Fixes remaining java tests * Samples regenerated
1 parent c21e654 commit e5bc774

File tree

845 files changed

+4601
-3745
lines changed

Some content is hidden

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

845 files changed

+4601
-3745
lines changed

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public interface CodegenConfig {
185185

186186
String toModelDocFilename(String name);
187187

188-
String toModelImport(String name);
188+
String toModelImport(String refClass);
189189

190190
Map<String, String> toModelImportMap(String name);
191191

@@ -330,4 +330,6 @@ public interface CodegenConfig {
330330
boolean getUseInlineModelResolver();
331331

332332
boolean getAddSuffixToDuplicateOperationNicknames();
333+
334+
String toRefClass(String ref, String sourceJsonPath);
333335
}

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenModel.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,8 @@ public void addDiscriminatorMappedModelsImports() {
12141214
}
12151215
for (CodegenDiscriminator.MappedModel mm : discriminator.getMappedModels()) {
12161216
if (!"".equals(mm.getModelName())) {
1217-
imports.add(mm.getModelName());
1217+
String complexType = mm.getModelName();
1218+
imports.add(complexType);
12181219
}
12191220
}
12201221
}

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

+253-207
Large diffs are not rendered by default.

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -1283,26 +1283,29 @@ private ModelsMap processModels(CodegenConfig config, Map<String, Schema> defini
12831283
List<ModelMap> modelMaps = new ArrayList<>();
12841284
Set<String> allImports = new LinkedHashSet<>();
12851285
for (Map.Entry<String, Schema> definitionsEntry : definitions.entrySet()) {
1286-
String key = definitionsEntry.getKey();
1286+
String schemaName = definitionsEntry.getKey();
12871287
Schema schema = definitionsEntry.getValue();
12881288
if (schema == null)
12891289
throw new RuntimeException("schema cannot be null in processModels");
1290-
CodegenModel cm = config.fromModel(key, schema);
1290+
CodegenModel cm = config.fromModel(schemaName, schema);
12911291
ModelMap mo = new ModelMap();
12921292
mo.setModel(cm);
1293-
mo.put("importPath", config.toModelImport(cm.classname));
1293+
mo.put("importPath", config.toModelImport(config.toRefClass("#/components/schemas/"+schemaName, "")));
12941294
modelMaps.add(mo);
12951295

12961296
cm.removeSelfReferenceImport();
12971297

1298+
if (cm.imports == null || cm.imports.size() == 0) {
1299+
continue;
1300+
}
12981301
allImports.addAll(cm.imports);
12991302
}
13001303
objs.setModels(modelMaps);
13011304
Set<String> importSet = new ConcurrentSkipListSet<>();
13021305
for (String nextImport : allImports) {
13031306
String mapping = config.importMapping().get(nextImport);
13041307
if (mapping == null) {
1305-
mapping = config.toModelImport(nextImport);
1308+
mapping = nextImport;
13061309
}
13071310
if (mapping != null && !config.defaultIncludes().contains(mapping)) {
13081311
importSet.add(mapping);

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/IJsonSchemaValidationProperties.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ default Set<String> getImports(boolean importContainerType, boolean importBaseTy
349349
DefaultCodegenTest.mapParamImportInnerObject
350350
*/
351351
String refClass = this.getRefClass();
352-
if (refClass != null) {
352+
if (refClass != null && refClass.contains(".")) {
353+
// self reference classes do not contain periods
353354
imports.add(refClass);
354355
}
355356
/*
@@ -364,7 +365,8 @@ default Set<String> getImports(boolean importContainerType, boolean importBaseTy
364365
} else {
365366
// referenced or inline schemas
366367
String refClass = this.getRefClass();
367-
if (refClass != null) {
368+
if (refClass != null && refClass.contains(".")) {
369+
// self reference classes do not contain periods
368370
imports.add(refClass);
369371
}
370372
String baseType = this.getBaseType();

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1081,15 +1081,15 @@ public GeneratorLanguage generatorLanguage() {
10811081
}
10821082

10831083
@Override
1084-
protected void updateModelForObject(CodegenModel m, Schema schema) {
1084+
protected void updateModelForObject(CodegenModel m, Schema schema, String sourceJsonPath) {
10851085
/**
10861086
* we have a custom version of this function so we only set isMap to true if
10871087
* ModelUtils.isMapSchema
10881088
* In other generators, isMap is true for all type object schemas
10891089
*/
10901090
if (schema.getProperties() != null || schema.getRequired() != null && !(schema instanceof ComposedSchema)) {
10911091
// passing null to allProperties and allRequired as there's no parent
1092-
addVars(m, unaliasPropertySchema(schema.getProperties()), schema.getRequired(), null, null);
1092+
addVars(m, unaliasPropertySchema(schema.getProperties()), schema.getRequired(), null, null, sourceJsonPath);
10931093
}
10941094
if (ModelUtils.isMapSchema(schema)) {
10951095
// an object or anyType composed schema that has additionalProperties set
@@ -1103,6 +1103,6 @@ protected void updateModelForObject(CodegenModel m, Schema schema) {
11031103
}
11041104
}
11051105
// process 'additionalProperties'
1106-
setAddProps(schema, m);
1106+
setAddProps(schema, m, sourceJsonPath);
11071107
}
11081108
}

0 commit comments

Comments
 (0)