Skip to content

Commit ff5cb88

Browse files
mridangclaude
andcommitted
feat: standardize file headers and convert Node test files to templates
- Add {{>api_info}} partial to all source templates in Python, PHP, Elixir, and Ruby for consistent file headers across all 12 languages - Replace {{>partial_header}} with {{>api_info}} in PHP and Python, delete redundant partial_header.mustache files - Convert 10 static Node .ts test files to .mustache templates with {{importFileExtension}} support - Fix renderOptionsTemplate to support Mustache partials via template loader and inject additionalProperties into options context - Rename Go Makefile fmt target to format for consistency - Add lint and analyze targets to C# Makefile Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 89d04fc commit ff5cb88

372 files changed

Lines changed: 1514 additions & 1717 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/io/github/mridang/codegen/generators/AbstractBetterCodegen.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.swagger.v3.oas.models.tags.Tag;
1313
import java.io.BufferedReader;
1414
import java.io.File;
15+
import java.io.FileNotFoundException;
1516
import java.io.IOException;
1617
import java.io.InputStream;
1718
import java.io.InputStreamReader;
@@ -1472,6 +1473,9 @@ protected void writeFile(String filePath, String content) {
14721473
* apiTemplateFiles mechanism cannot produce per-operation files.
14731474
*/
14741475
protected String renderOptionsTemplate(String templateName, Map<String, Object> context) {
1476+
for (Map.Entry<String, Object> entry : additionalProperties.entrySet()) {
1477+
context.putIfAbsent(entry.getKey(), entry.getValue());
1478+
}
14751479
final String templatePath = embeddedTemplateDir + "/" + templateName;
14761480
try (InputStream is =
14771481
getClass().getClassLoader().getResourceAsStream(templatePath);
@@ -1480,7 +1484,25 @@ protected String renderOptionsTemplate(String templateName, Map<String, Object>
14801484
Objects.requireNonNull(
14811485
is, "Template not found: " + templatePath),
14821486
StandardCharsets.UTF_8)) {
1483-
return Mustache.compiler().escapeHTML(false).compile(reader).execute(context);
1487+
return Mustache.compiler()
1488+
.escapeHTML(false)
1489+
.withLoader(
1490+
name -> {
1491+
String partialPath =
1492+
embeddedTemplateDir + "/" + name + ".mustache";
1493+
InputStream partialIs =
1494+
getClass()
1495+
.getClassLoader()
1496+
.getResourceAsStream(partialPath);
1497+
if (partialIs == null) {
1498+
throw new FileNotFoundException(
1499+
"Partial not found: " + partialPath);
1500+
}
1501+
return new InputStreamReader(
1502+
partialIs, StandardCharsets.UTF_8);
1503+
})
1504+
.compile(reader)
1505+
.execute(context);
14841506
} catch (IOException e) {
14851507
throw new UncheckedIOException("Failed to render template: " + templatePath, e);
14861508
}

src/main/java/io/github/mridang/codegen/generators/node/BetterNodeCodegen.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,22 +313,22 @@ public void processOpts() {
313313
supportingFiles.add(new SupportingFile("test/setup.ts", "test", "setup.ts"));
314314
supportingFiles.add(
315315
new SupportingFile(
316-
"test/Api/pet-api.test.ts",
316+
"test/Api/pet-api.test.mustache",
317317
Path.of("test", "Api").toString(),
318318
"pet-api.test.ts"));
319319
supportingFiles.add(
320320
new SupportingFile(
321-
"test/Api/store-api.test.ts",
321+
"test/Api/store-api.test.mustache",
322322
Path.of("test", "Api").toString(),
323323
"store-api.test.ts"));
324324
supportingFiles.add(
325325
new SupportingFile(
326-
"test/default-api-client.test.ts",
326+
"test/default-api-client.test.mustache",
327327
"test",
328328
"default-api-client.test.ts"));
329329
supportingFiles.add(
330330
new SupportingFile(
331-
"test/default-api-client-unit.test.ts",
331+
"test/default-api-client-unit.test.mustache",
332332
"test",
333333
"default-api-client-unit.test.ts"));
334334
supportingFiles.add(
@@ -338,17 +338,17 @@ public void processOpts() {
338338
"transport-options.test.ts"));
339339
supportingFiles.add(
340340
new SupportingFile(
341-
"test/object-serializer.test.ts",
341+
"test/object-serializer.test.mustache",
342342
"test",
343343
"object-serializer.test.ts"));
344344
supportingFiles.add(
345345
new SupportingFile(
346-
"test/value-serializer.test.ts",
346+
"test/value-serializer.test.mustache",
347347
"test",
348348
"value-serializer.test.ts"));
349349
supportingFiles.add(
350350
new SupportingFile(
351-
"test/trace-context-util.test.ts",
351+
"test/trace-context-util.test.mustache",
352352
"test",
353353
"trace-context-util.test.ts"));
354354
supportingFiles.add(
@@ -358,17 +358,17 @@ public void processOpts() {
358358
"base-api.test.ts"));
359359
supportingFiles.add(
360360
new SupportingFile(
361-
"test/metadata.test.ts",
361+
"test/metadata.test.mustache",
362362
"test",
363363
"metadata.test.ts"));
364364
supportingFiles.add(
365365
new SupportingFile(
366-
"test/composed-schema.test.ts",
366+
"test/composed-schema.test.mustache",
367367
"test",
368368
"composed-schema.test.ts"));
369369
supportingFiles.add(
370370
new SupportingFile(
371-
"test/header-selector.test.ts",
371+
"test/header-selector.test.mustache",
372372
"test",
373373
"header-selector.test.ts"));
374374
supportingFiles.add(

src/main/resources/templates/csharp/makefile.mustache

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
.PHONY: build test format docs clean
1+
.PHONY: build test lint format analyze docs clean
22

33
build:
44
dotnet build
55

66
test:
77
dotnet test --verbosity normal
88

9+
lint:
10+
dotnet csharpier --check .
11+
912
format:
1013
dotnet csharpier .
1114

15+
analyze:
16+
dotnet build --no-restore /warnaserror
17+
1218
docs:
1319
dotnet build /p:DocumentationFile=docs/api.xml
1420

src/main/resources/templates/elixir/api/api.mustache

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
{{#appName}}
2-
# {{{.}}}
3-
{{/appName}}
4-
{{#appDescription}}
5-
# {{{.}}}
6-
{{/appDescription}}
7-
#
8-
# The version of the OpenAPI document: {{#version}}{{{.}}}{{/version}}
9-
#
10-
# Generated by: https://openapi-generator.tech
1+
{{>api_info}}
112

123
defmodule {{moduleName}}.Api do
134
@moduledoc """

src/main/resources/templates/elixir/api/options.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{{>api_info}}
2+
13
defmodule {{moduleName}}.Api.Options.{{className}} do
24
@moduledoc """
35
Options for the `{{operationId}}` operation.

src/main/resources/templates/elixir/api_client.mustache

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
{{#appName}}
2-
# {{{.}}}
3-
{{/appName}}
4-
{{#appDescription}}
5-
# {{{.}}}
6-
{{/appDescription}}
7-
#
8-
# The version of the OpenAPI document: {{#version}}{{{.}}}{{/version}}
9-
#
10-
# Generated by: https://openapi-generator.tech
1+
{{>api_info}}
112

123
defmodule {{moduleName}}.ApiClient do
134
@moduledoc """

src/main/resources/templates/elixir/api_error.mustache

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
{{#appName}}
2-
# {{{.}}}
3-
{{/appName}}
4-
{{#appDescription}}
5-
# {{{.}}}
6-
{{/appDescription}}
7-
#
8-
# The version of the OpenAPI document: {{#version}}{{{.}}}{{/version}}
9-
#
10-
# Generated by: https://openapi-generator.tech
1+
{{>api_info}}
112

123
defmodule {{moduleName}}.ApiError do
134
@moduledoc """
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{{#appName}}
2+
# {{{.}}}
3+
{{/appName}}
4+
{{#appDescription}}
5+
# {{{.}}}
6+
{{/appDescription}}
7+
#
8+
# The version of the OpenAPI document: {{#version}}{{{.}}}{{/version}}
9+
#
10+
# Generated by: https://openapi-generator.tech

src/main/resources/templates/elixir/api_response.mustache

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
{{#appName}}
2-
# {{{.}}}
3-
{{/appName}}
4-
{{#appDescription}}
5-
# {{{.}}}
6-
{{/appDescription}}
7-
#
8-
# The version of the OpenAPI document: {{#version}}{{{.}}}{{/version}}
9-
#
10-
# Generated by: https://openapi-generator.tech
1+
{{>api_info}}
112

123
defmodule {{moduleName}}.ApiResponse do
134
@moduledoc """

src/main/resources/templates/elixir/api_result.mustache

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
{{#appName}}
2-
# {{{.}}}
3-
{{/appName}}
4-
{{#appDescription}}
5-
# {{{.}}}
6-
{{/appDescription}}
7-
#
8-
# The version of the OpenAPI document: {{#version}}{{{.}}}{{/version}}
9-
#
10-
# Generated by: https://openapi-generator.tech
1+
{{>api_info}}
112

123
defmodule {{moduleName}}.ApiResult do
134
@moduledoc """

0 commit comments

Comments
 (0)