(
name: string,
schema: JSONSchema7,
packageName: string,
packageDir: string,
headerComment: string
)
| 1130 | } |
| 1131 | |
| 1132 | async function generateStandaloneEnum( |
| 1133 | name: string, |
| 1134 | schema: JSONSchema7, |
| 1135 | packageName: string, |
| 1136 | packageDir: string, |
| 1137 | headerComment: string |
| 1138 | ): Promise<void> { |
| 1139 | const values = schema.enum as string[]; |
| 1140 | const lines: string[] = []; |
| 1141 | lines.push(COPYRIGHT); |
| 1142 | lines.push(""); |
| 1143 | lines.push(AUTO_GENERATED_HEADER); |
| 1144 | lines.push(headerComment); |
| 1145 | lines.push(""); |
| 1146 | lines.push(`package ${packageName};`); |
| 1147 | lines.push(""); |
| 1148 | lines.push(`import javax.annotation.processing.Generated;`); |
| 1149 | lines.push(""); |
| 1150 | if (schema.description) { |
| 1151 | lines.push(`/**`); |
| 1152 | lines.push(` * ${schema.description}`); |
| 1153 | lines.push(` *`); |
| 1154 | lines.push(` * @since 1.0.0`); |
| 1155 | lines.push(` */`); |
| 1156 | } |
| 1157 | lines.push(GENERATED_ANNOTATION); |
| 1158 | lines.push(`public enum ${name} {`); |
| 1159 | for (let i = 0; i < values.length; i++) { |
| 1160 | const v = values[i]; |
| 1161 | const comma = i < values.length - 1 ? "," : ";"; |
| 1162 | lines.push(` /** The {@code ${v}} variant. */`); |
| 1163 | lines.push(` ${toEnumConstant(v)}("${v}")${comma}`); |
| 1164 | } |
| 1165 | lines.push(""); |
| 1166 | lines.push(` private final String value;`); |
| 1167 | lines.push(` ${name}(String value) { this.value = value; }`); |
| 1168 | lines.push(` @com.fasterxml.jackson.annotation.JsonValue`); |
| 1169 | lines.push(` public String getValue() { return value; }`); |
| 1170 | lines.push(` @com.fasterxml.jackson.annotation.JsonCreator`); |
| 1171 | lines.push(` public static ${name} fromValue(String value) {`); |
| 1172 | lines.push(` for (${name} v : values()) {`); |
| 1173 | lines.push(` if (v.value.equals(value)) return v;`); |
| 1174 | lines.push(` }`); |
| 1175 | lines.push(` throw new IllegalArgumentException("Unknown ${name} value: " + value);`); |
| 1176 | lines.push(` }`); |
| 1177 | lines.push(`}`); |
| 1178 | lines.push(""); |
| 1179 | |
| 1180 | await writeGeneratedFile(`${packageDir}/${name}.java`, lines.join("\n")); |
| 1181 | } |
| 1182 | |
| 1183 | async function generateStandaloneRecord( |
| 1184 | name: string, |
no test coverage detected
searching dependent graphs…