Developed according to 📗 Official documentation
* [YOJO](#yojo)
* [YAML to POJO generator](#yaml-to-pojo-generator-)
The generator works with schema objects described in components:
An excerpt from the 📜 AsyncApi documentation:
The AsyncAPI Schema Object is a JSON Schema vocabulary which extends JSON Schema Core and Validation vocabularies. As such, any keyword available for those vocabularies is by definition available in AsyncAPI, and will work the exact same way, including but not limited to:
-
title
-
type
-
required
-
multipleOf
-
maximum
-
exclusiveMaximum
-
minimum
-
exclusiveMinimum
-
maxLength
-
minLength
-
pattern
(This string SHOULD be a valid regular expression, according to the ECMA 262 regular expression dialect) -
maxItems
-
minItems
-
uniqueItems
-
maxProperties
-
minProperties
-
enum
-
const
-
examples
-
if
/then
/else
-
readOnly
-
writeOnly
-
properties
-
patternProperties
-
additionalProperties
-
additionalItems
-
items
-
propertyNames
-
contains
-
allOf
-
oneOf
-
anyOf
-
not
The following properties are taken from the JSON Schema definition but their definitions were adjusted to the AsyncAPI Specification.
-
description
- CommonMark syntax can be used for rich text representation. -
format
- See Data Type Formats for further details. While relying on JSON Schema's defined formats, the AsyncAPI Specification offers a few additional predefined formats. -
default
- The default value represents what would be assumed by the consumer of the input as the value of the schema if one is not provided. Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level. For example, of type is string, then default can be "foo" but cannot be 1. -
$ref
- Alternatively, any time a Schema Object can be used, a Reference Object can be used in its place. This allows referencing definitions in place of defining them inline. It is appropriate to clarify that the $ref keyword MUST follow the behavior described by Reference Object instead of the one in JSON Schema definition.
Not all keywords are currently available. Available are marked with a checkbox.
Find examples here for more cases
At the moment, yojo is actively being refined and supplemented with various custom attributes for convenient code generation in Java. The features available today are:
Please note that it is always necessary to fill in the type
attribute!
You can fill message like this:
RequestDtoByRef:
payload:
#This attribute will help you generate the message in the package you need.
pathForGenerateMessage: 'io.github.somepath'
$ref: '#/components/schemas/RequestDtoSchema'
And you will get message like:
package example.testGenerate.contract.test.io.github.somepath;
public class RequestDtoByRef {
}
Also you can make generate messages with propeties like:
RequestDtoByRefAndProperties:
payload:
$ref: '#/components/schemas/RequestDtoSchema'
properties:
someString:
type: String
And you will getting this one:
package example.testGenerate.contract.test.messages;
public class RequestDtoByRefAndProperties {
private String someString;
}
This is what the option looks like with all possible attributes:
RequestDtoWithDoubleInheritance:
payload:
#You can use enable true/false on lombok
lombok:
accessors:
chain: true
fluent: false
equalsAndHashCode:
enable: true
callSuper: true
allArgsConstructor: true
noArgsConstructor: false
#removeSchema - schema in the reference will not be deleted.
removeSchema: false
$ref: '#/components/schemas/RequestDtoSchema'
implements:
fromInterface:
- testGenerate.InterfaceForImpl
- testGenerate.InterfaceForImpl2
extends:
fromClass: ClassForExtends
fromPackage: example.testGenerate.contract.test.common
In the end, you will easily obtain such a class:
@Data
@Accessors(chain = true)
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class RequestDtoWithDoubleInheritance extends ClassForExtends implements InterfaceForImpl,InterfaceForImpl2 {
}
See more in here
This is what the option looks like with all possible attributes:
RequestDtoSchema:
type: object
lombok:
accessors:
enable: false
implements:
fromInterface:
- testGenerate.InterfaceForImpl
- testGenerate.InterfaceForImpl2
extends:
fromClass: ClassForExtends
fromPackage: example.testGenerate.contract.test.common
In the end, you will easily obtain such a class:
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RequestDtoSchema extends ClassForExtends implements InterfaceForImpl,InterfaceForImpl2 {
}
Common name |
type | format | Result |
---|---|---|---|
integer | integer | int32 | Integer |
long | integer | int64 | Long |
float | number | float | Float |
double | number | double | Double |
byte | string | byte | Byte |
bigInteger | number | bigInteger | BigInteger |
bigDecimal | number | bigDecimal | BigDecimal |
boolean | boolean | - | Boolean |
string | string | - | String |
uuid | string | uuid | UUID |
date | object | simple-date | Date |
date | string | date | LocalDate |
dateTime | string | date-time | LocalDateTime |
offsetDateTime | string | offsetDateTime | OffsetDateTime |
The list is constantly being updated; for more details, see the examples.
Attribute | Description | Example |
---|---|---|
realization | Use this attribute to specify the type of collection being used | Accepts realization by name. = new ArrayList/HashSet/HashMap etc. |
primitive | Use for generating primitive types. | Accepts a boolean. long, int, byte, boolean etc. |
existing package |
Use for generating with using existing object. | |
digits | Use for generating @Digits annotation | |
removeSchema | Used in messages. See examples | |
interface definition |
Use for generating interfaces. | |
extends implements fromClass fromPackage fromInterface |
Attributes for extending or implementing objects |
The list is constantly being updated; for more details, see the examples.
Also the generator is capable of generating collections(Map,List,Set) and enums.
Please contact me if you need assistance; I will definitely help you. This instruction only covers a small part of what can be generated. Use the examples, or download the open source code and run the test cases, commenting out the file deletion in them beforehand.
- 😎 Vladimir Morozkin
- 💬 Contacts:
- 📧 Email:
[email protected]
- 📟 Telegram:
@vmorozkin
- 📧 Email:
- 💬 Contacts: