Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve GetModelName #322

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Atc.OpenApi/Extensions/OpenApiSchemaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,13 @@ public static string GetModelName(this OpenApiSchema schema, bool ensureFirstCha

if (ensureFirstCharacterToUpper)
{
return schema.Items is null
? schema.Reference.Id.EnsureFirstCharacterToUpper()
: schema.Items.Reference.Id.EnsureFirstCharacterToUpper();
var dataType = schema.Items is null
? schema.Reference.Id
: schema.Items.Reference.Id;

return string.Equals(dataType, OpenApiDataTypeConstants.String, StringComparison.Ordinal)
? dataType
: dataType.PascalCase(ModelNameSeparators, removeSeparators: true);
}

return schema.Items is null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,11 @@ public static TheoryData<string, OpenApiSchema> GetModelNameItemData
{ "Pet", TestDataOpenApiFactory.CreateSchemaPet() },
{ string.Empty, TestDataOpenApiSchemaOfTypeFactory.CreateString() },
{ string.Empty, TestDataOpenApiSchemaOfTypeFactory.CreateListString() },
{ "HalloWorld", TestDataOpenApiFactory.CreateSchemaWithModelName("Hallo World") },
{ "HalloWorld", TestDataOpenApiFactory.CreateSchemaWithModelName("Hallo_World_") },
{ "HalloWorld", TestDataOpenApiFactory.CreateSchemaWithModelName("Hallo.World_") },
{ "HalloWorld", TestDataOpenApiFactory.CreateSchemaWithModelName("HalloWorld_") },
{ "HalloWorld", TestDataOpenApiFactory.CreateSchemaWithModelName("HalloWorld.") },
};

public static TheoryData<string, OpenApiSchema, bool> GetModelNameEnsureFirstCharacterToUpperItemData
Expand Down