nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: stephenh/ts-proto
Pull request #648 (2022-08-06 18:17:04)

fix: Use underscore separator in snakeToCamel.


Patch:
diff --git a/README.markdown b/README.markdown
index 43c5dce7..c4813e38 100644
--- a/README.markdown
+++ b/README.markdown
@@ -339,7 +339,15 @@ Generated code will be placed in the Gradle build directory.
 
 - With `--ts_proto_opt=lowerCaseServiceMethods=true`, the method names of service methods will be lowered/camel-case, i.e. `service.findFoo` instead of `service.FindFoo`.
 
-- With `--ts_proto_opt=snakeToCamel=false`, fields will be kept snake case. `snakeToCamel` can also be set as string with `--ts_proto_opt=snakeToCamel=keys,json`. `keys` will keep field names as camelCase and `json` will keep json field names as camelCase. Empty string will keep field names as snake_case.
+- With `--ts_proto_opt=snakeToCamel=false`, fields will be kept snake case in both the message keys and the `toJSON` / `fromJSON` methods.
+
+  `snakeToCamel` can also be set as a `_`-delimited list of strings (comma is reserved as the flag delimited), i.e. `--ts_proto_opt=snakeToCamel=keys_json`, where including `keys` will make message keys be camel case and including `json` will make JSON keys be camel case.
+
+   Empty string, i.e. `snakeToCamel=`, will keep both messages keys and `JSON` keys as snake case (it is the same as `snakeToCamel=false`).
+
+   Note that to use the `json_name` attribute, you'll have to use the `json`.
+
+   The default behavior is `keys_json`, i.e. both will be camel cased, and `json_name` will be used if set.
 
 - With `--ts_proto_opt=outputEncodeMethods=false`, the `Message.encode` and `Message.decode` methods for working with protobuf-encoded/binary data will not be output.
 
