Skip to content

Commit 28ae69d

Browse files
authored
[windows] Fixed missing output (#19715)
* fixed missing output * bug fix * add new sample * build samples again * delete sample * move the sample and add to github workflow * remove model not needed for this test * handle specs with no models
1 parent 6745340 commit 28ae69d

Some content is hidden

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

56 files changed

+4308
-8
lines changed

.github/workflows/openapi-generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ jobs:
142142
path: modules/openapi-generator-cli/target
143143
- name: Delete samples that are entirely generated
144144
run: |
145+
rm -rf samples/client/petstore/csharp/generichost/latest/Tags
146+
145147
rm -rf samples/client/petstore/csharp/generichost/net8/AllOf
146148
rm -rf samples/client/petstore/csharp/generichost/net8/AnyOf
147149
rm -rf samples/client/petstore/csharp/generichost/net8/AnyOfNoCompare

.github/workflows/samples-dotnet.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ name: Samples C# .Net 8 Clients
33
on:
44
push:
55
paths:
6+
- samples/client/petstore/csharp/generichost/latest/**
67
- samples/client/petstore/csharp/generichost/net8/**
78
- samples/client/petstore/csharp/httpclient/net8/**
89
- samples/client/petstore/csharp/restsharp/net8/**
910
- samples/client/petstore/csharp/unityWebRequest/net8/**
1011
pull_request:
1112
paths:
13+
- samples/client/petstore/csharp/generichost/latest/**
1214
- samples/client/petstore/csharp/generichost/net8/**
1315
- samples/client/petstore/csharp/httpclient/net8/**
1416
- samples/client/petstore/csharp/restsharp/net8/**
@@ -21,6 +23,7 @@ jobs:
2123
fail-fast: false
2224
matrix:
2325
sample:
26+
- samples/client/petstore/csharp/generichost/latest/Tags
2427
- samples/client/petstore/csharp/generichost/net8/AllOf
2528
- samples/client/petstore/csharp/generichost/net8/AnyOf
2629
- samples/client/petstore/csharp/generichost/net8/AnyOfNoCompare
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# for csharp generichost
2+
generatorName: csharp
3+
outputDir: samples/client/petstore/csharp/generichost/latest/Tags
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/tags.json
5+
library: generichost
6+
templateDir: modules/openapi-generator/src/main/resources/csharp
7+
additionalProperties:
8+
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
9+
modelPropertySorting: alphabetical
10+
operationParameterSorting: alphabetical

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ public String toRegularExpression(String pattern) {
14561456
}
14571457

14581458
/**
1459-
* Return the file name of the Api Test
1459+
* Return the file name of the Api
14601460
*
14611461
* @param name the file name of the Api
14621462
* @return the file name of the Api
@@ -5678,6 +5678,8 @@ protected void addHeaders(ApiResponse response, List<CodegenProperty> properties
56785678
}
56795679
}
56805680

5681+
private final Map<String, Integer> seenOperationIds = new HashMap<String, Integer>();
5682+
56815683
/**
56825684
* Add operation to group
56835685
*
@@ -5698,13 +5700,18 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
56985700
}
56995701
// check for operationId uniqueness
57005702
String uniqueName = co.operationId;
5701-
int counter = 0;
5703+
int counter = seenOperationIds.getOrDefault(uniqueName, 0);
5704+
while(seenOperationIds.containsKey(uniqueName)) {
5705+
uniqueName = co.operationId + "_" + counter;
5706+
counter++;
5707+
}
57025708
for (CodegenOperation op : opList) {
57035709
if (uniqueName.equals(op.operationId)) {
57045710
uniqueName = co.operationId + "_" + counter;
57055711
counter++;
57065712
}
57075713
}
5714+
seenOperationIds.put(co.operationId, counter);
57085715
if (!co.operationId.equals(uniqueName)) {
57095716
LOGGER.warn("generated unique operationId `{}`", uniqueName);
57105717
}
@@ -6080,30 +6087,68 @@ protected String removeNonNameElementToCamelCase(final String name, final String
60806087
return result;
60816088
}
60826089

6090+
/**
6091+
* Return a value that is unique, suffixed with _index to make it unique
6092+
* Ensures generated files are unique when compared case-insensitive
6093+
* Not all operating systems support case-sensitive paths
6094+
*/
6095+
private String uniqueCaseInsensitiveString(String value, Map<String, String> seenValues) {
6096+
if (seenValues.keySet().contains(value)) {
6097+
return seenValues.get(value);
6098+
}
6099+
6100+
Optional<Entry<String,String>> foundEntry = seenValues.entrySet().stream().filter(v -> v.getValue().toLowerCase(Locale.ROOT).equals(value.toLowerCase(Locale.ROOT))).findAny();
6101+
if (foundEntry.isPresent()) {
6102+
int counter = 0;
6103+
String uniqueValue = value + "_" + counter;
6104+
6105+
while (seenValues.values().stream().map(v -> v.toLowerCase(Locale.ROOT)).collect(Collectors.toList()).contains(uniqueValue.toLowerCase(Locale.ROOT))) {
6106+
counter++;
6107+
uniqueValue = value + "_" + counter;
6108+
}
6109+
6110+
seenValues.put(value, uniqueValue);
6111+
return uniqueValue;
6112+
}
6113+
6114+
seenValues.put(value, value);
6115+
return value;
6116+
}
6117+
6118+
private final Map<String, String> seenApiFilenames = new HashMap<String, String>();
6119+
60836120
@Override
60846121
public String apiFilename(String templateName, String tag) {
6122+
String uniqueTag = uniqueCaseInsensitiveString(tag, seenApiFilenames);
60856123
String suffix = apiTemplateFiles().get(templateName);
6086-
return apiFileFolder() + File.separator + toApiFilename(tag) + suffix;
6124+
return apiFileFolder() + File.separator + toApiFilename(uniqueTag) + suffix;
60876125
}
60886126

60896127
@Override
60906128
public String apiFilename(String templateName, String tag, String outputDir) {
6129+
String uniqueTag = uniqueCaseInsensitiveString(tag, seenApiFilenames);
60916130
String suffix = apiTemplateFiles().get(templateName);
6092-
return outputDir + File.separator + toApiFilename(tag) + suffix;
6131+
return outputDir + File.separator + toApiFilename(uniqueTag) + suffix;
60936132
}
60946133

6134+
private final Map<String, String> seenModelFilenames = new HashMap<String, String>();
6135+
60956136
@Override
60966137
public String modelFilename(String templateName, String modelName) {
6138+
String uniqueModelName = uniqueCaseInsensitiveString(modelName, seenModelFilenames);
60976139
String suffix = modelTemplateFiles().get(templateName);
6098-
return modelFileFolder() + File.separator + toModelFilename(modelName) + suffix;
6140+
return modelFileFolder() + File.separator + toModelFilename(uniqueModelName) + suffix;
60996141
}
61006142

61016143
@Override
61026144
public String modelFilename(String templateName, String modelName, String outputDir) {
6145+
String uniqueModelName = uniqueCaseInsensitiveString(modelName, seenModelFilenames);
61036146
String suffix = modelTemplateFiles().get(templateName);
6104-
return outputDir + File.separator + toModelFilename(modelName) + suffix;
6147+
return outputDir + File.separator + toModelFilename(uniqueModelName) + suffix;
61056148
}
61066149

6150+
private final Map<String, String> seenApiDocFilenames = new HashMap<String, String>();
6151+
61076152
/**
61086153
* Return the full path and API documentation file
61096154
*
@@ -6113,11 +6158,14 @@ public String modelFilename(String templateName, String modelName, String output
61136158
*/
61146159
@Override
61156160
public String apiDocFilename(String templateName, String tag) {
6161+
String uniqueTag = uniqueCaseInsensitiveString(tag, seenApiDocFilenames);
61166162
String docExtension = getDocExtension();
61176163
String suffix = docExtension != null ? docExtension : apiDocTemplateFiles().get(templateName);
6118-
return apiDocFileFolder() + File.separator + toApiDocFilename(tag) + suffix;
6164+
return apiDocFileFolder() + File.separator + toApiDocFilename(uniqueTag) + suffix;
61196165
}
61206166

6167+
private final Map<String, String> seenApiTestFilenames = new HashMap<String, String>();
6168+
61216169
/**
61226170
* Return the full path and API test file
61236171
*
@@ -6127,8 +6175,9 @@ public String apiDocFilename(String templateName, String tag) {
61276175
*/
61286176
@Override
61296177
public String apiTestFilename(String templateName, String tag) {
6178+
String uniqueTag = uniqueCaseInsensitiveString(tag, seenApiTestFilenames);
61306179
String suffix = apiTestTemplateFiles().get(templateName);
6131-
return apiTestFileFolder() + File.separator + toApiTestFilename(tag) + suffix;
6180+
return apiTestFileFolder() + File.separator + toApiTestFilename(uniqueTag) + suffix;
61326181
}
61336182

61346183
@Override

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,8 @@ protected File processTemplateToFile(Map<String, Object> templateData, String te
14411441
return processTemplateToFile(templateData, templateName, outputFilename, shouldGenerate, skippedByOption, this.config.getOutputDir());
14421442
}
14431443

1444+
private final Set<String> seenFiles = new HashSet<>();
1445+
14441446
private File processTemplateToFile(Map<String, Object> templateData, String templateName, String outputFilename, boolean shouldGenerate, String skippedByOption, String intendedOutputDir) throws IOException {
14451447
String adjustedOutputFilename = outputFilename.replaceAll("//", "/").replace('/', File.separatorChar);
14461448
File target = new File(adjustedOutputFilename);
@@ -1451,6 +1453,11 @@ private File processTemplateToFile(Map<String, Object> templateData, String temp
14511453
if (!absoluteTarget.startsWith(outDir)) {
14521454
throw new RuntimeException(String.format(Locale.ROOT, "Target files must be generated within the output directory; absoluteTarget=%s outDir=%s", absoluteTarget, outDir));
14531455
}
1456+
1457+
if (seenFiles.stream().filter(f -> f.toLowerCase(Locale.ROOT).equals(absoluteTarget.toString().toLowerCase(Locale.ROOT))).findAny().isPresent()) {
1458+
LOGGER.warn("Duplicate file path detected. Not all operating systems can handle case sensitive file paths. path={}", absoluteTarget.toString());
1459+
}
1460+
seenFiles.add(absoluteTarget.toString());
14541461
return this.templateProcessor.write(templateData, templateName, target);
14551462
} else {
14561463
this.templateProcessor.skip(target.toPath(), String.format(Locale.ROOT, "Skipped by %s options supplied by user.", skippedByOption));

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ClientUtils.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ using System.Text;
1212
using System.Text.Json;
1313
using System.Text.RegularExpressions;{{#useCompareNetObjects}}
1414
using KellermanSoftware.CompareNetObjects;{{/useCompareNetObjects}}
15+
{{#models}}
16+
{{#-first}}
1517
using {{packageName}}.{{modelPackage}};
18+
{{/-first}}
19+
{{/models}}
1620
using System.Runtime.CompilerServices;
1721

1822
{{>Assembly}}namespace {{packageName}}.{{clientPackage}}

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/HostConfiguration.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ using System.Text.Json.Serialization;
1111
using System.Net.Http;
1212
using Microsoft.Extensions.DependencyInjection;
1313
using {{packageName}}.{{apiPackage}};
14+
{{#models}}
15+
{{#-first}}
1416
using {{packageName}}.{{modelPackage}};
17+
{{/-first}}
18+
{{/models}}
1519

1620
namespace {{packageName}}.{{clientPackage}}
1721
{
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"info": {
3+
"title": "Files.com API",
4+
"contact": {
5+
"name": "Files.com Customer Success Team",
6+
"email": "support@files.com"
7+
},
8+
"version": "0.0.1"
9+
},
10+
"swagger": "2.0",
11+
"produces": [
12+
"application/json",
13+
"application/msgpack",
14+
"application/xml"
15+
],
16+
"securityDefinitions": {
17+
"api_key": {
18+
"type": "apiKey",
19+
"description": "API Key - supports user-based or site-wide API keys",
20+
"name": "XFilesAPIKey",
21+
"in": "header"
22+
}
23+
},
24+
"host": "app.files.com",
25+
"basePath": "/api/rest/v1",
26+
"tags": [
27+
{
28+
"name": "api_key",
29+
"description": "Operations about api_keys"
30+
},
31+
{
32+
"name": "API Keys",
33+
"description": "Operations about API Keys"
34+
},
35+
{
36+
"name": "a_p_i_k_e_y_s",
37+
"description": "Operations about API keys"
38+
}
39+
],
40+
"paths": {
41+
"/api_keys/{id}": {
42+
"get": {
43+
"summary": "Show API Key",
44+
"description": "Show API Key",
45+
"produces": [
46+
"application/json"
47+
],
48+
"parameters": [
49+
{
50+
"in": "path",
51+
"name": "id",
52+
"description": "Api Key ID.",
53+
"type": "integer",
54+
"format": "int32",
55+
"required": true,
56+
"x-ms-summary": "Api Key ID."
57+
}
58+
],
59+
"responses": {
60+
"400": {
61+
"description": "Bad Request",
62+
"x-ms-summary": "Bad Request"
63+
}
64+
},
65+
"tags": [
66+
"api_keys",
67+
"API Keys",
68+
"a_p_i_k_e_y_s"
69+
],
70+
"operationId": "GetApiKeysId",
71+
"x-authentication": [
72+
"self_managed"
73+
],
74+
"x-category": [
75+
"developers"
76+
]
77+
}
78+
}
79+
}
80+
,
81+
"definitions": {}
82+
}

0 commit comments

Comments
 (0)