-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenAPI ServiceReference Tool (#12810)
Add ServiceReference tool
- Loading branch information
1 parent
1b20107
commit cfcffd8
Showing
53 changed files
with
3,657 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
{ | ||
"files.trimTrailingWhitespace": true, | ||
"files.associations": { | ||
"*.*proj": "xml", | ||
"*.props": "xml", | ||
"*.targets": "xml", | ||
"*.tasks": "xml" | ||
} | ||
"files.trimTrailingWhitespace": true, | ||
"files.associations": { | ||
"*.*proj": "xml", | ||
"*.props": "xml", | ||
"*.targets": "xml", | ||
"*.tasks": "xml" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Microsoft.dotnet-openapi | ||
|
||
`Microsoft.dotnet-openapi` is a tool for managing OpenAPI references within your project. | ||
|
||
## Commands | ||
|
||
### Add Commands | ||
|
||
<!-- TODO: Restore after https://github.com/aspnet/AspNetCore/issues/12738 | ||
#### Add Project | ||
##### Options | ||
| Short option | Long option | Description | Example | | ||
|-------|------|-------|---------| | ||
| -v|--verbose | Show verbose output. |dotnet openapi add project *-v* ../Ref/ProjRef.csproj | | ||
| -p|--project | The project to operate on. |dotnet openapi add project *--project .\Ref.csproj* ../Ref/ProjRef.csproj | | ||
##### Arguments | ||
| Argument | Description | Example | | ||
|-------------|-------------|---------| | ||
| source-file | The source to create a reference from. Must be a project file. |dotnet openapi add project *../Ref/ProjRef.csproj* | --> | ||
|
||
#### Add File | ||
|
||
##### Options | ||
|
||
| Short option| Long option| Description | Example | | ||
|-------|------|-------|---------| | ||
| -v|--verbose | Show verbose output. |dotnet openapi add file *-v* .\OpenAPI.json | | ||
| -p|--updateProject | The project to operate on. |dotnet openapi add file *--updateProject .\Ref.csproj* .\OpenAPI.json | | ||
|
||
##### Arguments | ||
|
||
| Argument | Description | Example | | ||
|-------------|-------------|---------| | ||
| source-file | The source to create a reference from. Must be an OpenAPI file. |dotnet openapi add file *.\OpenAPI.json* | | ||
|
||
#### Add URL | ||
|
||
##### Options | ||
|
||
| Short option| Long option| Description | Example | | ||
|-------|------|-------------|---------| | ||
| -v|--verbose | Show verbose output. |dotnet openapi add url *-v* <http://contoso.com/openapi.json> | | ||
| -p|--updateProject | The project to operate on. |dotnet openapi add url *--updateProject .\Ref.csproj* <http://contoso.com/openapi.json> | | ||
| -o|--output-file | Where to place the local copy of the OpenAPI file. |dotnet openapi add url <https://contoso.com/openapi.json> *--output-file myclient.json* | | ||
|
||
##### Arguments | ||
|
||
| Argument | Description | Example | | ||
|-------------|-------------|---------| | ||
| source-file | The source to create a reference from. Must be a URL. |dotnet openapi add url <https://contoso.com/openapi.json> | | ||
|
||
### Remove | ||
|
||
##### Options | ||
|
||
| Short option| Long option| Description| Example | | ||
|-------|------|------------|---------| | ||
| -v|--verbose | Show verbose output. |dotnet openapi remove *-v*| | ||
| -p|--updateProject | The project to operate on. |dotnet openapi remove *--updateProject .\Ref.csproj* .\OpenAPI.json | | ||
|
||
#### Arguments | ||
|
||
| Argument | Description| Example | | ||
| ------------|------------|---------| | ||
| source-file | The source to remove the reference to. |dotnet openapi remove *.\OpenAPI.json* | | ||
|
||
### Refresh | ||
|
||
#### Options | ||
|
||
| Short option| Long option| Description | Example | | ||
|-------|------|-------------|---------| | ||
| -v|--verbose | Show verbose output. | dotnet openapi refresh *-v* <https://contoso.com/openapi.json> | | ||
| -p|--updateProject | The project to operate on. | dotnet openapi refresh *--updateProject .\Ref.csproj* <https://contoso.com/openapi.json> | | ||
|
||
#### Arguments | ||
|
||
| Argument | Description | Example | | ||
| ------------|-------------|---------| | ||
| source-file | The URL to refresh the reference from. | dotnet openapi refresh *<https://contoso.com/openapi.json>* | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
using Microsoft.Build.Locator; | ||
using Microsoft.DotNet.Openapi.Tools; | ||
using Microsoft.DotNet.OpenApi.Commands; | ||
using Microsoft.Extensions.CommandLineUtils; | ||
|
||
namespace Microsoft.DotNet.OpenApi | ||
{ | ||
internal class Application : CommandLineApplication | ||
{ | ||
static Application() | ||
{ | ||
MSBuildLocator.RegisterDefaults(); | ||
} | ||
|
||
public Application( | ||
string workingDirectory, | ||
IHttpClientWrapper httpClient, | ||
TextWriter output = null, | ||
TextWriter error = null) | ||
{ | ||
Out = output ?? Out; | ||
Error = error ?? Error; | ||
|
||
WorkingDirectory = workingDirectory; | ||
|
||
Name = "openapi"; | ||
FullName = "OpenApi reference management tool"; | ||
Description = "OpenApi reference management operations."; | ||
ShortVersionGetter = GetInformationalVersion; | ||
|
||
Help = HelpOption("-?|-h|--help"); | ||
Help.Inherited = true; | ||
|
||
Invoke = () => | ||
{ | ||
ShowHelp(); | ||
return 0; | ||
}; | ||
|
||
Commands.Add(new AddCommand(this, httpClient)); | ||
Commands.Add(new RemoveCommand(this, httpClient)); | ||
Commands.Add(new RefreshCommand(this, httpClient)); | ||
} | ||
|
||
public string WorkingDirectory { get; } | ||
|
||
public CommandOption Help { get; } | ||
|
||
public new int Execute(params string[] args) | ||
{ | ||
try | ||
{ | ||
return base.Execute(args); | ||
} | ||
catch (AggregateException ex) when (ex.InnerException != null) | ||
{ | ||
foreach (var innerException in ex.InnerExceptions) | ||
{ | ||
Error.WriteLine(ex.InnerException.Message); | ||
} | ||
return 1; | ||
} | ||
|
||
catch (ArgumentException ex) | ||
{ | ||
// Don't show a call stack when we have unneeded arguments, just print the error message. | ||
// The code that throws this exception will print help, so no need to do it here. | ||
Error.WriteLine(ex.Message); | ||
return 1; | ||
} | ||
catch (CommandParsingException ex) | ||
{ | ||
// Don't show a call stack when we have unneeded arguments, just print the error message. | ||
// The code that throws this exception will print help, so no need to do it here. | ||
Error.WriteLine(ex.Message); | ||
return 1; | ||
} | ||
catch (OperationCanceledException) | ||
{ | ||
// This is a cancellation, not a failure. | ||
Error.WriteLine("Cancelled"); | ||
return 1; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Error.WriteLine(ex); | ||
return 1; | ||
} | ||
} | ||
|
||
private string GetInformationalVersion() | ||
{ | ||
var assembly = typeof(Application).GetTypeInfo().Assembly; | ||
var attribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>(); | ||
return attribute.InformationalVersion; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.DotNet.OpenApi | ||
{ | ||
public enum CodeGenerator | ||
{ | ||
NSwagCSharp, | ||
NSwagTypeScript | ||
} | ||
} |
Oops, something went wrong.