Skip to content

Commit

Permalink
Merge branch 'master' into fix-python-attrs-preset
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Feb 21, 2025
2 parents 74a4adf + 9233548 commit f806fd8
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 7 deletions.
22 changes: 20 additions & 2 deletions src/helpers/CommonModelToMetaModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,19 @@ export function convertToAnyModel(
if (!Array.isArray(jsonSchemaModel.type) || !isAnyType) {
return undefined;
}
let originalInput = jsonSchemaModel.originalInput;
if (typeof jsonSchemaModel.originalInput !== 'object') {
originalInput = {
value: jsonSchemaModel.originalInput,
...(jsonSchemaModel.originalInput?.description !== undefined && {
description: jsonSchemaModel.originalInput.description
})
};
}

return new AnyModel(
name,
jsonSchemaModel.originalInput,
originalInput,
getMetaModelOptions(jsonSchemaModel, options)
);
}
Expand Down Expand Up @@ -519,9 +529,17 @@ export function convertToDictionaryModel(
getOriginalInputFromAdditionalAndPatterns(jsonSchemaModel);
const keyModel = new StringModel(name, originalInput, {});
const valueModel = convertAdditionalAndPatterns(context);

const input = {
originalInput,
...(jsonSchemaModel.originalInput?.description !== undefined && {
description: jsonSchemaModel.originalInput.description
})
};

return new DictionaryModel(
name,
originalInput,
input,
getMetaModelOptions(jsonSchemaModel, options),
keyModel,
valueModel,
Expand Down
6 changes: 6 additions & 0 deletions test/generators/go/presets/DescriptionPreset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const doc = {
additionalProperties: false,
$id: 'NestedTest',
properties: { stringProp: { type: 'string', description: 'string prop' } }
},
anyProp: {
type: 'object',
$id: 'AnyTest',
properties: {},
description: 'AnyTest description'
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ type Test struct {
// Description
NumberProp float64
ObjectProp *NestedTest
// AnyTest description
AnyProp map[string]interface{}
}"
`;

Expand Down
6 changes: 6 additions & 0 deletions test/generators/java/presets/DescriptionPreset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ describe('JAVA_DESCRIPTION_PRESET', () => {
type: 'string',
description: 'Description for prop',
examples: ['exampleValue']
},
anyProp: {
type: 'object',
$id: 'AnyTest',
properties: {},
description: 'AnyTest description'
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ exports[`JAVA_DESCRIPTION_PRESET should render description and examples for clas
*/
public class Clazz {
private String prop;
private Map<String, Object> anyProp;
private Map<String, Object> additionalProperties;
/**
Expand All @@ -75,6 +76,12 @@ public class Clazz {
public String getProp() { return this.prop; }
public void setProp(String prop) { this.prop = prop; }
/**
* AnyTest description
*/
public Map<String, Object> getAnyProp() { return this.anyProp; }
public void setAnyProp(Map<String, Object> anyProp) { this.anyProp = anyProp; }
public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; }
public void setAdditionalProperties(Map<String, Object> additionalProperties) { this.additionalProperties = additionalProperties; }
}"
Expand Down
6 changes: 6 additions & 0 deletions test/generators/kotlin/presets/DescriptionPreset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ describe('KOTLIN_DESCRIPTION_PRESET', () => {
type: 'string',
description: 'Description for prop',
examples: ['exampleValue']
},
anyProp: {
type: 'object',
$id: 'AnyTest',
properties: {},
description: 'AnyTest description'
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ exports[`KOTLIN_DESCRIPTION_PRESET should render description and examples for cl
* Description for class
*
* @property prop Description for prop
* @property anyProp AnyTest description
* @property additionalProperties
*
* Examples:
* {\\"prop\\":\\"value\\"}
*/
data class Clazz(
val prop: String? = null,
val anyProp: Map<String, Any>? = null,
val additionalProperties: Map<String, Any>? = null,
)"
`;
Expand Down
6 changes: 6 additions & 0 deletions test/generators/php/presets/DescriptionPreset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ describe('PHP_DESCRIPTION_PRESET', () => {
type: 'string',
description: 'Description for prop',
examples: ['exampleValue']
},
anyProp: {
type: 'object',
$id: 'AnyTest',
properties: {},
description: 'AnyTest description'
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ exports[`PHP_DESCRIPTION_PRESET should render description and examples for class
final class Clazz
{
private ?string $prop;
private mixed $anyProp;
private mixed $additionalProperties;
public function getProp(): ?string { return $this->prop; }
public function setProp(?string $prop): void { $this->prop = $prop; }
public function getAnyProp(): mixed { return $this->anyProp; }
public function setAnyProp(mixed $anyProp): void { $this->anyProp = $anyProp; }
public function getAdditionalProperties(): mixed { return $this->additionalProperties; }
public function setAdditionalProperties(mixed $additionalProperties): void { $this->additionalProperties = $additionalProperties; }
}
Expand Down
6 changes: 6 additions & 0 deletions test/generators/scala/presets/DescriptionPreset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ describe('SCALA_DESCRIPTION_PRESET', () => {
type: 'string',
description: 'Description for prop',
examples: ['exampleValue']
},
anyProp: {
type: 'object',
$id: 'AnyTest',
properties: {},
description: 'AnyTest description'
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ exports[`SCALA_DESCRIPTION_PRESET should render description and examples for cla
* Description for class
*
* @property prop Description for prop
* @property anyProp AnyTest description
* @property additionalProperties
*
* Examples:
* {\\"prop\\":\\"value\\"}
*/
case class Clazz(
prop: Option[String],
anyProp: Option[Map[String, Any]],
additionalProperties: Option[Map[String, Any]],
)"
`;
Expand Down
6 changes: 6 additions & 0 deletions test/generators/typescript/preset/DescriptionPreset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const doc = {
$id: 'NestedTest',
properties: { stringProp: { type: 'string' } },
examples: ['Example 1', 'Example 2']
},
anyProp: {
type: 'object',
$id: 'AnyTest',
properties: {},
description: 'AnyTest description'
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ class Test {
private _stringProp: string;
private _numberProp?: number;
private _objectProp?: NestedTest;
private _anyProp?: Map<string, any>;
private _additionalProperties?: Map<string, any>;
constructor(input: {
stringProp: string,
numberProp?: number,
objectProp?: NestedTest,
anyProp?: Map<string, any>,
additionalProperties?: Map<string, any>,
}) {
this._stringProp = input.stringProp;
this._numberProp = input.numberProp;
this._objectProp = input.objectProp;
this._anyProp = input.anyProp;
this._additionalProperties = input.additionalProperties;
}
Expand All @@ -38,6 +41,12 @@ class Test {
get objectProp(): NestedTest | undefined { return this._objectProp; }
set objectProp(objectProp: NestedTest | undefined) { this._objectProp = objectProp; }
/**
* AnyTest description
*/
get anyProp(): Map<string, any> | undefined { return this._anyProp; }
set anyProp(anyProp: Map<string, any> | undefined) { this._anyProp = anyProp; }
get additionalProperties(): Map<string, any> | undefined { return this._additionalProperties; }
set additionalProperties(additionalProperties: Map<string, any> | undefined) { this._additionalProperties = additionalProperties; }
}"
Expand Down
20 changes: 15 additions & 5 deletions test/processors/__snapshots__/AsyncAPIInputProcessor.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ Object {
"options": Object {
"isNullable": true,
},
"originalInput": true,
"originalInput": Object {
"value": true,
},
},
},
"propertyName": "additionalProperties",
Expand Down Expand Up @@ -149,7 +151,9 @@ Object {
"options": Object {
"isNullable": true,
},
"originalInput": true,
"originalInput": Object {
"value": true,
},
},
},
"propertyName": "additionalProperties",
Expand Down Expand Up @@ -4265,7 +4269,9 @@ InputMetaModel {
"options": Object {
"isNullable": true,
},
"originalInput": true,
"originalInput": Object {
"value": true,
},
},
},
"propertyName": "additionalProperties",
Expand Down Expand Up @@ -4438,7 +4444,9 @@ InputMetaModel {
"options": Object {
"isNullable": true,
},
"originalInput": true,
"originalInput": Object {
"value": true,
},
},
},
"propertyName": "additionalProperties",
Expand Down Expand Up @@ -4611,7 +4619,9 @@ InputMetaModel {
"options": Object {
"isNullable": true,
},
"originalInput": true,
"originalInput": Object {
"value": true,
},
},
},
"propertyName": "additionalProperties",
Expand Down

0 comments on commit f806fd8

Please sign in to comment.