Skip to content

Commit

Permalink
Merge pull request #84 from christianhelle/development
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhelle authored Jul 18, 2023
2 parents cd3a495 + 129f490 commit cd4d528
Show file tree
Hide file tree
Showing 24 changed files with 667 additions and 72 deletions.
28 changes: 21 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,28 @@ on:
branches:
- '*'

env:
VERSION: 0.6.3.${{ github.run_number }}

jobs:
build:
name: 👌 Verify build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build
run: dotnet build src/Refitter.sln
- name: Test
run: dotnet test --no-build src/Refitter.sln
- name: Package
run: dotnet pack src/Refitter.sln
- name: 🛒 Checkout repository
uses: actions/checkout@v2
- name: 🛠️ Build
run: dotnet build src/Refitter.sln -c Release -p:UseSourceLink=true -p:PackageVersion="${{ env.VERSION }}"
- name: 🧪 Test
run: dotnet test src/Refitter.sln --no-build --no-restore -c Release
- name: 🗳️ Package
run: dotnet pack src/Refitter.sln --no-build --no-restore -c Release --output .
- name: 🗳️ Publish
run: dotnet publish src/Refitter/Refitter.csproj --no-build --no-restore -c Release
- name: 🗳️ Upload
uses: actions/upload-artifact@v2
with:
name: CLI Tool
path: |
**/*.nupkg
README.md
16 changes: 15 additions & 1 deletion .github/workflows/production-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ jobs:
format: [json, yaml]
version: [V2, V3]
os: [macos-latest, windows-latest, ubuntu-latest]
openapi: ["callback-example", "link-example", "uber", "uspto", "petstore"]
openapi: [
"api-with-examples",
"callback-example",
"link-example",
"uber",
"uspto",
"petstore",
"petstore-expanded",
"petstore-minimal",
"petstore-simple",
"petstore-with-external-docs",
"ingram-micro",
"hubspot-events",
"hubspot-webhooks"
]
uses: ./.github/workflows/template.yml
with:
os: ${{ matrix.os }}
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ on:
- "release"

env:
VERSION: 0.6.2
VERSION: 0.6.3
NUGET_REPO_URL: "https://api.nuget.org/v3/index.json"

jobs:
CLI:
name: 🚚 Prepare new release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -25,9 +26,6 @@ jobs:
run: ((Get-Content -Path Refitter.Core.csproj -Raw) -Replace "1.0.0", "${{ env.VERSION }}") | Set-Content -Path Refitter.Core.csproj
working-directory: src/Refitter.Core/
shell: pwsh
- name: Remove badges from README.md
run: (Get-Content .\README.md | Select-Object -Skip 4) | Set-Content README.md
shell: pwsh
- name: Build
run: dotnet build -c Release /p:UseSourceLink=true src/Refitter.sln -p:PackageVersion="${{ env.VERSION }}"
- name: Pack
Expand Down
21 changes: 11 additions & 10 deletions .github/workflows/template-url.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ jobs:
timeout-minutes: 10

steps:
- uses: actions/checkout@v2
- name: 🛒 Checkout repository
uses: actions/checkout@v2

- name: Generate code
- name: 🛠️ Generate code
run: |
${{ inputs.command }} "${{ inputs.openapi }}" --namespace "Petstore" --output Output.cs --no-logging
${{ inputs.command }} "${{ inputs.openapi }}" --namespace "Petstore.Interface" --output IOutput.cs --interface-only --no-logging
Expand All @@ -44,34 +45,34 @@ jobs:
working-directory: test
shell: pwsh

- name: Build .NET 6 generated code
- name: 🛠️ Build .NET 6 generated code
run: dotnet build ./ConsoleApp/Net6/Net6.csproj
working-directory: test

- name: Build .NET 7 generated code
- name: 🛠️ Build .NET 7 generated code
run: dotnet build ./ConsoleApp/Net7/Net7.csproj
working-directory: test

- name: Build .NET 4.8.1 generated code
- name: 🛠️ Build .NET 4.8.1 generated code
run: dotnet build ./ConsoleApp/Net481/Net481.csproj
working-directory: test

- name: Build .NET 4.8 generated code
- name: 🛠️ Build .NET 4.8 generated code
run: dotnet build ./ConsoleApp/Net48/Net48.csproj
working-directory: test

- name: Build .NET 4.7.2 generated code
- name: 🛠️ Build .NET 4.7.2 generated code
run: dotnet build ./ConsoleApp/Net472/Net472.csproj
working-directory: test

- name: Build .NET 4.6.2 generated code
- name: 🛠️ Build .NET 4.6.2 generated code
run: dotnet build ./ConsoleApp/Net462/Net462.csproj
working-directory: test

- name: Build .NET Standard 2.0 generated code
- name: 🛠️ Build .NET Standard 2.0 generated code
run: dotnet build ./ConsoleApp/NetStandard20/NetStandard20.csproj
working-directory: test

- name: Build .NET Standard 2.1 generated code
- name: 🛠️ Build .NET Standard 2.1 generated code
run: dotnet build ./ConsoleApp/NetStandard21/NetStandard21.csproj
working-directory: test
29 changes: 15 additions & 14 deletions .github/workflows/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ jobs:
timeout-minutes: 10

steps:
- uses: actions/checkout@v2
- name: 🛒 Checkout repository
uses: actions/checkout@v2

- name: Prepare OpenAPI Spec
- name: 🛠️ Prepare OpenAPI Spec
id: prepare_openapi_spec
run: |
$filename = "./OpenAPI/${{ inputs.version }}/${{ inputs.openapi }}.${{ inputs.format }}"
Expand All @@ -44,7 +45,7 @@ jobs:
working-directory: test
shell: pwsh

- name: Generate code
- name: 🛠️ Generate code
run: |
$outputPath = "${{ inputs.openapi }}.cs"
$outputPath = $outputPath.Substring(0, 1).ToUpperInvariant() + $outputPath.Substring(1, $outputPath.Length - 1)
Expand Down Expand Up @@ -109,59 +110,59 @@ jobs:
shell: pwsh
if: steps.prepare_openapi_spec.outputs.exists == 'True'

- name: Publish generated code as Artifact
- name: 🛠️ Publish generated code as Artifact
uses: actions/upload-artifact@v2
with:
name: Generated Code (${{ inputs.openapi }}.${{ inputs.format }}, ${{ inputs.version }}, ${{ inputs.os }})
path: test/*.cs
if: steps.prepare_openapi_spec.outputs.exists == 'True'

- name: Build .NET 6 generated code
- name: 🛠️ Build .NET 6 generated code
run: dotnet build ./ConsoleApp/Net6/Net6.csproj
working-directory: test
if: steps.prepare_openapi_spec.outputs.exists == 'True'

- name: Build .NET 7 generated code
- name: 🛠️ Build .NET 7 generated code
run: dotnet build ./ConsoleApp/Net7/Net7.csproj
working-directory: test
if: steps.prepare_openapi_spec.outputs.exists == 'True'

- name: Build .NET 4.8.1 generated code
- name: 🛠️ Build .NET 4.8.1 generated code
run: dotnet build ./ConsoleApp/Net481/Net481.csproj
if: ${{ steps.prepare_openapi_spec.outputs.exists == 'True' && inputs.os == 'windows-2022' }}
working-directory: test

- name: Build .NET 4.8 generated code
- name: 🛠️ Build .NET 4.8 generated code
run: dotnet build ./ConsoleApp/Net48/Net48.csproj
working-directory: test
if: steps.prepare_openapi_spec.outputs.exists == 'True'

- name: Build .NET 4.7.2 generated code
- name: 🛠️ Build .NET 4.7.2 generated code
run: dotnet build ./ConsoleApp/Net472/Net472.csproj
working-directory: test
if: steps.prepare_openapi_spec.outputs.exists == 'True'

- name: Build .NET 4.6.2 generated code
- name: 🛠️ Build .NET 4.6.2 generated code
run: dotnet build ./ConsoleApp/Net462/Net462.csproj
working-directory: test
if: steps.prepare_openapi_spec.outputs.exists == 'True'

- name: Build .NET Standard 2.0 generated code
- name: 🛠️ Build .NET Standard 2.0 generated code
run: dotnet build ./ConsoleApp/NetStandard20/NetStandard20.csproj
working-directory: test
if: steps.prepare_openapi_spec.outputs.exists == 'True'

- name: Build .NET Standard 2.1 generated code
- name: 🛠️ Build .NET Standard 2.1 generated code
run: dotnet build ./ConsoleApp/NetStandard21/NetStandard21.csproj
working-directory: test
if: steps.prepare_openapi_spec.outputs.exists == 'True'

- name: Prepare Minimal API project
- name: ⚙️ Prepare Minimal API project
run: cp Petstore.cs ./MinimalApi/
working-directory: test
if: ${{ steps.prepare_openapi_spec.outputs.exists == 'True' && inputs.openapi == 'petstore' }}

- name: Build Minimal API generated code
- name: 🛠️ Build Minimal API generated code
run: dotnet build ./MinimalApi/MinimalApi.csproj
working-directory: test
if: ${{ steps.prepare_openapi_spec.outputs.exists == 'True' && inputs.openapi == 'petstore' }}
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,25 @@ EXAMPLES:
refitter ./openapi.json --cancellation-tokens
refitter ./openapi.json --no-operation-headers
refitter ./openapi.json --use-iso-date-format
refitter ./openapi.json --additional-namespace "Your.Additional.Namespace" --additional-namespace "Your.Other.Additional.Namespace"
ARGUMENTS:
[URL or input file] URL or file path to OpenAPI Specification file
OPTIONS:
DEFAULT
-h, --help Prints help information
-n, --namespace GeneratedCode Default namespace to use for generated types
-o, --output Output.cs Path to Output file
--no-auto-generated-header Don't add <auto-generated> header to output file
--interface-only Don't generate contract types
--use-api-response Return Task<IApiResponse<T>> instead of Task<T>
--internal Set the accessibility of the generated types to 'internal'
--cancellation-tokens Use cancellation tokens
--no-operation-headers Don't generate operation headers
--no-logging Don't log errors or collect telemetry
--use-iso-date-format Explicitly format date query string parameters in ISO 8601
standard date format using delimiters (2023-06-15)
DEFAULT
-h, --help Prints help information
-n, --namespace GeneratedCode Default namespace to use for generated types
-o, --output Output.cs Path to Output file
--no-auto-generated-header Don't add <auto-generated> header to output file
--interface-only Don't generate contract types
--use-api-response Return Task<IApiResponse<T>> instead of Task<T>
--internal Set the accessibility of the generated types to 'internal'
--cancellation-tokens Use cancellation tokens
--no-operation-headers Don't generate operation headers
--no-logging Don't log errors or collect telemetry
--use-iso-date-format Explicitly format date query string parameters in ISO 8601 standard date format using delimiters (2023-06-15)
--additional-namespace Add additional namespace to generated types
```

To generate code from an OpenAPI specifications file, run the following:
Expand Down
2 changes: 1 addition & 1 deletion src/Refitter.Core/CSharpClientGeneratorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Refitter.Core;

public class CSharpClientGeneratorFactory
internal class CSharpClientGeneratorFactory
{
private readonly RefitGeneratorSettings settings;
private readonly OpenApiDocument document;
Expand Down
6 changes: 3 additions & 3 deletions src/Refitter.Core/CustomCSharpClientGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Refitter.Core;

public class CustomCSharpClientGenerator : CSharpClientGenerator
internal class CustomCSharpClientGenerator : CSharpClientGenerator
{
public CustomCSharpClientGenerator(OpenApiDocument document, CSharpClientGeneratorSettings settings)
internal CustomCSharpClientGenerator(OpenApiDocument document, CSharpClientGeneratorSettings settings)
: base(document, settings)
{
}

public CSharpOperationModel CreateOperationModel(OpenApiOperation operation) =>
internal CSharpOperationModel CreateOperationModel(OpenApiOperation operation) =>
CreateOperationModel(operation, Settings);
}
2 changes: 1 addition & 1 deletion src/Refitter.Core/CustomCSharpPropertyNameGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Refitter.Core;

public class CustomCSharpPropertyNameGenerator : CSharpPropertyNameGenerator
internal class CustomCSharpPropertyNameGenerator : CSharpPropertyNameGenerator
{
public override string Generate(JsonSchemaProperty property) =>
string.IsNullOrWhiteSpace(property.Name) ? "_" : base.Generate(property);
Expand Down
2 changes: 1 addition & 1 deletion src/Refitter.Core/OperationNameGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Refitter.Core;

public class OperationNameGenerator : IOperationNameGenerator
internal class OperationNameGenerator : IOperationNameGenerator
{
private readonly IOperationNameGenerator defaultGenerator =
new MultipleClientsFromOperationIdOperationNameGenerator();
Expand Down
2 changes: 1 addition & 1 deletion src/Refitter.Core/ParameterExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Refitter.Core;

public static class ParameterExtractor
internal static class ParameterExtractor
{
public static IEnumerable<string> GetParameters(
CSharpOperationModel operationModel,
Expand Down
28 changes: 28 additions & 0 deletions src/Refitter.Core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
To use the `RefitGenerator` class, you need to follow these steps:

1. Install the `Refitter.Core` NuGet package in your project.
2. Create an instance of the `RefitGeneratorSettings` class, which contains the settings used to configure the generator. You need to set the `OpenApiPath` property to the path of your OpenAPI specification file or a URL.
3. Create an instance of the `RefitGenerator` class by calling the `CreateAsync` method and passing in the `RefitGeneratorSettings` instance.
4. Call the `Generate())` method on the `RefitGenerator` instance to generate the Refit clients and interfaces based on the OpenAPI specification. This method returns the generated code as a string.

Here's an example of how to use the `RefitGenerator` class:

```csharp
using Refit;
using Refitter.Core;

// Create an instance of the RefitGeneratorSettings class
var settings = new RefitGeneratorSettings
{
OpenApiPath = "Relative or absolute path to .json or .yaml local file or a URL to a .json or .yaml file"
};

// Create an instance of the RefitGenerator class
var generator = await RefitGenerator.CreateAsync(settings);

// Generate the Refit clients and interfaces and get the generated code as a string
var generatedCode = await generator.Generate();

// Use the generated code in your project
```

Loading

0 comments on commit cd4d528

Please sign in to comment.