Skip to content

Commit

Permalink
Merge pull request #10 from amarzavery/master
Browse files Browse the repository at this point in the history
Resolve conflicts and minor updates to EnumTemplate and readme
  • Loading branch information
amarzavery committed Oct 21, 2017
2 parents 5f949f3 + c41f6d5 commit a0f61ce
Show file tree
Hide file tree
Showing 107 changed files with 412 additions and 90 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@

# Installation
```
npm install -g autorest
```

# Usage
- Basic Usage:
```
autorest --typescript --output-folder=<path-to-the-output-folder(usually upto lib or src folder of your project)> --license-header=MICROSOFT_MIT_NO_VERSION --input-file=<path-to-swagger-spec> --package-name=<your-package-name> --package-version<your-package-version>
```
- If you have a markdown config file then there is no need to use --input-file, simply provide the path to the markdown file:
```
autorest --typescript --output-folder=<path-to-the-output-folder(usually upto lib or src folder of your project)> --license-header=MICROSOFT_MIT_NO_VERSION <path-to-readme.md> -package-name=<your-package-name> --package-version<your-package-version>
```
- If you want to generate metadata files (package.json, .npmignore, webpack.config.js, tsconfig.json), then provide `--generate-metadata=true`:

**NOTE: This will generate all the files one level above the output-folder.**
```
autorest --typescript --output-folder=<path-to-the-output-folder(usually upto lib or src folder of your project)> --license-header=MICROSOFT_MIT_NO_VERSION --input-file=<path-to-swagger-spec> --package-name=<your-package-name> --package-version<your-package-version> --generate-metadata=true
```

- For generating a client for an azure service, provide `--typescript.azure-arm=true`:
```
autorest --typescript --output-folder=<path-to-the-output-folder(usually upto lib or src folder of your project)> --license-header=MICROSOFT_MIT_NO_VERSION --input-file=<path-to-swagger-spec> --package-name=<your-package-name> --package-version<your-package-version> --generate-metadata=true --typescript.azure-arm=true
```

# Development

### Building the project
After cloning the repo, execute:
- `npm install`
- `gulp build` (Make sure you have gulp installed globally too (`npm install -g gulp`))

### Testing the developed changes
- `gulp regenerate`
- `gulp test`

### Debugging using vscode
Add the `--typescript.debugger` to the command line and then use the Attach to Debugger option from vscode. Attach to the dotnet.exe process id that is provided in the command line.
We have the .vscode folder in the repo that has the config for attaching to the debugger.

# Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Expand Down
2 changes: 1 addition & 1 deletion src/azure/PluginTSa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public PluginTSa()
new Factory<DictionaryType, DictionaryTypeTS>(),
new Factory<SequenceType, SequenceTypeTS>(),
new Factory<MethodGroup, MethodGroupTS>(),
new Factory<EnumType, EnumType>(),
new Factory<EnumType, EnumTypeTS>(),
new Factory<PrimaryType, PrimaryTypeTS>()
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/vanilla/ClientModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static string GetEnumValuesArray(this EnumType type)
throw new ArgumentNullException(nameof(type));
}

return $"[ {string.Join(", ", type.Values.Select(p => $"'{p.Name}'"))} ]";
return $"[ {string.Join(", ", type.Values.Select(p => $"'{p.SerializedName}'"))} ]";
}