diff --git a/src/options.ts b/src/options.ts
index f19acab9..549ef4f5 100644
--- a/src/options.ts
+++ b/src/options.ts
@@ -176,7 +176,7 @@ export function optionsFromParameter(parameter: string | undefined): Options {
   } else if ((options.snakeToCamel as any) === true) {
     options.snakeToCamel = ['keys', 'json'];
   } else if (typeof options.snakeToCamel === 'string') {
-    options.snakeToCamel = [options.snakeToCamel];
+    options.snakeToCamel = (options.snakeToCamel as string).split('_') as any;
   }
 
   if (options.useJsonWireFormat) {


Test patch:
diff --git a/tests/options-test.ts b/tests/options-test.ts
index efb733c6..ccbbc6b5 100644
--- a/tests/options-test.ts
+++ b/tests/options-test.ts
@@ -98,6 +98,11 @@ describe('options', () => {
     expect(options).toMatchObject({ snakeToCamel: ['keys'] });
   });
 
+  it('can set snakeToCamel as two values', () => {
+    const options = optionsFromParameter('snakeToCamel=keys_json');
+    expect(options).toMatchObject({ snakeToCamel: ['keys', 'json'] });
+  });
+
   it('can set multiple values as an array', () => {
     const options = optionsFromParameter('foo=one,foo=two');
     expect(options).toMatchObject({ foo: ['one', 'two'] });
Repository: stoplightio/spectral
Pull request #824 (2019-11-30 13:09:58)

fix: print falsy value in error messages

**Checklist**

- [x] Tests added / updated
- [x] Docs added / updated

**Does this PR introduce a breaking change?**

- [ ] Yes
- [x] No


**Additional context**

Fixes an issue where a falsy value (referenced via `{{value}}`) would not be printed in the error message.



Patch:
diff --git a/src/rulesets/message.ts b/src/rulesets/message.ts
index c0f2967c..cece5596 100644
--- a/src/rulesets/message.ts
+++ b/src/rulesets/message.ts
@@ -18,7 +18,7 @@ export const message: MessageInterpolator = (str, values) => {
 
   // tslint:disable-next-line:no-conditional-assignment
   while ((result = BRACES.exec(str))) {
-    const newValue = String(values[result[1]] || '');
+    const newValue = result[1] in values ? String(values[result[1]]) : '';
     str = `${str.slice(0, result.index)}${newValue}${str.slice(BRACES.lastIndex)}`;
     BRACES.lastIndex = result.index + newValue.length;
   }


Test patch:
diff --git a/src/rulesets/oas/__tests__/message.spec.ts b/src/rulesets/__tests__/message.spec.ts
similarity index 71%
rename from src/rulesets/oas/__tests__/message.spec.ts
rename to src/rulesets/__tests__/message.spec.ts
index c235ea77..0b5f4c07 100644
--- a/src/rulesets/oas/__tests__/message.spec.ts
+++ b/src/rulesets/__tests__/message.spec.ts
@@ -1,4 +1,4 @@
-import { message } from '../../message';
+import { message } from '../message';
 
 describe('message util', () => {
   test('interpolates correctly', () => {
@@ -13,6 +13,18 @@ describe('message util', () => {
     ).toEqual('oops... "description" is missing;error: expected property to be truthy');
   });
 
+  test.each([0, false, null, undefined])('interpolates %s value correctly', value => {
+    const template = 'Value must not equal {{value}}';
+    expect(
+      message(template, {
+        property: 'description',
+        error: 'expected property to be truthy',
+        path: '',
+        value,
+      }),
+    ).toEqual(`Value must not equal ${value}`);
+  });
+
   test('handles siblings', () => {
     const template = '{{error}}{{error}}{{property}}{{bar}}{{error}}{{error}}';
     expect(
Repository: stoplightio/spectral
Pull request #1031 (2020-03-24 19:06:49)

fix(ruleset): Correct misleading 'info-license' message
**Checklist**

- [x] Tests added / updated
- [ ] Docs added / updated

**Does this PR introduce a breaking change?**

- [ ] Yes
- [x] No

Discovered while working on #974


Patch:
diff --git a/src/rulesets/oas/index.json b/src/rulesets/oas/index.json
index 0b407004..1ea6ad9d 100644
--- a/src/rulesets/oas/index.json
+++ b/src/rulesets/oas/index.json
@@ -161,7 +161,7 @@
       ]
     },
     "info-license": {
-      "description": "OpenAPI object info `license` must be present and non-empty string.",
+      "description": "OpenAPI object `info` should contain a `license` object.",
       "recommended": false,
       "type": "style",
       "given": "$",


Test patch:
diff --git a/src/rulesets/oas/__tests__/info-license.ts b/src/rulesets/oas/__tests__/info-license.ts
index fbffe829..b5921e6b 100644
--- a/src/rulesets/oas/__tests__/info-license.ts
+++ b/src/rulesets/oas/__tests__/info-license.ts
@@ -33,7 +33,7 @@ describe('info-license', () => {
     expect(results).toEqual([
       {
         code: 'info-license',
-        message: 'OpenAPI object info `license` must be present and non-empty string.',
+        message: 'OpenAPI object `info` should contain a `license` object.',
         path: ['info'],
         range: {
           end: {
Repository: stoplightio/spectral
Pull request #1038 (2020-03-29 09:15:59)

fix(ruleset): Make openapi-tags rule fit its description
Should help this rule fulfill its own promise ;-)

**Checklist**

- [x] Tests added / updated
- [ ] Docs added / updated

**Does this PR introduce a breaking change?**

- [ ] Yes
- [x] No

Discovered while working on #974 


Patch:
diff --git a/src/rulesets/oas/index.json b/src/rulesets/oas/index.json
index 1ea6ad9d..e6e9e5bd 100644
--- a/src/rulesets/oas/index.json
+++ b/src/rulesets/oas/index.json
@@ -253,7 +253,13 @@
       "given": "$",
       "then": {
         "field": "tags",
-        "function": "truthy"
+        "function": "schema",
+        "functionOptions": {
+          "schema": {
+            "type": "array",
+            "minItems": 1
+          }
+        }
       },
       "tags": [
         "api"


Test patch:
diff --git a/src/rulesets/oas/__tests__/openapi-tags.ts b/src/rulesets/oas/__tests__/openapi-tags.ts
index 8ad2379a..dd8b0b6a 100644
--- a/src/rulesets/oas/__tests__/openapi-tags.ts
+++ b/src/rulesets/oas/__tests__/openapi-tags.ts
@@ -44,4 +44,30 @@ describe('openapi-tags', () => {
       },
     ]);
   });
+
+  test('return errors if empty tags', async () => {
+    const results = await s.run({
+      swagger: '2.0',
+      paths: {},
+      tags: [],
+    });
+    expect(results).toEqual([
+      {
+        code: 'openapi-tags',
+        message: 'OpenAPI object should have non-empty `tags` array.',
+        path: ['tags'],
+        range: {
+          start: {
+            character: 9,
+            line: 3,
+          },
+          end: {
+            character: 12,
+            line: 3,
+          },
+        },
+        severity: DiagnosticSeverity.Warning,
+      },
+    ]);
+  });
 });
Repository: stoplightio/spectral
Pull request #1172 (2020-05-20 00:02:37)

fix: handle exceptions thrown by runRule
Fixes https://github.com/stoplightio/spectral/issues/1170

**Checklist**

- [x] Tests added / updated
- [x] Docs added / updated

**Does this PR introduce a breaking change?**

- [ ] Yes
- [x] No



Patch:
diff --git a/src/runner/runner.ts b/src/runner/runner.ts
index d7704b71..9e41da4b 100644
--- a/src/runner/runner.ts
+++ b/src/runner/runner.ts
@@ -45,7 +45,11 @@ export const runRules = async (context: IRunnerPublicContext): Promise<IRuleResu
   );
 
   for (const rule of relevantRules) {
-    runRule(runnerContext, rule, exceptRuleByLocations[rule.name]);
+    try {
+      runRule(runnerContext, rule, exceptRuleByLocations[rule.name]);
+    } catch (ex) {
+      console.error(ex);
+    }
   }
 
   if (runnerContext.promises.length > 0) {


Test patch:
diff --git a/src/__tests__/linter.test.ts b/src/__tests__/linter.test.ts
index 2816938b..46027ab6 100644
--- a/src/__tests__/linter.test.ts
+++ b/src/__tests__/linter.test.ts
@@ -56,6 +56,43 @@ describe('linter', () => {
     return expect(spectral.run('123')).resolves.toBeTruthy();
   });
 
+  test('should run all rules despite of invalid JSON path expressions', async () => {
+    spectral.setRules({
+      rule1: {
+        given: '$.bar[?(@.in==foo)]',
+        then: {
+          function: 'truthy',
+        },
+      },
+      rule2: {
+        given: '$.foo',
+        then: {
+          function: 'truthy',
+        },
+      },
+    });
+
+    const results = await spectral.run(
+      {
+        bar: {
+          in: {},
+        },
+        foo: null,
+      },
+      { ignoreUnknownFormat: true },
+    );
+
+    return expect(results).toEqual([
+      {
+        code: 'rule2',
+        message: '`foo` property is not truthy',
+        path: ['foo'],
+        range: expect.any(Object),
+        severity: DiagnosticSeverity.Warning,
+      },
+    ]);
+  });
+
   test('should return all properties matching 4xx response code', async () => {
     const message = '4xx responses require a description';
Repository: stoplightio/spectral
Pull request #1256 (2020-06-25 15:48:16)

fix: casing fn handles leading char
We could tweak the regular expression, but this feels more readable to me.

**Checklist**

- [x] Tests added / updated
- [x] Docs added / updated

**Does this PR introduce a breaking change?**

- [ ] Yes
- [x] No




Patch:
diff --git a/src/functions/casing.ts b/src/functions/casing.ts
index fffe480a..fb85400e 100644
--- a/src/functions/casing.ts
+++ b/src/functions/casing.ts
@@ -36,6 +36,15 @@ export const casing: IFunction<ICasingOptions> = (targetVal, opts) => {
     return;
   }
 
+  if (
+    targetVal.length === 1 &&
+    opts.separator !== void 0 &&
+    opts.separator.allowLeading === true &&
+    targetVal === opts.separator.char
+  ) {
+    return;
+  }
+
   const casingValidator = buildFrom(CASES[opts.type], opts);
 
   if (casingValidator.test(targetVal)) {


Test patch:
diff --git a/src/functions/__tests__/casing.test.ts b/src/functions/__tests__/casing.test.ts
index d5fc5596..8da9fa88 100644
--- a/src/functions/__tests__/casing.test.ts
+++ b/src/functions/__tests__/casing.test.ts
@@ -265,6 +265,13 @@ describe('casing', () => {
       );
     });
 
+    test.each(Object.values(CasingType))('properly detects leading char for %s casing', casing => {
+      expect(runCasing('/', casing, true, { allowLeading: true, char: '/' })).toBeUndefined();
+      expect(runCasing('//', casing, true, { allowLeading: true, char: '/' })).toEqual([
+        { message: `must be ${casing} case` },
+      ]);
+    });
+
     test('allows advanced scenarios', () => {
       expect(runCasing('X-MyAmazing-Header', CasingType.pascal, true, { char: '-' })).toBeUndefined();
       expect(
Repository: stoplightio/spectral
Pull request #1338 (2020-09-14 13:06:59)

feat: implement defined function
Should help with https://github.com/openapi-contrib/style-guides/issues/10

It'd be actually good if we had some support for NOT in rulesets.

**Checklist**

- [x] Tests added / updated
- [x] Docs added / updated

**Does this PR introduce a breaking change?**

- [ ] Yes
- [x] No





Patch:
diff --git a/docs/reference/functions.md b/docs/reference/functions.md
index ced150fd..64c16f40 100644
--- a/docs/reference/functions.md
+++ b/docs/reference/functions.md
@@ -236,6 +236,11 @@ important-fields:
       function: truthy
 ```
 
+## defined
+
+The value must be defined, meaning it must be anything but `undefined`.
+It's the opposite of what undefined function does.
+
 ## undefined
 
 The value must be `undefined`. When combined with `field: foo` on an object the `foo` property must be undefined.
diff --git a/src/functions/defined.ts b/src/functions/defined.ts
new file mode 100644
index 00000000..b1cec320
--- /dev/null
+++ b/src/functions/defined.ts
@@ -0,0 +1,11 @@
+import { IFunction, IFunctionResult } from '../types';
+
+export const defined: IFunction = (targetVal): void | IFunctionResult[] => {
+  if (typeof targetVal === 'undefined') {
+    return [
+      {
+        message: '{{property|gravis|append-property}}should be defined',
+      },
+    ];
+  }
+};


Test patch:
diff --git a/src/functions/__tests__/defined.test.ts b/src/functions/__tests__/defined.test.ts
new file mode 100644
index 00000000..eb9e473e
--- /dev/null
+++ b/src/functions/__tests__/defined.test.ts
@@ -0,0 +1,30 @@
+import { defined } from '../defined';
+
+function runDefined(targetVal: any, targetPath?: any) {
+  return defined(
+    targetVal,
+    null,
+    {
+      given: ['$'],
+      target: targetPath,
+    },
+    {
+      given: null,
+      original: null,
+    } as any,
+  );
+}
+
+describe('defined', () => {
+  test.each([true, 0, null])('should return undefined if target value is defined', value => {
+    expect(runDefined(value)).toBeUndefined();
+  });
+
+  test('should return an error message if target value is undefined', () => {
+    expect(runDefined(void 0)).toEqual([
+      {
+        message: '{{property|gravis|append-property}}should be defined',
+      },
+    ]);
+  });
+});
Repository: stoplightio/spectral
Pull request #1379 (2020-10-09 11:22:41)

fix(oas-valid-example): ignore externalValue
Fixes https://github.com/stoplightio/spectral/issues/1349

**Checklist**

- [x] Tests added / updated
- [x] Docs added / updated

**Does this PR introduce a breaking change?**

- [ ] Yes
- [x] No





Patch:
diff --git a/src/rulesets/oas/functions/oasExample.ts b/src/rulesets/oas/functions/oasExample.ts
index 4b19b542..2cf31412 100644
--- a/src/rulesets/oas/functions/oasExample.ts
+++ b/src/rulesets/oas/functions/oasExample.ts
@@ -91,7 +91,7 @@ export const oasExample: IFunction<IOasExampleOptions> = function (
 
       for (const exampleKey of Object.keys(value)) {
         const exampleValue = value[exampleKey];
-        if (keyed && !isObject(exampleValue)) {
+        if (opts.oasVersion === 3 && keyed && (!isObject(exampleValue) || 'externalValue' in exampleValue)) {
           // should be covered by oas3-examples-value-or-externalValue
           continue;
         }


Test patch:
diff --git a/src/rulesets/oas/__tests__/oas3-valid-media-example.test.ts b/src/rulesets/oas/__tests__/oas3-valid-media-example.test.ts
index 3c67a064..db3e8382 100644
--- a/src/rulesets/oas/__tests__/oas3-valid-media-example.test.ts
+++ b/src/rulesets/oas/__tests__/oas3-valid-media-example.test.ts
@@ -173,6 +173,26 @@ describe('oas3-valid-media-example', () => {
       ]);
     });
 
+    test('ignores externalValue', async () => {
+      const results = await s.run({
+        openapi: '3.0.0',
+        [path]: {
+          xoxo: {
+            schema: {
+              type: 'string',
+            },
+            examples: {
+              test1: {
+                externalValue: 'http://example.com/foobar.json',
+              },
+            },
+          },
+        },
+      });
+
+      expect(results).toEqual([]);
+    });
+
     test('does not report example mismatches for unknown AJV formats', async () => {
       const results = await s.run({
         openapi: '3.0.0',
Repository: stoplightio/spectral
Pull request #1427 (2020-12-27 16:04:07)

fix(ruleset): Allow single trailing slash for oas3 server url
This PR makes a small modification to the `oas3-server-trailing-slash` rule to allow the url value to be a single slash.

According to the description of the `servers` field of an OpenAPI object in [the OpenAPI specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#oasDocument):

> the default value would be a Server Object with a url value of `/`

Since the default value for the `url` is a single slash (`/`), this should be considered a valid value and not generate a warning message.

**Checklist**

- [X] Tests added / updated
- [ ] Docs added / updated (NA)

**Does this PR introduce a breaking change?**

- [ ] Yes
- [X] No



Patch:
diff --git a/src/rulesets/oas/index.json b/src/rulesets/oas/index.json
index 13414e0b..92d4ab40 100644
--- a/src/rulesets/oas/index.json
+++ b/src/rulesets/oas/index.json
@@ -569,7 +569,7 @@
       "then": {
         "function": "pattern",
         "functionOptions": {
-          "notMatch": "/$"
+          "notMatch": "./$"
         }
       }
     },


Test patch:
diff --git a/src/rulesets/oas/__tests__/oas3-server-trailing-slash.ts b/src/rulesets/oas/__tests__/oas3-server-trailing-slash.ts
index bfc2d00f..148677b4 100644
--- a/src/rulesets/oas/__tests__/oas3-server-trailing-slash.ts
+++ b/src/rulesets/oas/__tests__/oas3-server-trailing-slash.ts
@@ -25,6 +25,19 @@ describe('oas3-server-trailing-slash', () => {
     expect(results.length).toEqual(0);
   });
 
+  test('validate a correct object with default value', async () => {
+    const results = await s.run({
+      openapi: '3.0.0',
+      paths: {},
+      servers: [
+        {
+          url: '/',
+        },
+      ],
+    });
+    expect(results.length).toEqual(0);
+  });
+
   test('return errors if server url ends with a slash', async () => {
     const results = await s.run({
       openapi: '3.0.0',
Repository: stoplightio/spectral
Pull request #503 (2019-08-29 14:28:48)

fix: supress unknown format AJV error
Fixes https://github.com/stoplightio/spectral/issues/396

**Checklist**

- [x] Tests added / updated
- [ ] Docs added / updated

**Does this PR introduce a breaking change?**

- [ ] Yes
- [x] No


**Additional context**

Removes AJV warnings starting with 'unknown format'


chris-miaskowski: hey folks, what's that btw https://circleci.com/gh/stoplightio/spectral/5994?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link ?? It isn't my fault :(
chris-miaskowski: > See my comment

What comment? I can't see any.
P0lip: Feel free to apply these 3 extra suggestions and then let's merge it.

Patch:
diff --git a/src/functions/schema.ts b/src/functions/schema.ts
index c3dda3db..0b2173d3 100644
--- a/src/functions/schema.ts
+++ b/src/functions/schema.ts
@@ -1,21 +1,34 @@
 import * as AJV from 'ajv';
-import * as jsonSpecv4 from 'ajv/lib/refs/json-schema-draft-04.json';
-const oasFormatValidator = require('ajv-oai/lib/format-validator');
 import { ValidateFunction } from 'ajv';
+import * as jsonSpecv4 from 'ajv/lib/refs/json-schema-draft-04.json';
 import { IOutputError } from 'better-ajv-errors';
 import { JSONSchema4, JSONSchema6 } from 'json-schema';
 import { IFunction, IFunctionResult, ISchemaOptions } from '../types';
+const oasFormatValidator = require('ajv-oai/lib/format-validator');
 const betterAjvErrors = require('better-ajv-errors/lib/modern');
 
 interface IAJVOutputError extends IOutputError {
   path?: string;
 }
 
+const logger = {
+  warn(...args: any[]) {
+    const firstArg = args[0];
+    if (typeof firstArg === 'string') {
+      if (firstArg.startsWith('unknown format')) return;
+      console.warn(...args);
+    }
+  },
+  log: console.log,
+  error: console.error,
+};
+
 const ajv = new AJV({
   meta: false,
   schemaId: 'auto',
   jsonPointers: true,
   unknownFormats: 'ignore',
+  logger,
 });
 ajv.addMetaSchema(jsonSpecv4);
 // @ts-ignore


Test patch:
diff --git a/src/functions/__tests__/schema.test.ts b/src/functions/__tests__/schema.test.ts
index d899c28a..1bb63a9a 100644
--- a/src/functions/__tests__/schema.test.ts
+++ b/src/functions/__tests__/schema.test.ts
@@ -6,6 +6,27 @@ function runSchema(target: any, schemaObj: object) {
 }
 
 describe('schema', () => {
+  describe('when schema defines unknown format', () => {
+    const testSchema = {
+      type: 'string',
+      format: 'ISO-3166-1 alpha-2',
+    };
+
+    beforeEach(() => {
+      jest.spyOn(console, 'warn');
+    });
+
+    afterEach(() => {
+      jest.restoreAllMocks();
+    });
+
+    test('does not log a warning in the console', () => {
+      const input = 'some string';
+      expect(runSchema(input, testSchema)).toEqual([]);
+      expect(console.warn).not.toHaveBeenCalled();
+    });
+  });
+
   describe('when schema defines a simple array', () => {
     const testSchema = {
       type: 'array',