* Updating docs

* fixed line space

* fixed anchor

* Update workstation.md

* Update generating-a-client.md

* Update compiling-autorest.md

* Update compiling-autorest.md
This commit is contained in:
Garrett Serack 2017-02-24 14:37:51 -08:00 коммит произвёл GitHub
Родитель 4db58a2424
Коммит 915de4eaa3
8 изменённых файлов: 415 добавлений и 112 удалений

158
README.md
Просмотреть файл

@ -1,134 +1,68 @@
[![Repo Status](http://img.shields.io/travis/Azure/autorest/dev.svg?style=flat-square&label=build)](https://travis-ci.org/Azure/autorest) [![Issue Stats](http://issuestats.com/github/Azure/autorest/badge/pr?style=flat-square)](http://issuestats.com/github/Azure/autorest) [![Issue Stats](http://issuestats.com/github/Azure/autorest/badge/issue?style=flat-square)](http://issuestats.com/github/Azure/autorest)
# <img align="center" src="https://raw.githubusercontent.com/Azure/autorest/master/docs/images/autorest-small-flat.png"> AutoRest
# <img align="center" src="./docs/images/logo.png"> AutoRest
The **AutoRest** tool generates client libraries for accessing RESTful web services. Input to *AutoRest* is a spec that describes the REST API using the [Open API Initiative](https://github.com/OAI/OpenAPI-Specification) format.
##Getting AutoRest
The AutoRest tools can be installed with Nuget for use in a Visual Studio project:
[![AutoRest NuGet](https://img.shields.io/nuget/v/autorest.svg?style=flat-square)](https://www.nuget.org/packages/autorest/)
[![Repo Status](http://img.shields.io/travis/Azure/autorest/dev.svg?style=flat-square&label=build)](https://travis-ci.org/Azure/autorest) [![Issue Stats](http://issuestats.com/github/Azure/autorest/badge/pr?style=flat-square)](http://issuestats.com/github/Azure/autorest) [![Issue Stats](http://issuestats.com/github/Azure/autorest/badge/issue?style=flat-square)](http://issuestats.com/github/Azure/autorest)
Alternatively it can be installed from [Chocolatey](https://chocolatey.org/) by running:
[![AutoRest Chocolatey](https://img.shields.io/chocolatey/v/autorest.svg?style=flat-square)](https://chocolatey.org/packages/AutoRest)
# What's New (02/24/2017)
choco install autorest
Nightlies are available via MyGet:
[![AutoRest MyGet](https://img.shields.io/myget/autorest/vpre/autorest.svg?style=flat-square)](https://www.myget.org/gallery/autorest)
AutoRest has been thru a lot of changes recently, most notably:
- we've switched to building the core components with the latest [dotnet-cli](https://github.com/dotnet/cli) tools, and the binaries are build for .NET Core 1.0 (aka 'CoreCLR')
- we're starting to build some of the components in NodeJS - this allows us to leverage all sorts of other great functionality with less coding effort
- we have a great cross-platform installation model for Windows, Mac OSX and Linux, which is built on top of NodeJS's `npm` package manager
AutoRest can be run on macOS and *nix using [Mono](http://www.mono-project.com/download):
> #### Why did you change that?
> Previously, in order to get AutoRest, you had to either get an older version from Chocolatey, or install a 'nightly' build from the MyGet feed using the NuGet tool.
> This didn't make it easier to keep up-to-date with AutoRest (as development happens pretty fast these days!), and often bugs were getting fixed and it was a pain for users to get the updated binaries.
>
> Now, you can "install" AutoRest just once, and AutoRest itself has the ability to download and install any updates, as well as allowing the user to choose any arbitrary build at runtime, and it will use the requested verion.
>
> This will let you install a 'release' version of AutoRest, and use that, but if you want to test a new nightly or preview version, you can just ask for it on the command line.
>
> Additionally, we're making AutoRest work in multiple environments, (including a upcoming [Visual Studio Code](https://code.visualstudio.com/) extension), and using this model, AutoRest will give exactly the same results from the command line as in the IDE, without having to manually fight to switch versions when you want.
# Download & Unpack Autorest
curl -LO https://github.com/Azure/autorest/releases/download/AutoRest-0.16.0/autorest.0.16.0.zip && \
unzip autorest.0.16.0.zip -d autorest/ && \
cd autorest && \
# Download Swagger.json example
curl -O https://raw.githubusercontent.com/Azure/autorest/master/Samples/petstore/petstore.json && \
# Installing Autorest
# Run AutoRest using mono
mono AutoRest.exe \
-CodeGenerator CSharp \
-Input petstore.json \
-OutputDirectory CSharp_PetStore -Namespace PetStore
Installing AutoRest on Windows, MacOS or Linux involves two steps:
Or [Docker](https://docs.docker.com/engine/installation):
1. __Install [Node.js](https://nodejs.org/en/)__ (6.9.5 or greater)
> for more help, check out [Installing Node.JS on different platforms](./docs/developer/workstation.md#nodejs)
# Download Swagger.json example
`curl -O https://raw.githubusercontent.com/Azure/autorest/master/Samples/petstore/petstore.json`
2. __Install AutoRest__ using `npm`
# Download latest AutoRest Docker image
`docker pull azuresdk/autorest:latest`
``` powershell
# Depending on your configuration you may need to be elevated or root to run this. (on OSX/Linux use 'sudo' )
npm install -g autorest
```
# Run AutoRest using Docker, mounting the current folder (pwd) into /home inside the container
`docker run -it --rm -v $(pwd):/home azuresdk/autorest:latest autorest \
-CodeGenerator CSharp \
-Input /home/petstore.json \
-OutputDirectory /home/CSharp_PetStore -Namespace PetStore`
### _Coming Soon_
A downloadable Installer EXE for Windows that automates both steps should be available shortly.
## Building AutoRest
AutoRest is developed primarily in C# but generates code for multiple languages. See [this link](docs/developer/guide/building-code.md) to build and test AutoRest.
# Getting Started using AutoRest ![image](./docs/images/normal.png)
> Hint: There is a powershell script (`verify-settings.ps1`) in the `Tools` folder that can verify that you have the required compilers/tools/libraries installed on your development system before trying to build.
Start by reading the documentation for using AutoRest:
- [Managing Autorest](./docs/managing-autorest.md) - shows how to get new updates to AutoRest and choose which version to use for code generation
- [Generating a Client using AutoRest](./docs/generating-a-client.md) - shows simple command line usage for generating a client library.
## Hello World
For this version of Hello World, we will use **AutoRest** to generate a client library and use it to call a web service. The trivial web service that just returns a string is defined as follows:
```C#
public class HelloWorldController : ApiController
{
// GET: api/HelloWorld
public string Get()
{
return "Hello via AutoRest.";
}
}
```
By convention, Swagger documents are exposed by web services with the name `swagger.json`. The `title` property of the `info` object is used by **AutoRest** as the name of the client object in the generated library. The `host` + `path` of the operation corresponds to the URL of the operation endpoint. The `operationId` is used as the method name. The spec declares that a `GET` request will return an HTTP 200 status code with content of mime-type `application/json` and the body will be a string. For a more in-depth overview of swagger processing, refer to [Defining Clients With Swagger](docs/developer/guide/defining-clients-swagger.md) section of the [documentation](docs).
# Developers ![image](./docs/images/glasses.png)
```json
{
"swagger": "2.0",
"info": {
"title": "MyClient",
"version": "1.0.0"
},
"host": "swaggersample.azurewebsites.net",
"paths": {
"/api/HelloWorld": {
"get": {
"operationId": "GetGreeting",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "GETs a greeting.",
"schema": {
"type": "string"
}
}
}
}
}
}
}
```
Next, we invoke **AutoRest.exe** with this swagger document to generate client library code (see [Command Line Interface documentation](docs/user/cli.md) for details).
Get yourself up and coding in AutoRest
**AutoRest** is extensible and can support multiple types of input and output. *AutoRest.exe* comes with a configuration file that defines the available inputs (*Modelers*) and outputs (*CodeGenerators*). When invoking *AutoRest.exe*, if you don't specify the `-Modeler` then Swagger is assumed and if you don't specify `-CodeGenerator` then CSharp is used.
- [Developer Workstation Requirements](./docs/developer/workstation.md) - what do you need to install to start working with the AutoRest code
- [Compiling AutoRest](./docs/developer/compiling-autorest.md) - compiling/testing AutoRest using the build scripts
The Swagger schema is language agnostic and doesn't include the notion of namespace, but for generating code, AutoRest requires `-Namespace` be specified. By default, the CodeGenerator will place output in a directory named *Generated*. This can be overridden by providing the `-OutputDirectory` parameter.
```
AutoRest.exe -CodeGenerator CSharp -Modeler Swagger -Input swagger.json -Namespace MyNamespace
```
Now, we will use the generated code to call the web service.
Create a console application called *HelloWorld*. Add the generated files to it. They won't compile until you add the NuGet package the generated code depends on: `Microsoft.Rest.ClientRuntime`.
You can add it to the Visual Studio project using the NuGet package manager or in the Package Manager Console with this command:
```PowerShell
Install-Package Microsoft.Rest.ClientRuntime
```
Add the namespace that was given to AutoRest.
```C#
using MyNamespace;
```
Access the REST API with very little code (see [Client Initialization](docs/client/init.md) and [Client Operations](docs/client/ops.md) for details).
```C#
var myClient = new MyClient();
var salutation = myClient.GetGreeting();
Console.WriteLine(salutation);
```
Running the console app shows the greeting retrieved from the service API.
```bat
C:\>HelloWorld.exe
Hello via AutoRest.
```
With that same basic pattern in place, you can now explore how different REST API operations and payloads are described in Swagger and exposed in the code generated by **AutoRest**.
Some information about the internal AutoRest architecture (may need updating!):
- [Developer Guide](./docs/developer/guide/) - Notes on developing with AutoRest
- [AutoRest and ClientRuntimes](./docs/developer/architecture/Autorest-and-Clientruntimes.md) - about the client runtime requirements for AutoRest
- [The `CodeModel` data model](./docs/developer/architecture/CodeModel-and-the-Language-specific-Generator-Transformer-Namer.md) and the Language-specific Generator/Transformer/Namer
- [`Fixable<T>` implemenation](./docs/developer/architecture/Fixable-T----When-a-value-is-both-calculated-and-or-fixed.md) - When a value is both calculated and/or fixed
- [LODIS](./docs/developer/architecture/Least-Offensive-Dependency-Injection-System.md) - The Least Offensive Dependency Injection System
- [Name Disambiguation](./docs/developer/architecture/Name-Disambiguation.md) - how names don't collide in code generation.
- [Validation Rules & Linting](./docs/developer/validation-rules/readme.md) - about the validation rules in AutoRest
---
### Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

Просмотреть файл

@ -0,0 +1,111 @@
# <img align="center" src="../images/logo.png"> Compiling AutoRest
## Requirements
Ensure that you've [setup your developer environment](./workstation.md)
## Check out the code
``` powershell
# clone the repository
git clone https://github.com/azure/autorest
# install node modules
cd autorest
npm install
```
## Using `gulp`
The AutoRest build system has standardized on `gulp` for the following reasons:
- it works very well cross-platform
- excellent support for parallelism
- using `IcedCoffeeScript` + `ShellJS` keeps the scripts very readable.
The main `gulpfile` is the file in the root of the folder called `gulpfile.iced`. You'll also find support modules for that in the `./src/local_modules` folder (see the `.iced` files there)
You can get a quick list of the available gulp commands by running `gulp` without arguments:
``` powershell
# list what gulp commands are available
gulp
```
#### Note: When merging from upstream
If you pull new code, and the `package.json` file has been updated, you will see a warning when you call `gulp`:
```
[13:50:53] Requiring external module iced-coffee-script/register
WARNING: package.json is newer than 'node_modules' - you might want to do an 'npm install'
[13:50:54] Using gulpfile C:\work\github\autorest\gulpfile.iced
```
#### Note: You can use gulp anywhere...
`gulp` is smart enough to find it's `gulpfile.iced` regardless where you are in the project hierarchy:
``` powershell
cd ./src/core/autorest
gulp clean
[13:55:16] Requiring external module iced-coffee-script/register
[13:55:16] Working directory changed to C:\work\github\autorest
[13:55:17] Using gulpfile C:\work\github\autorest\gulpfile.iced
[13:55:17] Starting 'clean/typescript'...
[13:55:17] Starting 'clean/dotnet'...
C:\work\github\autorest :: dotnet clean C:\work\github\autorest/AutoRest.sln /nologo
[13:55:18] Finished 'clean/typescript' after 813 ms
[13:55:21] Finished 'clean/dotnet' after 3.95 s
[13:55:21] Starting 'clean'...
[13:55:21] Finished 'clean' after 19 μs
```
## Common `gulp` commands
### Build the whole project (c# and typscript bits)
`gulp build` - ensures that the dotnet-cli packages are restored, then compiles the typescript and c# projects in parallel.
### Clean out build artifacts from the project
`gulp clean` - cleans the build artifacts
### Shortcut to launch Visual Studio Code at the project root.
`gulp code` - launches vscode
### Fix up line endings for some files
`gulp fix-line-endings` - ensures that .ts files are LF not CRLF. Will be expanded in the future.
### Wiping the nuget package cache
`gulp reset-dotnet-cache` - removes installed dotnet-packages so restore is from a perfectly clean state. WARNING: This will remove the files in `~/.nuget/*`
### Restore dotnet packages
`gulp restore` - restores the dotnet packages for all the projects
### Restore npm packages for Typescript projects
`gulp npm-install` - restores packages for the typescript projects
### Build autorest and install it in the user's home folder (`~/.autorest/plugins/autorest/<VERSION>-<DATE>-<TIME>-private`) as a private build so you can run it with the `autorest` command anywhere.
`gulp install` - build and install the dev version of autorest
### Run AutoRest without installing it
`gulp autorest` - runs the autorest binary directly. You can pass regular command line parameters to it.
`gulp autorest-app` - Runs AutoRest (via the `node` front-end. This will soon be the default.)
### Testing
`gulp regenerate` - regenerate all expected code for tests (There are many fine-grained `rengenerate-*` tasks, find them with `gulp -T` if you need them. )
`gulp test` - runs all tests<br>
`gulp test-dotnet` - runs dotnet tests<br>
`gulp test-go` - runs Go tests<br>
`gulp test-java` - runs Java tests<br>
`gulp test-node` - runs NodeJS tests<br>
`gulp test-python` - runs Python tests<br>
`gulp test-ruby` - runs Ruby tests<br>
## available switches
`--force` specify when you want to force an action (restore, etc)<br>
`--configuration` 'debug' or 'release'<br>
`--release` same as --configuration=release<br>
`--verbose` enable verbose output<br>
`--threshold=nn` set parallelism threshold - default = (# of cpus in system-1)<br>

Просмотреть файл

@ -0,0 +1,87 @@
# <img align="center" src="../images/logo.png"> AutoRest - Developer Workstation Requirements
## Build Prerequisites
AutoRest is developed primarily in C# but generates code for multiple languages. To build and test AutoRest requires a few things be installed locally.
## Minimal Required Tools
At a bare minimum, to compile autorest and run it you will need at least:
### The .NET CLI tools
##### Required: [.NET CLI](https://github.com/dotnet/cli#installers-and-binaries) tools build -004812 or later (after 02/14/2017)
> You want the **.NET Core SDK Binaries** for your platform <br>
>
> `dotnet --version ` <br>
> ` 1.0.0-rc4-004812 ` <br>
### NodeJS
#### Required: [Node.js](https://nodejs.org/en/) 6.9.5 or greater
|asd |Most Users |Technical Users |
|----|------------|--------------------------|
|Windows|Install [Latest NodeJS LTS build](https://nodejs.org/en/download/ ) using the <br>Windows installer.|You can install the [Node Version Manager for Windows](https://github.com/coreybutler/nvm-windows) <br><br>Install the latest release of the [Node Version Manager](https://github.com/coreybutler/nvm-windows/releases/download/1.1.2/nvm-setup.zip) and then run the following commands: <br> `nvm install 6.10.0` <br> `nvm use 6.10.0` |
|Linux|Install [Latest NodeJS LTS build](https://nodejs.org/en/download/package-manager/) via the<br> package manager instructions for <br>your version of Linux|You can install the [Node Version Manager](https://github.com/creationix/nvm#install-script):<br><br>Run the following commands:<br>`curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash` <br> `nvm install 6.10.0` <br> `nvm use 6.10.0`|
|OS X|Install [Latest NodeJS LTS build](https://nodejs.org/en/download/ ) using<br> the Macintosh installer<br><br>or<br><br>Use the [Instructions using a package manager](https://nodejs.org/en/download/package-manager/#osx)|You can install the [Node Version Manager](https://github.com/creationix/nvm#install-script). <br><br>Run the following commands: <br>`touch ~/.bash_profile` <br> `curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash` <br> `nvm install 6.10.0` <br> `nvm use 6.10.0` |
### [Gulp](https://github.com/gulpjs/gulp)
##### Required: version 3.9.1
``` powershell
# Install Globally using 'npm': (may require root/admin depending on your configuration)
npm install -g gulp
```
---
## Recommended Tools
To actually run all the tests for the different languages, you'll also need all the tools and languages installed for your workstation:
- Visual Studio Code
- Git
- JDK 8
- Maven
- Gulp
- Ruby 2.3
- Ruby Devkit
(Windows - also need missing CA Roots for Ruby)
- Python 2.7
- Python 3.5
- Tox
- Go
- Glide
## Easy Windows Setup
### Manual Steps
> #### Enable Developer Mode in win10
> In Cortana, search for `developer settings`<br>
> click "Developer Mode", answer "yes"<br>
> scroll down, and click apply, apply, apply<br>
> Close Settings.<br>
> Reboot (win-r `shutdown -r -t 0`)<br>
> #### Use Install Script to install tools
> After Reboot, login then:<br>
> Win-x , `cmd prompt (admin)` -- (ELEVATED!) <br>
> start Powershell and run this command:<br>
``` powershell
# download the install script and run it.
iwr https://raw.githubusercontent.com/Azure/autorest/master/Tools/setup-developerworkstation.ps1 -OutFile c:\install-software.ps1 ; c:\install-software.ps1
```
> See the actual script at: https://github.com/Azure/autorest/blob/master/Tools/setup-developerworkstation.ps1
## Easy Linux Setup
(coming soon)
## Easy OS X Setup
(coming soon)

Просмотреть файл

@ -0,0 +1,40 @@
# <img align="center" src="./images/logo.png"> Sample : Generating a client using AutoRest
First,Download the Swagger.json example:
| Platform | Command |
|----|---|
|PowerShell|`iwr https://raw.githubusercontent.com/Azure/autorest/master/Samples/petstore/petstore.json -o swagger.json`|
|Linux/OS X|`curl -O https://raw.githubusercontent.com/Azure/autorest/master/Samples/petstore/petstore.json`|
Next, generate the client:
``` powershell
# generate the client
> autorest -Input petstore.json -CodeGenerator CSharp -OutputDirectory CSharp_PetStore -Namespace PetStore
The Microsoft.Rest.ClientRuntime.2.2.0 nuget package is required to compile the generated code.
# show what got generated:
> ls CSharp_PetStore -r
Directory: ...\CSharp_PetStore
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/24/2017 12:20 PM Models
-a---- 2/24/2017 12:20 PM 17657 ISwaggerPetstore.cs
-a---- 2/24/2017 12:20 PM 133979 SwaggerPetstore.cs
-a---- 2/24/2017 12:20 PM 36933 SwaggerPetstoreExtensions.cs
Directory: ...\CSharp_PetStore\Models
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2/24/2017 12:20 PM 2454 Category.cs
-a---- 2/24/2017 12:20 PM 5214 Order.cs
-a---- 2/24/2017 12:20 PM 6610 Pet.cs
-a---- 2/24/2017 12:20 PM 2409 Tag.cs
-a---- 2/24/2017 12:20 PM 6305 User.cs
-a---- 2/24/2017 12:20 PM 4026 XmlSerialization.cs
```

Двоичные данные
docs/images/glasses.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.0 KiB

Двоичные данные
docs/images/logo.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 20 KiB

Двоичные данные
docs/images/normal.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 997 B

131
docs/managing-autorest.md Normal file
Просмотреть файл

@ -0,0 +1,131 @@
# <img align="center" src="./images/logo.png"> Managing AutoRest from the command line
Once you have AutoRest installed using `npm`, it should be available on the PATH, so you can just run it from anywhere:
``` powershell
# The first time you run it, it will pull in the binaries that are needed to run. (no elevation/root required)
> autorest
AutoRest
Downloading https://github.com/Azure/autorest/releases/.../dotnet-win7-x64.1.0.3.zip
to c:\users\...\.autorest\frameworks
Downloading https://github.com/Azure/autorest/releases/.../autorest-1.0.1-20170223-1007-preview.zip
to c:\users\...\.autorest\plugins\autorest\1.0.1-20170223-1007-preview
```
You can get some help from the command line:
``` powershell
# Run AutoRest and see the command-line help.
> autorest --help
AutoRest
Build Information
Bootstrapper : 0.9.10
NetCore framework : 1.0.3
AutoRest core : 1.0.1-20170223-1007-preview
Output Verbosity
--verbose show verbose output information
--debug show internal debug information
--quiet suppress output
Versions
--list-installed show all installed versions of AutoRest tools
--list-available=nn lists the last nn releases available from github
(defaults to 10)
Installation
--version=version uses version of AutoRest, installing if necessary.
for version you can
use a version label (see --list-available) or
latest - get latest nightly build
latest-release - get latest release version
--reset remove all installed versions of AutoRest tools
and install the latest (override with --version)
```
You can use any version of AutoRest by asking for it on the command-line. If it's not installed, AutoRest will install it first:
``` powershell
# Use the latest nightly or preview version:
> autorest --version=latest <...args>
# Use the latest 'release' version :
> autorest --version=latest-release <...args>
# Use a specific version
> autorest --version=1.0.1-20170223-1007-preview <...args>
```
You can see what versions of AutoRest that are available to install:
``` powershell
# show available versions
> autorest --list-available
AutoRest
Build Information
Bootstrapper : 0.9.10
NetCore framework : 1.0.3
AutoRest core : 1.0.1-20170223-1007-preview
Output Verbosity
--verbose show verbose output information
--debug show internal debug information
--quiet suppress output
Versions
--list-installed show all installed versions of AutoRest tools
--list-available=nn lists the last nn releases available from github
(defaults to 10)
Installation
--version=version uses version of AutoRest, installing if necessary.
for version you can
use a version label (see --list-available) or
latest - get latest nightly build
latest-release - get latest release version
--reset remove all installed versions of AutoRest tools
and install the latest (override with --version)
Last 10 releases available online:
1.0.1-20170223-1007-preview
1.0.1-20170222-1520-preview
```
You can also see what's installed locally:
``` powershell
# look what is installed already
autorest --list-installed
AutoRest
Build Information
Bootstrapper : 0.9.10 # current npm package version
NetCore framework : 1.0.3 # current version of the .NET Core framework
AutoRest core : 1.0.1-20170223-1007-preview # current version of the AutoRest tool itself.
Installed versions of AutoRest :
1.0.1-20170223-1007-preview # list of all the versions installed.
```
If you want to remove all versions of AutoRest and install the just latest version
``` powershell
# Remove all binaries for AutoRest
> autorest --reset <...args>
AutoRest
Downloading https://github.com/Azure/autorest/releases/.../dotnet-win7-x64.1.0.3.zip
to ~\.autorest\frameworks
Downloading https://github.com/Azure/autorest/releases/.../autorest-1.0.1-20170223-1007-preview.zip
to ~\.autorest\plugins\autorest\1.0.1-20170223-1007-preview
```