public static string EscapeSingleQuotes(this string valueReference)
Expand Down Expand Up @@ -516,7 +516,7 @@ public static string TSType(this IModelType type, bool inModelsModule) {
}
else if (enumType != null)
{
var enumName = enumType.Name;
var enumName = enumType.Name.ToPascalCase();
tsType = "Models." + enumName;
if (inModelsModule || enumName.Contains('.'))
{
Expand Down
3 changes: 3 additions & 0 deletions src/vanilla/Model/CodeModelTS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public CodeModelTS(string packageName = "test-client", string packageVersion = "
[JsonIgnore]
public virtual IEnumerable<CompositeTypeTS> ModelTemplateModels => ModelTypes.Cast<CompositeTypeTS>();

[JsonIgnore]
public virtual IEnumerable<EnumTypeTS> EnumTemplateModels => EnumTypes.Cast<EnumTypeTS>();

[JsonIgnore]
public virtual IEnumerable<MethodGroupTS> MethodGroupModels => Operations.Cast<MethodGroupTS>().Where( each => !each.IsCodeModelMethodGroup );

Expand Down
13 changes: 13 additions & 0 deletions src/vanilla/Model/EnumTypeTS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using AutoRest.Core;
using AutoRest.Core.Model;

namespace AutoRest.TypeScript.Model
{
public class EnumTypeTS : EnumType
{
public string EnumName => CodeNamer.Instance.PascalCase(Name);
}
}
2 changes: 1 addition & 1 deletion src/vanilla/PluginTS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public PluginTS()
new Factory<DictionaryType, DictionaryTypeTS>(),
new Factory<SequenceType, SequenceTypeTS>(),
new Factory<MethodGroup, MethodGroupTS>(),
new Factory<EnumType, EnumType>(),
new Factory<EnumType, EnumTypeTS>(),
new Factory<PrimaryType, PrimaryTypeTS>()
};
}
Expand Down
6 changes: 6 additions & 0 deletions src/vanilla/Templates/EnumTemplate.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
@if (Model.ExtendedDocumentation != null)
{
@:@(WrapComment(" * ", Model.ExtendedDocumentation))
}
@if (Model.ModelAsString)
{
@:@(WrapComment(" * ", "There could be more values for this enum apart from the ones defined here." +
"If you want to set a value that is not from the known values then you can do the following:\n" +
"let param: " + Model.Name + " = <" + Model.Name + ">\"someUnknownValueThatWillStillBeValid\";"))
}
* @@readonly
* @@enum {@CodeNamer.Instance.CamelCase(Model.UnderlyingType.Name)}
Expand Down
1 change: 0 additions & 1 deletion src/vanilla/Templates/ModelIndexTemplate.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@
@EmptyLine
@:@(Include(new EnumTemplate(), model))
}

Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,10 @@ export interface ReadonlypropertyPutValidOptionalParams extends RequestOptionsBa
/**
* Defines values for CMYKColors.
* Possible values include: 'cyan', 'Magenta', 'YELLOW', 'blacK'
* There could be more values for this enum apart from the ones defined here.If
* you want to set a value that is not from the known values then you can do
* the following:
* let param: CMYKColors = <CMYKColors>"someUnknownValueThatWillStillBeValid";
* @readonly
* @enum {string}
*/
Expand Down
14 changes: 14 additions & 0 deletions test/azure/Expected/AcceptanceTests/Lro/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,11 @@ export interface LROsCustomHeaderBeginPostAsyncRetrySucceededOptionalParams exte
* Defines values for ProvisioningStateValues.
* Possible values include: 'Succeeded', 'Failed', 'canceled', 'Accepted',
* 'Creating', 'Created', 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK'
* There could be more values for this enum apart from the ones defined here.If
* you want to set a value that is not from the known values then you can do
* the following:
* let param: ProvisioningStateValues =
* <ProvisioningStateValues>"someUnknownValueThatWillStillBeValid";
* @readonly
* @enum {string}
*/
Expand All @@ -1535,6 +1540,11 @@ export enum ProvisioningStateValues {
* Defines values for ProvisioningStateValues1.
* Possible values include: 'Succeeded', 'Failed', 'canceled', 'Accepted',
* 'Creating', 'Created', 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK'
* There could be more values for this enum apart from the ones defined here.If
* you want to set a value that is not from the known values then you can do
* the following:
* let param: ProvisioningStateValues1 =
* <ProvisioningStateValues1>"someUnknownValueThatWillStillBeValid";
* @readonly
* @enum {string}
*/
Expand All @@ -1556,6 +1566,10 @@ export enum ProvisioningStateValues1 {
* Defines values for Status.
* Possible values include: 'Succeeded', 'Failed', 'canceled', 'Accepted',
* 'Creating', 'Created', 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK'
* There could be more values for this enum apart from the ones defined here.If
* you want to set a value that is not from the known values then you can do
* the following:
* let param: Status = <Status>"someUnknownValueThatWillStillBeValid";
* @readonly
* @enum {string}
*/
Expand Down
4 changes: 4 additions & 0 deletions test/azure/Expected/AcceptanceTests/Paging/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ export interface OdataProductResult extends Array<Product> {
* Defines values for Status.
* Possible values include: 'Succeeded', 'Failed', 'canceled', 'Accepted',
* 'Creating', 'Created', 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK'
* There could be more values for this enum apart from the ones defined here.If
* you want to set a value that is not from the known values then you can do
* the following:
* let param: Status = <Status>"someUnknownValueThatWillStillBeValid";
* @readonly
* @enum {string}
*/
Expand Down
2 changes: 1 addition & 1 deletion test/azure/dist/AcceptanceTests/startServer.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit a0f61ce

Please sign in to comment.