Skip to content

Commit

Permalink
fix adding enum value & command line exception (#255)
Browse files Browse the repository at this point in the history
* fix adding enum value & command line exception

* fix lint error

* fix test

* fix test

* fix file path contains space

* fix lint error

Co-authored-by: jianyexi <[email protected]>
  • Loading branch information
jianyexi and jianyexi authored Nov 24, 2022
1 parent 185090c commit 000f1f7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ public void CommonParameterWithRef()
public void XmsEnumModelAsString()
{
var messages = CompareSwagger("enum_as_string.json").ToArray();
Assert.Empty(messages.Where(m => m.Id == ComparisonMessages.AddedEnumValue.Id));
Assert.Equal(2,messages.Where(m => m.Id == ComparisonMessages.AddedEnumValue.Id).ToList().Count());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ private void CompareEnums(ComparisonContext<ServiceDefinition> context, T prior)
CompareXmsEnum(context,prior);
bool relaxes = (prior.Enum != null && this.Enum == null);
bool constrains = (prior.Enum == null && this.Enum != null);
bool isEnumModelAsString = (this.XmsEnum != null && this.XmsEnum.ModelAsString == true);
if (!relaxes && !constrains)
{
// It was enum and it is still enum i.e check for addition/removal
Expand All @@ -213,9 +212,7 @@ private void CompareEnums(ComparisonContext<ServiceDefinition> context, T prior)
IEnumerable<string> addedEnums = this.Enum.Except(prior.Enum);
if (addedEnums.Any())
{
if (!isEnumModelAsString) {
context.LogBreakingChange(ComparisonMessages.AddedEnumValue, String.Join(", ", addedEnums.ToList()));
}
context.LogBreakingChange(ComparisonMessages.AddedEnumValue, String.Join(", ", addedEnums.ToList()));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/oad",
"version": "0.10.2",
"version": "0.10.3",
"author": {
"name": "Microsoft Corporation",
"email": "[email protected]",
Expand Down
12 changes: 8 additions & 4 deletions src/lib/validators/openApiDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ const updateChangeProperties = (change: ChangeProperties, pf: ProcessedFile): Ch
}
}

function escape(filePath: string) {
return `"${filePath}"`
}

/**
* @class
* Open API Diff class.
Expand Down Expand Up @@ -154,7 +158,7 @@ export class OpenApiDiff {
const result = path.join(__dirname, "..", "..", "..", "node_modules", "autorest", "dist", "app.js")
if (fs.existsSync(result)) {
log.silly(`Found autoRest:${result} `)
return `node ${result}`
return `node ${escape(result)}`
}
}

Expand All @@ -163,7 +167,7 @@ export class OpenApiDiff {
const result = path.join(__dirname, "..", "..", "..", "..", "..", "autorest", "dist", "app.js")
if (fs.existsSync(result)) {
log.silly(`Found autoRest:${result} `)
return `node ${result}`
return `node ${escape(result)}`
}
}

Expand All @@ -172,7 +176,7 @@ export class OpenApiDiff {
const result = path.resolve("node_modules/.bin/autorest")
if (fs.existsSync(result)) {
log.silly(`Found autoRest:${result} `)
return result
return escape(result)
}
}

Expand All @@ -188,7 +192,7 @@ export class OpenApiDiff {
public openApiDiffDllPath(): string {
log.silly(`openApiDiffDllPath is being called`)

return path.join(__dirname, "..", "..", "..", "dlls", "OpenApiDiff.dll")
return escape(path.join(__dirname, "..", "..", "..", "dlls", "OpenApiDiff.dll"))
}

/**
Expand Down

0 comments on commit 000f1f7

Please sign in to comment.