Skip to content

Commit

Permalink
Merge branch 'asyncapi:master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-supy-io authored Feb 21, 2025
2 parents 1b6cbf1 + 039dab0 commit 527b32a
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 24 deletions.
22 changes: 11 additions & 11 deletions modelina-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ $ npm install -g @asyncapi/modelina-cli
$ modelina COMMAND
running command...
$ modelina (--version)
@asyncapi/modelina-cli/4.0.2 linux-x64 node-v18.20.6
@asyncapi/modelina-cli/4.0.3 linux-x64 node-v18.20.6
$ modelina --help [COMMAND]
USAGE
$ modelina COMMAND
Expand Down Expand Up @@ -240,7 +240,7 @@ DESCRIPTION
CLI config settings
```

_See code: [src/commands/config/index.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/index.ts)_
_See code: [src/commands/config/index.ts](https://github.com/asyncapi/modelina/blob/v4.0.3/modelina-cli/src/commands/config/index.ts)_

## `modelina config context`

Expand All @@ -254,7 +254,7 @@ DESCRIPTION
Manage short aliases for full paths to inputs
```

_See code: [src/commands/config/context/index.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/index.ts)_
_See code: [src/commands/config/context/index.ts](https://github.com/asyncapi/modelina/blob/v4.0.3/modelina-cli/src/commands/config/context/index.ts)_

## `modelina config context add CONTEXT-NAME SPEC-FILE-PATH`

Expand All @@ -276,7 +276,7 @@ DESCRIPTION
Add a context to the store
```

_See code: [src/commands/config/context/add.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/add.ts)_
_See code: [src/commands/config/context/add.ts](https://github.com/asyncapi/modelina/blob/v4.0.3/modelina-cli/src/commands/config/context/add.ts)_

## `modelina config context current`

Expand All @@ -293,7 +293,7 @@ DESCRIPTION
Shows the current context that is being used
```

_See code: [src/commands/config/context/current.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/current.ts)_
_See code: [src/commands/config/context/current.ts](https://github.com/asyncapi/modelina/blob/v4.0.3/modelina-cli/src/commands/config/context/current.ts)_

## `modelina config context edit CONTEXT-NAME NEW-SPEC-FILE-PATH`

Expand All @@ -314,7 +314,7 @@ DESCRIPTION
Edit a context in the store
```

_See code: [src/commands/config/context/edit.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/edit.ts)_
_See code: [src/commands/config/context/edit.ts](https://github.com/asyncapi/modelina/blob/v4.0.3/modelina-cli/src/commands/config/context/edit.ts)_

## `modelina config context init [CONTEXT-FILE-PATH]`

Expand All @@ -337,7 +337,7 @@ DESCRIPTION
Initialize context
```

_See code: [src/commands/config/context/init.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/init.ts)_
_See code: [src/commands/config/context/init.ts](https://github.com/asyncapi/modelina/blob/v4.0.3/modelina-cli/src/commands/config/context/init.ts)_

## `modelina config context list`

Expand All @@ -354,7 +354,7 @@ DESCRIPTION
List all the stored contexts in the store
```

_See code: [src/commands/config/context/list.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/list.ts)_
_See code: [src/commands/config/context/list.ts](https://github.com/asyncapi/modelina/blob/v4.0.3/modelina-cli/src/commands/config/context/list.ts)_

## `modelina config context remove CONTEXT-NAME`

Expand All @@ -374,7 +374,7 @@ DESCRIPTION
Delete a context from the store
```

_See code: [src/commands/config/context/remove.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/remove.ts)_
_See code: [src/commands/config/context/remove.ts](https://github.com/asyncapi/modelina/blob/v4.0.3/modelina-cli/src/commands/config/context/remove.ts)_

## `modelina config context use CONTEXT-NAME`

Expand All @@ -394,7 +394,7 @@ DESCRIPTION
Set a context as current
```

_See code: [src/commands/config/context/use.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/use.ts)_
_See code: [src/commands/config/context/use.ts](https://github.com/asyncapi/modelina/blob/v4.0.3/modelina-cli/src/commands/config/context/use.ts)_

## `modelina generate LANGUAGE FILE`

Expand Down Expand Up @@ -458,7 +458,7 @@ DESCRIPTION
Generates typed models
```

_See code: [src/commands/generate.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/generate.ts)_
_See code: [src/commands/generate.ts](https://github.com/asyncapi/modelina/blob/v4.0.3/modelina-cli/src/commands/generate.ts)_

## `modelina help [COMMAND]`

Expand Down
4 changes: 2 additions & 2 deletions modelina-cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion modelina-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@asyncapi/modelina-cli",
"description": "CLI to work with Modelina",
"version": "4.0.3",
"version": "4.0.4",
"bin": {
"modelina": "./bin/run_bin"
},
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@asyncapi/modelina",
"version": "4.0.3",
"version": "4.0.4",
"description": "Library for generating data models based on inputs such as AsyncAPI, OpenAPI, or JSON Schema documents",
"license": "Apache-2.0",
"homepage": "https://www.modelina.org",
Expand Down
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
Loading

0 comments on commit 527b32a

Please sign in to comment.