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

Update docs with new --tag and --match-path features #134

Merged
merged 15 commits into from
Aug 31, 2023
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
2 changes: 0 additions & 2 deletions .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ on:
jobs:

file:

strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -51,7 +50,6 @@ jobs:
command: 'dotnet run --project ../src/Refitter/Refitter.csproj'

url:

strategy:
fail-fast: false
matrix:
Expand Down
101 changes: 22 additions & 79 deletions .github/workflows/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ jobs:
runs-on: ${{ inputs.os }}
timeout-minutes: 10

strategy:
matrix:
args: [
"--cancellation-tokens",
"--internal",
"--use-api-response",
"--use-iso-date-format",
"--multiple-interfaces ByEndpoint",
"--match-path ^/pet/.*",
"--tag pet"
]

steps:
- name: 🛒 Checkout repository
uses: actions/checkout@v3
Expand All @@ -47,74 +59,15 @@ jobs:

- name: 🛠️ Generate code
run: |
$outputPath = "${{ inputs.openapi }}.cs"
$outputPath = $outputPath.Substring(0, 1).ToUpperInvariant() + $outputPath.Substring(1, $outputPath.Length - 1)
$namespace = "${{ inputs.openapi }}".Replace("-", "")
$namespace = $namespace.Substring(0, 1).ToUpperInvariant() + $namespace.Substring(1, $namespace.Length - 1)
${{ inputs.command }} ./openapi.${{ inputs.format }} --namespace $namespace --output $outputPath --no-logging
${{ inputs.command }} ./openapi.${{ inputs.format }} --namespace "$namespace.WithCancellation" --output "WithCancellation$outputPath" --cancellation-tokens --no-logging
${{ inputs.command }} ./openapi.${{ inputs.format }} --namespace "$namespace.Internal" --output "Internal$outputPath" --internal --no-logging
${{ inputs.command }} ./openapi.${{ inputs.format }} --namespace "$namespace.Interface" --output "I$outputPath" --interface-only --no-logging
${{ inputs.command }} ./openapi.${{ inputs.format }} --namespace "$namespace.UsingApiResponse" --output "IApi$outputPath" --interface-only --return-api-response --no-logging
${{ inputs.command }} ./openapi.${{ inputs.format }} --namespace "$namespace.UsingIsoDateFormat" --output "UsingIsoDateFormat$outputPath" --use-iso-date-format --no-logging
${{ inputs.command }} ./openapi.${{ inputs.format }} --namespace "$namespace.MultipleInterfaces" --output "MultipleInterfaces$outputPath" --multiple-interfaces byEndpoint --no-logging
Copy-Item $outputPath ./OpenAPI/${{ inputs.version }}/${{ inputs.openapi }}.${{ inputs.format }}.cs
Copy-Item $outputPath ./ConsoleApp/Net6/
Copy-Item $outputPath ./ConsoleApp/Net7/
Copy-Item $outputPath ./ConsoleApp/Net48/
Copy-Item $outputPath ./ConsoleApp/Net472/
Copy-Item $outputPath ./ConsoleApp/Net462/
Copy-Item $outputPath ./ConsoleApp/Net481/
Copy-Item $outputPath ./ConsoleApp/NetStandard20/
Copy-Item $outputPath ./ConsoleApp/NetStandard21/
Copy-Item "I$outputPath" ./ConsoleApp/Net6/
Copy-Item "I$outputPath" ./ConsoleApp/Net7/
Copy-Item "I$outputPath" ./ConsoleApp/Net48/
Copy-Item "I$outputPath" ./ConsoleApp/Net472/
Copy-Item "I$outputPath" ./ConsoleApp/Net462/
Copy-Item "I$outputPath" ./ConsoleApp/Net481/
Copy-Item "I$outputPath" ./ConsoleApp/NetStandard20/
Copy-Item "I$outputPath" ./ConsoleApp/NetStandard21/
Copy-Item "IApi$outputPath" ./ConsoleApp/Net6/
Copy-Item "IApi$outputPath" ./ConsoleApp/Net7/
Copy-Item "IApi$outputPath" ./ConsoleApp/Net48/
Copy-Item "IApi$outputPath" ./ConsoleApp/Net472/
Copy-Item "IApi$outputPath" ./ConsoleApp/Net462/
Copy-Item "IApi$outputPath" ./ConsoleApp/Net481/
Copy-Item "IApi$outputPath" ./ConsoleApp/NetStandard20/
Copy-Item "IApi$outputPath" ./ConsoleApp/NetStandard21/
Copy-Item "Internal$outputPath" ./ConsoleApp/Net6/
Copy-Item "Internal$outputPath" ./ConsoleApp/Net7/
Copy-Item "Internal$outputPath" ./ConsoleApp/Net48/
Copy-Item "Internal$outputPath" ./ConsoleApp/Net472/
Copy-Item "Internal$outputPath" ./ConsoleApp/Net462/
Copy-Item "Internal$outputPath" ./ConsoleApp/Net481/
Copy-Item "Internal$outputPath" ./ConsoleApp/NetStandard20/
Copy-Item "Internal$outputPath" ./ConsoleApp/NetStandard21/
Copy-Item "WithCancellation$outputPath" ./ConsoleApp/Net6/
Copy-Item "WithCancellation$outputPath" ./ConsoleApp/Net7/
Copy-Item "WithCancellation$outputPath" ./ConsoleApp/Net48/
Copy-Item "WithCancellation$outputPath" ./ConsoleApp/Net472/
Copy-Item "WithCancellation$outputPath" ./ConsoleApp/Net462/
Copy-Item "WithCancellation$outputPath" ./ConsoleApp/Net481/
Copy-Item "WithCancellation$outputPath" ./ConsoleApp/NetStandard20/
Copy-Item "WithCancellation$outputPath" ./ConsoleApp/NetStandard21/
Copy-Item "UsingIsoDateFormat$outputPath" ./ConsoleApp/Net6/
Copy-Item "UsingIsoDateFormat$outputPath" ./ConsoleApp/Net7/
Copy-Item "UsingIsoDateFormat$outputPath" ./ConsoleApp/Net48/
Copy-Item "UsingIsoDateFormat$outputPath" ./ConsoleApp/Net472/
Copy-Item "UsingIsoDateFormat$outputPath" ./ConsoleApp/Net462/
Copy-Item "UsingIsoDateFormat$outputPath" ./ConsoleApp/Net481/
Copy-Item "UsingIsoDateFormat$outputPath" ./ConsoleApp/NetStandard20/
Copy-Item "UsingIsoDateFormat$outputPath" ./ConsoleApp/NetStandard21/
Copy-Item "MultipleInterfaces$outputPath" ./ConsoleApp/Net6/
Copy-Item "MultipleInterfaces$outputPath" ./ConsoleApp/Net7/
Copy-Item "MultipleInterfaces$outputPath" ./ConsoleApp/Net48/
Copy-Item "MultipleInterfaces$outputPath" ./ConsoleApp/Net472/
Copy-Item "MultipleInterfaces$outputPath" ./ConsoleApp/Net462/
Copy-Item "MultipleInterfaces$outputPath" ./ConsoleApp/Net481/
Copy-Item "MultipleInterfaces$outputPath" ./ConsoleApp/NetStandard20/
Copy-Item "MultipleInterfaces$outputPath" ./ConsoleApp/NetStandard21/
${{ inputs.command }} ./openapi.${{ inputs.format }} --no-logging ${{ matrix.args }}
Copy-Item Output.cs ./ConsoleApp/Net6/
Copy-Item Output.cs ./ConsoleApp/Net7/
Copy-Item Output.cs ./ConsoleApp/Net48/
Copy-Item Output.cs ./ConsoleApp/Net472/
Copy-Item Output.cs ./ConsoleApp/Net462/
Copy-Item Output.cs ./ConsoleApp/Net481/
Copy-Item Output.cs ./ConsoleApp/NetStandard20/
Copy-Item Output.cs ./ConsoleApp/NetStandard21/
working-directory: test
shell: pwsh
if: steps.prepare_openapi_spec.outputs.exists == 'True'
Expand Down Expand Up @@ -164,14 +117,4 @@ jobs:
- 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
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
run: dotnet build ./MinimalApi/MinimalApi.csproj
working-directory: test
if: ${{ steps.prepare_openapi_spec.outputs.exists == 'True' && inputs.openapi == 'petstore' }}
if: steps.prepare_openapi_spec.outputs.exists == 'True'
41 changes: 26 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,31 @@ EXAMPLES:
refitter ./openapi.json --use-iso-date-format
refitter ./openapi.json --additional-namespace "Your.Additional.Namespace" --additional-namespace "Your.Other.Additional.Namespace"
refitter ./openapi.json --multiple-interfaces ByEndpoint
refitter ./openapi.json --tag Pet --tag Store --tag User
refitter ./openapi.json --match-path '^/pet/.*'

ARGUMENTS:
[URL or input file] URL or file path to OpenAPI Specification file

OPTIONS:
DEFAULT
-h, --help Prints help information
-s, --settings-file Path to .refitter settings file. Specifying this will ignore all other settings
-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
--no-accept-headers Don't add <Accept> 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
--additional-namespace Add additional namespace to generated types
DEFAULT
-h, --help Prints help information
-s, --settings-file Path to .refitter settings file. Specifying this will ignore all other settings
-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
--no-accept-headers Don't add <Accept> 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
--additional-namespace Add additional namespace to generated types
--use-iso-date-format Explicitly format date query string parameters in ISO 8601 standard date format using delimiters (2023-06-15)
--multiple-interfaces Generate a Refit interface for each endpoint. May be one of ByEndpoint, ByTag
--multiple-interfaces Generate a Refit interface for each endpoint. May be one of ByEndpoint, ByTag
--match-path Only include Paths that match the provided regular expression. May be set multiple times
--tag Only include Endpoints that contain this tag. May be set multiple times and result in OR'ed evaluation
```

To generate code from an OpenAPI specifications file, run the following:
Expand Down Expand Up @@ -127,6 +131,11 @@ The following is an example `.refitter` file
"additionalNamespaces": [ // Optional
"Namespace1",
"Namespace2"
],
"tag": [ // Optional. OpenAPI Tag to include when generating code
"Pet",
"Store",
"User"
]
}
```
Expand All @@ -146,6 +155,8 @@ The following is an example `.refitter` file
- `useIsoDateFormat` - Set to `true` to explicitly format date query string parameters in ISO 8601 standard date format using delimiters (for example: 2023-06-15). Default is `false`
- `multipleInterfaces` - Set to `ByEndpoint` to generate an interface for each endpoint, or `ByTag` to group Endpoints by their Tag (like SwaggerUI groups them).
- `additionalNamespaces` - A collection of additional namespaces to include in the generated file. A use case for this is when you want to reuse contracts from a different namespace than the generated code. Default is empty
- `tag` - A collection of tags to use a filter for including endpoints that contain this tag.
- `match-path` - A collection of regular expressions used to filter paths.


# Using the generated code
Expand Down
9 changes: 8 additions & 1 deletion src/Refitter.SourceGenerator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ The following is an example `.refitter` file
"additionalNamespaces": [ // Optional
"Namespace1",
"Namespace2"
],
"tag": [ // Optional. OpenAPI Tag to include when generating code
"Pet",
"Store",
"User"
]
}
```
Expand All @@ -63,4 +68,6 @@ The following is an example `.refitter` file
- `useCancellationTokens` - Use cancellation tokens in the generated methods. Default is `false`
- `useIsoDateFormat` - Set to `true` to explicitly format date query string parameters in ISO 8601 standard date format using delimiters (for example: 2023-06-15). Default is `false`
- `multipleInterfaces` - Set to `ByEndpoint` to generate an interface for each endpoint, or `ByTag` to group Endpoints by their Tag (like SwaggerUI groups them).
- `additionalNamespaces` - A collection of additional namespaces to include in the generated file. A use case for this is when you want to reuse contracts from a different namespace than the generated code. Default is empty
- `additionalNamespaces` - A collection of additional namespaces to include in the generated file. A use case for this is when you want to reuse contracts from a different namespace than the generated code. Default is empty
- `tag` - A collection of tags to use a filter for including endpoints that contain this tag.
- `match-path` - A collection of regular expressions used to filter paths.
16 changes: 16 additions & 0 deletions src/Refitter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ static int Main(string[] args)
"./openapi.json",
"--multiple-interfaces",
"ByEndpoint");

configuration
.AddExample(
"./openapi.json",
"--tag",
"Pet",
"--tag",
"Store",
"--tag",
"User");

configuration
.AddExample(
"./openapi.json",
"--match-path",
"'^/pet/.*'");
});

return app.Run(args);
Expand Down
Loading