nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: stephenh/ts-proto
Pull request #1046 (2024-05-24 18:50:30)

fix: camelToSnake to respect uppercase words, such as "GetAPIValue" -> "GET_API_VALUE"
## Problem
`camelToSnake()` is converting the example string "TestAPI" -> "TEST_AP_I" when converting a 3rd party integration proto files that I am attempting to generate with the Nest option. I believe that the conversion should respect the "API" part of the string and not split it into two parts like so. 

## Fix
I swapped the logic to use the already imported "case-anything" library's `snakeCase()` function as `snakeCaseAnything()` and added a couple of simple tests to ensure the logic.

I would love for this fix to go through as it is a pretty inconvenient problem at the moment (:

Thanks!

stephenh: Hi @BrandonArmand , thanks for the PR! Can you remove the `package-lock.json` and `yarn.lock` changes? Thanks!
stephenh: Fwiw my guess is that the build failures are because a dependency like ts-poet or prettier accidentally got unlocked/bumped to latest with the package-lock/yarn.lock changes.
BrandonArmand: Removed `package.lock` and reverted `yarn.lock`, and squashed the commits to cleanup the git logs regarding those changes.
stephenh: Looks great! Thanks!

Patch:
diff --git a/src/case.ts b/src/case.ts
index ae4f6b86..09e27041 100644
--- a/src/case.ts
+++ b/src/case.ts
@@ -1,4 +1,4 @@
-import { camelCase as camelCaseAnything } from "case-anything";
+import { camelCase as camelCaseAnything, snakeCase as snakeCaseAnything } from "case-anything";
 
 import { Options } from "./options";
 
@@ -24,7 +24,7 @@ export function snakeToCamel(s: string): string {
 }
 
 export function camelToSnake(s: string): string {
-  return s.replace(/\w([A-Z])/g, (m) => m[0] + "_" + m[1]).toUpperCase();
+  return snakeCaseAnything(s).toUpperCase();
 }
 
 export function capitalize(s: string): string {


Test patch:
diff --git a/tests/case-test.ts b/tests/case-test.ts
index f20a0a46..e9666926 100644
--- a/tests/case-test.ts
+++ b/tests/case-test.ts
@@ -1,4 +1,4 @@
-import { maybeSnakeToCamel, camelCaseGrpc } from "../src/case";
+import { maybeSnakeToCamel, camelCaseGrpc, camelToSnake } from "../src/case";
 import { Options, optionsFromParameter } from "../src/options";
 import { getFieldJsonName } from "../src/utils";
 
@@ -51,6 +51,14 @@ describe("case", () => {
     expect(camelCaseGrpc("GetAPIValue")).toEqual("getApiValue");
   });
 
+  it("converts simple string to snake case, getApiValue === GET_API_VALUE", () => {
+    expect(camelToSnake("GetApiValue")).toEqual("GET_API_VALUE");
+  });
+
+  it("converts string to snake case respecting word separation, getAPIValue === GET_API_VALUE", () => {
+    expect(camelToSnake("getAPIValue")).toEqual("GET_API_VALUE");
+  });
+
   describe("getFieldJsonName", () => {
     it("keeps snake case when jsonName is probably not set", () => {
       expect(getFieldJsonName({ name: "foo_bar", jsonName: "fooBar" }, { snakeToCamel: [], useJsonName: false })).toBe(
Repository: stoplightio/spectral
Pull request #2355 (2022-12-01 23:49:04)

fix(rulesets): length.min said "must not be longer than"
When the rule is minimum 20, if there is less than 20 characters it will say "must not be longer than 20". This removes the not, making minimum now correctly say "must be longer than 20".

**Checklist**

- [x] Tests added / updated
- [ ] Docs added / updated

**Does this PR introduce a breaking change?**

- [x] Yes
- [ ] No

Any change to a message could be considered breaking but this was broken already, so hopefully people arent programatically doing things on string responses.



philsturgeon: @P0lip I don't think we should block this on the grounds of consistency. Currently its literally incorrect.

Note that the rule is `if ('min' in opts && value < opts.min) {`

"must not be longer than"

If minimum is 5 characters, and you provide 4 characters, it will say: 

"foo must not be longer than 5 characters"

whiiiich is the opposite of what it means. It means

"foo must be longer than 5 characters"

Can we merge to fix this?
philsturgeon: @P0lip @mnaumanali94 this bug is holding up the Documentation ruleset, as right now it's saying "must not be longer than 20 characters" for a shorter than 20 characters description. I'll code the tests with the bug in place but somebody else will need to update that later.

Patch:
diff --git a/packages/functions/src/length.ts b/packages/functions/src/length.ts
index 05475834..0e576ab7 100644
--- a/packages/functions/src/length.ts
+++ b/packages/functions/src/length.ts
@@ -40,7 +40,7 @@ export default createRulesetFunction<unknown[] | Record<string, unknown> | strin
     if ('min' in opts && value < opts.min) {
       results = [
         {
-          message: `#{{print("property")}}must not be longer than ${printValue(opts.min)}`,
+          message: `#{{print("property")}}must be longer than ${printValue(opts.min)}`,
         },
       ];
     }


Test patch:
diff --git a/packages/functions/src/__tests__/length.test.ts b/packages/functions/src/__tests__/length.test.ts
index 173a5c1e..9e3fff23 100644
--- a/packages/functions/src/__tests__/length.test.ts
+++ b/packages/functions/src/__tests__/length.test.ts
@@ -35,7 +35,7 @@ describe('Core Functions / Length', () => {
     async input => {
       expect(await runLength(input, { min: 4 })).toEqual([
         {
-          message: 'The document must not be longer than 4',
+          message: 'The document must be longer than 4',
           path: [],
         },
       ]);
Repository: stoplightio/spectral
Pull request #2551 (2023-11-07 19:06:33)

feat(formats): jsonSchemaLoose format should search for enum keyword
Related to https://github.com/stoplightio/platform-internal/issues/18500

**Checklist**

- [x] Tests added / updated
- [ ] Docs added / updated

**Does this PR introduce a breaking change?**

- [ ] Yes
- [x] No




Patch:
diff --git a/packages/formats/src/jsonSchema.ts b/packages/formats/src/jsonSchema.ts
index 1cd63335..7c35401e 100644
--- a/packages/formats/src/jsonSchema.ts
+++ b/packages/formats/src/jsonSchema.ts
@@ -17,6 +17,8 @@ const hasValidJSONSchemaType = (document: Partial<{ type?: unknown }>): boolean
   return Array.isArray(document.type) && document.type.every(type => KNOWN_JSON_SCHEMA_TYPES.includes(type));
 };
 
+const hasValidJSONSchemaEnumKeyword = (document: Record<string, unknown>): boolean => Array.isArray(document['enum']);
+
 const hasValidJSONSchemaCompoundKeyword = (document: Record<string, unknown>): boolean =>
   KNOWN_JSON_SCHEMA_COMPOUND_KEYWORDS.some(
     combiner => combiner in document && typeof document[combiner] === 'object' && document[combiner] !== null,
@@ -43,7 +45,10 @@ export const jsonSchemaLoose: Format<Record<string, unknown>> = (
   document: unknown,
 ): document is Record<string, unknown> =>
   isPlainObject(document) &&
-  (isJsonSchema(document) || hasValidJSONSchemaType(document) || hasValidJSONSchemaCompoundKeyword(document));
+  (isJsonSchema(document) ||
+    hasValidJSONSchemaType(document) ||
+    hasValidJSONSchemaEnumKeyword(document) ||
+    hasValidJSONSchemaCompoundKeyword(document));
 
 jsonSchemaLoose.displayName = 'JSON Schema (loose)';
 


Test patch:
diff --git a/packages/formats/src/__tests__/jsonSchema.test.ts b/packages/formats/src/__tests__/jsonSchema.test.ts
index 9a185607..e9f648fe 100644
--- a/packages/formats/src/__tests__/jsonSchema.test.ts
+++ b/packages/formats/src/__tests__/jsonSchema.test.ts
@@ -80,6 +80,15 @@ describe('JSON Schema format', () => {
       expect(jsonSchemaLoose({ not: {} }, null)).toBe(true);
     });
 
+    it('recognizes by the presence of valid "enum"', () => {
+      expect(jsonSchemaLoose({ enum: ['1'] }, null)).toBe(true);
+      expect(jsonSchemaLoose({ enum: [] }, null)).toBe(true);
+
+      expect(jsonSchemaLoose({ enum: 2 }, null)).toBe(false);
+      expect(jsonSchemaLoose({ enum: {} }, null)).toBe(false);
+      expect(jsonSchemaLoose({ enum: null }, null)).toBe(false);
+    });
+
     describe('mixed', () => {
       it('invalid type but valid combiner', () => {
         expect(jsonSchemaLoose({ type: 'foo', allOf: [] }, null)).toBe(true);
Repository: stoplightio/spectral
Pull request #2625 (2024-05-24 16:54:59)

fix(rulesets): always allow string examples in asyncapi schema
Fixes https://github.com/stoplightio/spectral/issues/2624.

**Checklist**

- [x] Tests added / updated
- [x] (N/A) Docs added / updated (N/A)

**Does this PR introduce a breaking change?**

- [ ] Yes
- [x] No


mnaumanali94: @jonaslagoni @smoya Will you be able to review this anytime soon?
 
jonaslagoni: @mnaumanali94 feel free to merge 👍 
mnaumanali94: @jonaslagoni Thank you! I'm working on trying to fix the pipeline. There's something with a memory leak in node/jest. I'll merge some of the PRs then. 
jonaslagoni: All good @mnaumanali94 ✌️ 

Patch:
diff --git a/packages/rulesets/src/asyncapi/functions/asyncApi2SchemaValidation.ts b/packages/rulesets/src/asyncapi/functions/asyncApi2SchemaValidation.ts
index dc36f069..3fa907b0 100644
--- a/packages/rulesets/src/asyncapi/functions/asyncApi2SchemaValidation.ts
+++ b/packages/rulesets/src/asyncapi/functions/asyncApi2SchemaValidation.ts
@@ -67,7 +67,7 @@ export default createRulesetFunction<SchemaFragment, Options>(
         },
       );
 
-      if (Array.isArray(result)) {
+      if (Array.isArray(result) && typeof relevantItem.value !== 'string') {
         results.push(...result);
       }
     }


Test patch:
diff --git a/packages/rulesets/src/asyncapi/functions/__tests__/asyncApi2SchemaValidation.test.ts b/packages/rulesets/src/asyncapi/functions/__tests__/asyncApi2SchemaValidation.test.ts
index db2ef425..e4538dc5 100644
--- a/packages/rulesets/src/asyncapi/functions/__tests__/asyncApi2SchemaValidation.test.ts
+++ b/packages/rulesets/src/asyncapi/functions/__tests__/asyncApi2SchemaValidation.test.ts
@@ -7,19 +7,19 @@ function runPayloadValidation(targetVal: any, opts: { type: 'examples' | 'defaul
 describe('asyncApi2SchemaValidation', () => {
   test('validates examples', () => {
     const payload = {
-      type: 'string',
-      examples: [17, 'one', 13],
+      type: 'object',
+      examples: [17, {}, 13, 'string-is-always-accepted'],
     };
 
     const results = runPayloadValidation(payload, { type: 'examples' });
 
     expect(results).toEqual([
       {
-        message: '"0" property type must be string',
+        message: '"0" property type must be object',
         path: ['examples', 0],
       },
       {
-        message: '"2" property type must be string',
+        message: '"2" property type must be object',
         path: ['examples', 2],
       },
     ]);
Repository: stoplightio/spectral
Pull request #2663 (2024-08-02 11:40:38)

feat(formats): add arazzo format
add Arazzo format support

**Checklist**

- [x] Tests added / updated
- [x] Docs added / updated

**Does this PR introduce a breaking change?**

- [ ] Yes
- [x] No



Patch:
diff --git a/packages/formats/src/arazzo.ts b/packages/formats/src/arazzo.ts
new file mode 100644
index 00000000..787449e5
--- /dev/null
+++ b/packages/formats/src/arazzo.ts
@@ -0,0 +1,12 @@
+import type { Format } from '@stoplight/spectral-core';
+import { isPlainObject } from '@stoplight/json';
+
+type MaybeArazzo = { arazzo: unknown } & Record<string, unknown>;
+
+const arazzo1_0Regex = /^1\.0(?:\.[0-9]*)?$/;
+
+const isArazzo = (document: unknown): document is { arazzo: string } & Record<string, unknown> =>
+  isPlainObject(document) && 'arazzo' in document && arazzo1_0Regex.test(String((document as MaybeArazzo).arazzo));
+
+export const arazzo1_0: Format = isArazzo;
+arazzo1_0.displayName = 'Arazzo 1.0.x';
diff --git a/packages/formats/src/index.ts b/packages/formats/src/index.ts
index 0451e893..071d1ae4 100644
--- a/packages/formats/src/index.ts
+++ b/packages/formats/src/index.ts
@@ -1,3 +1,4 @@
 export * from './openapi';
 export * from './asyncapi';
 export * from './jsonSchema';
+export * from './arazzo';


Test patch:
diff --git a/packages/formats/src/__tests__/arazzo.test.ts b/packages/formats/src/__tests__/arazzo.test.ts
new file mode 100644
index 00000000..f9557463
--- /dev/null
+++ b/packages/formats/src/__tests__/arazzo.test.ts
@@ -0,0 +1,27 @@
+import { arazzo1_0 } from '../arazzo';
+
+describe('Arazzo format', () => {
+  describe('Arazzo 1.0.x', () => {
+    it.each(['1.0.0', '1.0', '1.0.1', '1.0.2', '1.0.99'])('recognizes %s version correctly', version => {
+      expect(arazzo1_0({ arazzo: version }, null)).toBe(true);
+    });
+
+    const testCases = [
+      { arazzo: '0.1' },
+      { arazzo: '1.1.0' },
+      { arazzo: '2' },
+      { arazzo: '2.0' },
+      { arazzo: '2.0.' },
+      { arazzo: '2.0.01' },
+      { arazzo: 2 },
+      { arazzo: null },
+      { arazzo: '4.0' },
+      {},
+      null,
+    ];
+
+    it.each(testCases)('does not recognize invalid document %o', document => {
+      expect(arazzo1_0(document, null)).toBe(false);
+    });
+  });
+});
Repository: stoplightio/spectral
Pull request #2812 (2025-04-23 09:58:44)

fix(functions): export or function
exports the `or` function so that it's accessible for core and cli


Patch:
diff --git a/packages/functions/src/index.ts b/packages/functions/src/index.ts
index 8f5e2e1c..c4f016fa 100644
--- a/packages/functions/src/index.ts
+++ b/packages/functions/src/index.ts
@@ -13,6 +13,7 @@ import {
   Options as UnreferencedReusableObjectOptions,
 } from './unreferencedReusableObject';
 import { default as xor, Options as XorOptions } from './xor';
+import { default as or, Options as OrOptions } from './or';
 
 export {
   alphabetical,
@@ -27,6 +28,7 @@ export {
   undefined,
   unreferencedReusableObject,
   xor,
+  or,
 };
 
 export type {
@@ -38,4 +40,5 @@ export type {
   SchemaOptions,
   UnreferencedReusableObjectOptions,
   XorOptions,
+  OrOptions,
 };


Test patch:
diff --git a/packages/ruleset-bundler/src/plugins/__tests__/builtins.spec.ts b/packages/ruleset-bundler/src/plugins/__tests__/builtins.spec.ts
index 79c12c3f..17743645 100644
--- a/packages/ruleset-bundler/src/plugins/__tests__/builtins.spec.ts
+++ b/packages/ruleset-bundler/src/plugins/__tests__/builtins.spec.ts
@@ -72,6 +72,7 @@ const truthy = globalThis[Symbol.for('@stoplight-spectral/builtins')]['822928'][
 const undefined$1 = globalThis[Symbol.for('@stoplight-spectral/builtins')]['822928']['@stoplight/spectral-functions']['undefined'];
 const unreferencedReusableObject = globalThis[Symbol.for('@stoplight-spectral/builtins')]['822928']['@stoplight/spectral-functions']['unreferencedReusableObject'];
 const xor = globalThis[Symbol.for('@stoplight-spectral/builtins')]['822928']['@stoplight/spectral-functions']['xor'];
+const or = globalThis[Symbol.for('@stoplight-spectral/builtins')]['822928']['@stoplight/spectral-functions']['or'];
 
 const oas = globalThis[Symbol.for('@stoplight-spectral/builtins')]['822928']['@stoplight/spectral-rulesets']['oas'];
 const asyncapi = globalThis[Symbol.for('@stoplight-spectral/builtins')]['822928']['@stoplight/spectral-rulesets']['asyncapi'];