Skip to content

Commit

Permalink
feat: Improve GetModelName
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkallesen committed Jun 25, 2024
1 parent 5b68212 commit b3716ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit b3716ce

Please sign in to comment.