Skip to content

Commit fd46952

Browse files
committed
feat: java generation config in openapitools and templates changed dirs
1 parent 25c3487 commit fd46952

File tree

11 files changed

+247
-68
lines changed

11 files changed

+247
-68
lines changed

.github/workflows/types-codegen-pr.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ jobs:
4040
- name: Setup Java
4141
uses: actions/setup-java@v4
4242
with:
43-
distribution: 'temurin'
43+
distribution: 'corretto'
4444
java-version: '21'
45-
#should we cache: 'gradle'
45+
cache: 'maven'
4646

47-
- name: Build Java
47+
- name: Build Java with Maven
4848
working-directory: types/codegen/generated/java
49-
run: ./gradlew build
49+
run: mvn clean verify

types/codegen/.gitignore

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1+
# Generated code
12
generated/
2-
typescript-template-bank
3+
4+
# Template bank
5+
typescript-template-bank/
6+
7+
# OpenAPI generator metadata
8+
.openapi-generator/
9+
10+
# Node.js dependencies
11+
node_modules/
12+
13+
# Build outputs
14+
dist/

types/codegen/custom-templates/java/.template_metadata.json

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
{{!This is a comment. Removed the export of runtimes because we do not need
4+
those functions. Was causing error because exported a def called ResponseError
5+
which is also used by vscode LSP}}
6+
{{#models.0}}
7+
export * from './models/index{{importFileExtension}}';
8+
{{/models.0}}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{{#stringEnums}}
2+
/**
3+
* {{#lambda.indented_star_1}}{{{unescapedDescription}}}{{/lambda.indented_star_1}}
4+
* @export
5+
* @type {string}
6+
*/
7+
export type {{classname}} = {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}} | {{/-last}}{{/enumVars}}{{/allowableValues}};
8+
{{/stringEnums}}{{^stringEnums}}
9+
/**
10+
* {{#lambda.indented_star_1}}{{{unescapedDescription}}}{{/lambda.indented_star_1}}
11+
* @export
12+
*/
13+
export const {{classname}} = {
14+
{{#allowableValues}}
15+
{{#enumVars}}
16+
{{#enumDescription}}
17+
/**
18+
* {{enumDescription}}
19+
*/
20+
{{/enumDescription}}
21+
{{{name}}}: {{{value}}}{{^-last}},{{/-last}}
22+
{{/enumVars}}
23+
{{/allowableValues}}
24+
} as const;
25+
export type {{classname}} = typeof {{classname}}[keyof typeof {{classname}}];
26+
{{/stringEnums}}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* {{#lambda.indented_star_1}}{{{unescapedDescription}}}{{/lambda.indented_star_1}}
3+
* @export
4+
* @interface {{classname}}
5+
*/
6+
export interface {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{
7+
{{#additionalPropertiesType}}
8+
[key: string]: {{{additionalPropertiesType}}}{{#hasVars}} | any{{/hasVars}};
9+
{{/additionalPropertiesType}}
10+
{{#vars}}
11+
/**
12+
* {{#lambda.indented_star_4}}{{{unescapedDescription}}}{{/lambda.indented_star_4}}
13+
* @type {{=<% %>=}}{<%&datatype%>}<%={{ }}=%>
14+
* @memberof {{classname}}
15+
{{#deprecated}}
16+
* @deprecated
17+
{{/deprecated}}
18+
*/
19+
{{#isReadOnly}}readonly {{/isReadOnly}}{{name}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}};
20+
{{/vars}}
21+
}{{#hasEnums}}
22+
23+
{{#vars}}
24+
{{!Changed to make actual string enum}}
25+
{{#isEnum}}
26+
{{#stringEnums}}
27+
/**
28+
* @export
29+
* @type {string}
30+
*/
31+
export type {{classname}}{{enumName}} = {{#allowableValues}} {{#enumVars}}{{{value}}}{{^-last}} | {{/-last}}{{/enumVars}}{{/allowableValues}};
32+
33+
{{/stringEnums}}{{^stringEnums}}
34+
/**
35+
* @export
36+
*/
37+
export const {{classname}}{{enumName}} = {
38+
{{#allowableValues}}
39+
{{#enumVars}}
40+
{{{name}}}: {{{value}}}{{^-last}},{{/-last}}
41+
{{/enumVars}}
42+
{{/allowableValues}}
43+
} as const;
44+
export type {{classname}}{{enumName}} = typeof {{classname}}{{enumName}}[keyof typeof {{classname}}{{enumName}}];
45+
{{/stringEnums}}
46+
{{/isEnum}}{{/vars}}{{/hasEnums}}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
import { Position, Range, TextDocumentIdentifier } from 'vscode-languageserver-types'
4+
5+
{{#models}}
6+
{{#model}}
7+
{{^withoutRuntimeChecks}}
8+
export * from './{{{ classFilename }}}{{importFileExtension}}';
9+
{{#useSagaAndRecords}}
10+
{{^isEnum}}
11+
export * from './{{{ classFilename }}}Record{{importFileExtension}}';
12+
{{/isEnum}}
13+
{{/useSagaAndRecords}}
14+
{{/withoutRuntimeChecks}}
15+
{{#withoutRuntimeChecks}}
16+
{{#isEnum}}
17+
{{>modelEnumInterfaces}}
18+
{{/isEnum}}
19+
{{^isEnum}}
20+
{{#oneOf}}
21+
{{#-first}}
22+
{{>modelOneOfInterfaces}}
23+
{{/-first}}
24+
{{/oneOf}}
25+
{{^oneOf}}
26+
{{>modelGenericInterfaces}}
27+
{{/oneOf}}
28+
{{/isEnum}}
29+
{{/withoutRuntimeChecks}}
30+
{{/model}}
31+
{{/models}}

types/codegen/openapitools.json

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
"generator-cli": {
55
"version": "7.14.0",
66
"generators": {
7-
"typescript-fetch": {
7+
"typescript": {
88
"generatorName": "typescript-fetch",
9-
"output": "#{cwd}/generated",
9+
"disabled": false,
10+
"output": "#{cwd}/generated/typescript",
1011
"inputSpec": "#{cwd}/schema/chatTypes.json",
11-
"templateDir": "#{cwd}/custom-templates",
12+
"templateDir": "#{cwd}/custom-templates/typescript",
1213
"additionalProperties": {
1314
"supportsES6": true,
1415
"modelPropertyNaming": "camelCase",
@@ -20,15 +21,39 @@
2021
"stringEnums": true,
2122
"disallowAdditionalPropertiesIfNotPresent": false
2223
},
23-
"global-property": {
24-
"generateAliasAsModel": true
25-
},
24+
"global-property": {},
2625
"openapi-normalizer": {
2726
"REF_AS_PARENT_IN_ALLOF": true
2827
},
2928
"reservedWordsMappings": {
3029
"export": "export"
3130
}
31+
},
32+
"java": {
33+
"generatorName": "java",
34+
"disabled": false,
35+
"output": "#{cwd}/generated/java",
36+
"inputSpec": "#{cwd}/schema/chatTypes.json",
37+
"templateDir": "#{cwd}/custom-templates/java",
38+
"additionalProperties": {
39+
"useOneOfInterfaces": true,
40+
"legacyDiscriminatorBehavior": false,
41+
"java8": false,
42+
"dateLibrary": "java8",
43+
"serializableModel": false,
44+
"useBeanValidation": false,
45+
"performBeanValidation": false,
46+
"sourceCompatibility": "21",
47+
"targetCompatibility": "21"
48+
},
49+
"global-property": {
50+
"models": "CursorPosition:FileParams:CopyFileParams:OpenFileDiffParams:ShowOpenDialogParams:ShowSaveFileDialogParams:ShowSaveFileDialogResult"
51+
},
52+
"importMappings": {
53+
"Position": "org.eclipse.lsp4j.Position",
54+
"Range": "org.eclipse.lsp4j.Range",
55+
"TextDocumentIdentifier": "org.eclipse.lsp4j.TextDocumentIdentifier"
56+
}
3257
}
3358
}
3459
}

types/codegen/post-generate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const fs = require('fs')
44
const path = require('path')
55

66
// Path to the generated index.ts file
7-
const indexPath = path.join(__dirname, 'generated/src/models/index.ts')
7+
const indexPath = path.join(__dirname, 'generated/typescript/src/models/index.ts')
88

99
// Read the constants file
1010
const constants = fs.readFileSync(path.join(__dirname, 'constants.ts'), 'utf8')

0 commit comments

Comments
 (0)