Skip to content

Commit

Permalink
Merge pull request #3939 from andreaTP/issue-3824
Browse files Browse the repository at this point in the history
[Java] Fix generation of models with underscores
  • Loading branch information
baywet authored Dec 20, 2023
2 parents 7a5c7dd + 0dae240 commit d08a287
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed a bug where the discriminator validation rule would report false positives on nullable union types.
- Fixed a bug where constructors and model names where clashing in Go. [#3920](https://github.com/microsoft/kiota/issues/3920)
- Fixed a bug where the order of enum declaration might results in a missing enum type. [#3935](https://github.com/microsoft/kiota/issues/3935)
- Fixed java generating compound types with underscore in the name. [#3824](https://github.com/microsoft/kiota/issues/3824)

## [1.9.1] - 2023-12-13

Expand Down
14 changes: 7 additions & 7 deletions src/Kiota.Builder/Refiners/JavaRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance
IsExternal = true
}
});
ConvertUnionTypesToWrapper(generatedCode,
_configuration.UsesBackingStore,
s => s.ToFirstCharacterLowerCase(),
true,
SerializationNamespaceName,
"ComposedTypeWrapper"
);
var reservedNamesProvider = new JavaReservedNamesProvider();
CorrectNames(generatedCode, s =>
{
Expand All @@ -58,13 +65,6 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance
GenerationLanguage.Java);
cancellationToken.ThrowIfCancellationRequested();
RemoveCancellationParameter(generatedCode);
ConvertUnionTypesToWrapper(generatedCode,
_configuration.UsesBackingStore,
s => s.ToFirstCharacterLowerCase(),
true,
SerializationNamespaceName,
"ComposedTypeWrapper"
);
CorrectCoreType(generatedCode, CorrectMethodType, CorrectPropertyType, CorrectImplements);
cancellationToken.ThrowIfCancellationRequested();
ReplaceBinaryByNativeType(generatedCode, "InputStream", "java.io", true, true);
Expand Down
8 changes: 4 additions & 4 deletions src/Kiota.Builder/Refiners/RubyRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance
var suffix = "Model";
DisambiguateClassesWithNamespaceNames(generatedCode, classesToDisambiguate, suffix);
UpdateReferencesToDisambiguatedClasses(generatedCode, classesToDisambiguate, suffix);
ConvertUnionTypesToWrapper(generatedCode,
_configuration.UsesBackingStore,
static s => s
);
var reservedNamesProvider = new RubyReservedNamesProvider();
CorrectNames(generatedCode, s =>
{
Expand All @@ -55,10 +59,6 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance
FlattenModelsNamespaces(modelsNS, modelsNS);
AddPropertiesAndMethodTypesImports(generatedCode, false, false, true);
RemoveCancellationParameter(generatedCode);
ConvertUnionTypesToWrapper(generatedCode,
_configuration.UsesBackingStore,
static s => s
);
cancellationToken.ThrowIfCancellationRequested();
AddParsableImplementsForModelClasses(generatedCode, "MicrosoftKiotaAbstractions::Parsable");
AddDefaultImports(generatedCode, defaultUsingEvaluators);
Expand Down
7 changes: 7 additions & 0 deletions tests/Kiota.Builder.IntegrationTests/GenerateSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ public async Task GeneratesIdiomaticChildrenNames(GenerationLanguage language)
};
await new KiotaBuilder(logger, configuration, _httpClient).GenerateClientAsync(new());

var fullText = "";
foreach (var file in Directory.GetFiles(OutputPath, "*.*", SearchOption.AllDirectories))
{
fullText += File.ReadAllText(file);
}

Assert.Empty(Directory.GetFiles(OutputPath, "*_*", SearchOption.AllDirectories));
Assert.DoesNotContain("_", fullText);
}
[InlineData(GenerationLanguage.CSharp)]
[InlineData(GenerationLanguage.Go)]
Expand Down
52 changes: 52 additions & 0 deletions tests/Kiota.Builder.IntegrationTests/NoUnderscoresInModel.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
openapi: 3.0.0
servers:
- url: https://localhost
info:
title: Test
version: 1.0.0
description: something
contact:
name: Microsoft
tags:
- name: metrics
description: "The metrics API"
- name: permissions
description: "The permissions API"
- name: image
description: "The image API"
paths:
/api/metrics/v1:
get:
operationId: getMetrics
tags:
- "metrics"
responses:
"200":
content:
Expand All @@ -16,6 +30,9 @@ paths:
description: Returns a test list
/api/permissions/v1:
get:
operationId: getPermissions
tags:
- "permissions"
responses:
"200":
content:
Expand All @@ -24,6 +41,25 @@ paths:
$ref: "#/components/schemas/app-permissions"
description: Test
description: Returns a app permissions
/api/image/v1:
post:
operationId: createImage
tags:
- "image"
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/CreateImageRequest"
responses:
"200":
content:
application/json:
schema:
$ref: "#/components/schemas/Value"
description: Test
description: Returns a create image request
components:
schemas:
app-permissions:
Expand Down Expand Up @@ -58,3 +94,19 @@ components:
type: array
items:
type: string
CreateImageRequest:
type: object
properties:
prompt:
description: A text description of the desired image(s). The maximum length is 1000 characters for `dall-e-2` and 4000 characters for `dall-e-3`.
type: string
example: "A cute baby sea otter"
model:
anyOf:
- type: string
- type: string
enum: ["dall-e-2", "dall-e-3"]
x-oaiTypeLabel: string
example: "dall-e-3"
nullable: true
description: The model to use for image generation.

0 comments on commit d08a287

Please sign in to comment.