Skip to content

Commit 4393e09

Browse files
authored
Merge pull request #144 from Microsoft/dm/housekeeping
Updates to the Readme along with examples
2 parents 6bcc4bc + 479e6c7 commit 4393e09

File tree

2 files changed

+88
-8
lines changed

2 files changed

+88
-8
lines changed

README.md

+72-6
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,87 @@
33
# OpenAPI.NET [Preview]
44
[ Disclaimer: This repository is in a preview state. Expect to see some iterating as we work towards the final release candidate slated for early 2018. Feedback is welcome! ]
55

6-
The **OpenAPI.NET** SDK contains a useful object model for OpenAPI documents in .NET along with common serializers to extract raw OAI JSON and YAML documents from the model.
6+
The **OpenAPI.NET** SDK contains a useful object model for OpenAPI documents in .NET along with common serializers to extract raw OpenAPI JSON and YAML documents from the model.
77

8-
**See more information on the Open API spec and its history here: <a href="https://www.openapis.org">Open API Initiative</a>**
8+
**See more information on the OpenAPI spec and its history here: <a href="https://www.openapis.org">Open API Initiative</a>**
99

1010
Project Objectives
1111

12-
- Provide a single shared object model in .NET for Open API documents.
13-
- Include the most primitive Reader for ingesting OAI JSON and YAML documents.
14-
- Enable developers to create Readers that translate different data formats into Open API documents.
12+
- Provide a single shared object model in .NET for OpenAPI descriptions.
13+
- Include the most primitive Reader for ingesting OpenAPI JSON and YAML documents in both V2 and V3 formats.
14+
- Provide OpenAPI description writers for both V2 and V3 specification formats.
15+
- Enable developers to create Readers that translate different data formats into OpenAPI descriptions.
1516

1617
# Readers
17-
The OpenAPI.NET project holds the base object model for representing OAI documents as .NET objects. Translation for different data types into this object model is handled by reading raw JSON/YAML or from individual "Readers", a number of which are in the works.
18+
The OpenAPI.NET project holds the base object model for representing OpenAPI descriptions as .NET objects. Translation for different data types into this object model is handled by reading raw JSON/YAML or from individual "Readers", a number of which are in the works.
1819

1920
The base JSON and YAML Readers are built into this project. Below is the list of supported "reader" projects.
2021

2122
- .NET Comment Reader: [Coming Soon]
2223

24+
# Example Usage
25+
26+
Creating an OpenAPI Document
27+
28+
```C#
29+
var document = new OpenApiDocument
30+
{
31+
Info = new OpenApiInfo
32+
{
33+
Version = "1.0.0",
34+
Title = "Swagger Petstore (Simple)",
35+
},
36+
Servers = new List<OpenApiServer>
37+
{
38+
new OpenApiServer { Url = "http://petstore.swagger.io/api" }
39+
},
40+
Paths = new OpenApiPaths
41+
{
42+
["/pets"] = new OpenApiPathItem
43+
{
44+
Operations = new Dictionary<OperationType, OpenApiOperation>
45+
{
46+
[OperationType.Get] = new OpenApiOperation
47+
{
48+
Description = "Returns all pets from the system that the user has access to",
49+
Responses = new OpenApiResponses
50+
{
51+
["200"] = new OpenApiResponse
52+
{
53+
Description = "OK"
54+
}
55+
}
56+
}
57+
}
58+
}
59+
}
60+
};
61+
```
62+
63+
Reading and writing a OpenAPI description
64+
65+
```C#
66+
var httpClient = new HttpClient
67+
{
68+
BaseAddress = new Uri("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/")
69+
};
70+
71+
var stream = await httpClient.GetStreamAsync("master/examples/v3.0/petstore.yaml");
72+
73+
// Read V3 as YAML
74+
var openApiDocument = new OpenApiStreamReader().Read(stream, out var diagnostic);
75+
76+
var outputStringWriter = new StringWriter();
77+
var writer = new OpenApiJsonWriter(outputStringWriter);
78+
79+
// Write V2 as JSON
80+
openApiDocument.SerializeAsV2(writer);
81+
82+
outputStringWriter.Flush();
83+
var output = outputStringWriter.GetStringBuilder().ToString();
84+
85+
```
86+
2387
# Build Status
2488

2589
|**master**|
@@ -39,3 +103,5 @@ provided by the bot. You will only need to do this once across all repos using o
39103
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
40104
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
41105
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
106+
107+
To provide feedback and ask questions you can use StackOverflow with the [OpenApi.net](https://stackoverflow.com/questions/tagged/openapi.net) tag or use the OpenApi.net Slack channel which you can join by registering for the httpapis team at http://slack.httpapis.com

build.cmd

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1-
SET VERSION=0.9.1
1+
@echo off
2+
if "%~1"=="" goto :error
3+
4+
SET %VERSION%=%~1
5+
6+
Echo Building Microsoft.OpenApi
7+
28
SET PROJ=%~dp0src\Microsoft.OpenApi\Microsoft.OpenApi.csproj
39
msbuild %PROJ% /t:restore /p:Configuration=Release
410
msbuild %PROJ% /t:build /p:Configuration=Release
511
msbuild %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts;Version=%VERSION%
612

13+
Echo Building Microsoft.OpenApi.Readers
14+
715
SET PROJ=%~dp0src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj
816
msbuild %PROJ% /t:restore /p:Configuration=Release
917
msbuild %PROJ% /t:build /p:Configuration=Release
10-
msbuild %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts;Version=%VERSION%
18+
msbuild %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts;Version=%VERSION%
19+
20+
goto :end
21+
:error
22+
echo Version parameter missing e.g. build.cmd 1.0.0-beta0008
23+
24+
:end

0 commit comments

Comments
 (0)