nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: glennjones/hapi-swagger
Pull request #402 (2017-03-06 16:41:37)

Disable dropdown for a property in UI via meta
Joi.allow() creates a valid list that results on dropdown in Swagger
docs UI. This is not expected in many cases and here we add
`disableDropdown` meta property for those.

One example that is used in tests is non-negative integers that could
not be edited in swagger UI forms:

    Joi.number().integer().positive().allow(0)

Only by adding `.meta({disableDropdown: true})` one could make this
editable as a form field.

Let me know if there is a better way to achieve this or the PR needs changes.


Patch:
diff --git a/.gitignore b/.gitignore
index a89d9c2..977ec22 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,5 +17,6 @@ npm-debug.log
 .DS_Store
 .vscode
 .coveralls.yml
+.idea
 
 test/certs/server.csr
\ No newline at end of file
diff --git a/lib/properties.js b/lib/properties.js
index 4771178..abc9a2f 100644
--- a/lib/properties.js
+++ b/lib/properties.js
@@ -111,7 +111,8 @@ internals.properties.prototype.parseProperty = function (name, joiObj, parent, p
 
     // add enum
     let describe = joiObj.describe();
-    if (Array.isArray(describe.valids) && describe.valids.length) {
+    const allowDropdown = !property['x-meta'] || !property['x-meta'].disableDropdown;
+    if (allowDropdown && Array.isArray(describe.valids) && describe.valids.length) {
         // fliter out empty values and arrays
         var enums = describe.valids.filter((item) => {
 


Test patch:
diff --git a/test/unit/property-test.js b/test/unit/property-test.js
index efde105..3d5895e 100644
--- a/test/unit/property-test.js
+++ b/test/unit/property-test.js
@@ -106,6 +106,12 @@ lab.experiment('property - ', () => {
         expect(propertiesNoAlt.parseProperty('x', Joi.date().timestamp().default(() => Date.now(), 'Current Timestamp')).default).to.exist();
         //console.log(JSON.stringify(propertiesAlt.parseProperty('x',Joi.date().timestamp().default(() => Date.now(), 'Current Timestamp'))));
 
+        const nonNegativeWithDropdown = propertiesAlt.parseProperty('x', Joi.number().integer().positive().allow(0), null, 'body', true, false);
+        const nonNegativeWithoutDropdown = propertiesAlt.parseProperty('x', Joi.number().integer().positive().allow(0).meta({disableDropdown: true}), null, 'body', true, false);
+
+        expect(nonNegativeWithDropdown).to.include({ enum: [0] });
+        expect(nonNegativeWithoutDropdown).to.not.include({ enum: [0] });
+
         done();
     });
Repository: glennjones/hapi-swagger
Pull request #548 (2018-11-28 06:17:39)

Allow user to add x-* outside of info object
Allow user to add x-* outside of info object


Patch:
diff --git a/lib/builder.js b/lib/builder.js
index e30a36d..d0b0ebf 100644
--- a/lib/builder.js
+++ b/lib/builder.js
@@ -54,7 +54,7 @@ builder.schema = Joi.object({
         expiresAt: Joi.string(),
         generateTimeout: Joi.number()
     })
-});
+}).pattern(/^x-/, Joi.any());
 
 /**
  * gets the Swagger JSON


Test patch:
diff --git a/test/Integration/builder-test.js b/test/Integration/builder-test.js
index a78e398..4f6d90e 100644
--- a/test/Integration/builder-test.js
+++ b/test/Integration/builder-test.js
@@ -82,7 +82,8 @@ lab.experiment('builder', () => {
             'externalDocs': {
                 'description': 'Find out more about HAPI',
                 'url': 'http://hapijs.com'
-            }
+            },
+            'x-custom': 'custom'
         };
 
         const server = await Helper.createServer(swaggerOptions, routes);
@@ -95,6 +96,7 @@ lab.experiment('builder', () => {
         expect(response.result.consumes).to.equal(['application/x-www-form-urlencoded']);
         expect(response.result.produces).to.equal(['application/json', 'application/xml']);
         expect(response.result.externalDocs).to.equal(swaggerOptions.externalDocs);
+        expect(response.result['x-custom']).to.equal('custom');
         const isValid = await Validate.test(response.result);
         expect(isValid).to.be.true();
Repository: glennjones/hapi-swagger
Pull request #562 (2019-02-10 16:18:14)

Add support for multihop proxy headers.
Pull first (orginating) entry out of host and proto forwarding headers.


Patch:
diff --git a/lib/builder.js b/lib/builder.js
index d0b0ebf..82b3cbf 100644
--- a/lib/builder.js
+++ b/lib/builder.js
@@ -140,6 +140,18 @@ builder.dereference = async (schema) => {
     }
 };
 
+/**
+ * return originating value for an `x-forwarded` header
+ * @param {Object} request
+ * @param {String} name header name (without x-forwarded prefix)
+ * @return {String}
+ */
+internals.getProxyHeader = function(request, name) {
+    const header = request.headers['x-forwarded-' + name];
+
+    return header ? header.split(',')[0] : undefined;
+};
+
 /**
  * finds the current host
  *
@@ -147,7 +159,7 @@ builder.dereference = async (schema) => {
  * @return {String}
  */
 internals.getHost = function(request) {
-    const proxyHost = request.headers['x-forwarded-host'] || request.headers['disguised-host'] || '';
+    const proxyHost = internals.getProxyHeader(request, 'host') || request.headers['disguised-host'] || '';
     if (proxyHost) {
         return proxyHost;
     }
@@ -179,7 +191,7 @@ internals.getHost = function(request) {
  * @return {String}
  */
 internals.getSchema = function(request) {
-    const forwardedProtocol = request.headers['x-forwarded-proto'];
+    const forwardedProtocol = internals.getProxyHeader(request, 'proto');
 
     if (forwardedProtocol) {
         return forwardedProtocol;


Test patch:
diff --git a/test/Integration/proxy-test.js b/test/Integration/proxy-test.js
index 9edcf36..c9b1106 100644
--- a/test/Integration/proxy-test.js
+++ b/test/Integration/proxy-test.js
@@ -80,6 +80,40 @@ lab.experiment('proxies', () => {
     });
 
 
+    lab.test('x-forwarded options', async() => {
+
+        const options = {};
+
+        requestOptions.headers = {
+            'x-forwarded-host': 'proxyhost',
+            'x-forwarded-proto': 'https'
+        };
+
+        const server = await Helper.createServer(options, routes);
+        const response = await server.inject(requestOptions);
+        expect(response.result.host).to.equal(requestOptions.headers['x-forwarded-host']);
+        expect(response.result.schemes).to.equal(['https']);
+
+    });
+
+
+    lab.test('multi-hop x-forwarded options', async() => {
+
+        const options = {};
+
+        requestOptions.headers = {
+            'x-forwarded-host': 'proxyhost,internalproxy',
+            'x-forwarded-proto': 'https,http'
+        };
+
+        const server = await Helper.createServer(options, routes);
+        const response = await server.inject(requestOptions);
+        expect(response.result.host).to.equal('proxyhost');
+        expect(response.result.schemes).to.equal(['https']);
+
+    });
+
+
     lab.test('Azure Web Sites options', async() => {
 
         const options = {};
Repository: glennjones/hapi-swagger
Pull request #597 (2019-06-13 07:29:57)

feat: add support for additional properties in object schemas
This PR adds `additionalProperties` keyword on the generated schema, when Joi object is created with `unkown(false)` option


Patch:
diff --git a/lib/properties.js b/lib/properties.js
index 624f71c..5f33cef 100644
--- a/lib/properties.js
+++ b/lib/properties.js
@@ -156,6 +156,11 @@ internals.properties.prototype.parseProperty = function(name, joiObj, parent, pa
         };
       }
     }
+
+    const allowUnknown = joiObj._flags.allowUnknown;
+    if (allowUnknown !== undefined && !allowUnknown) {
+      property.additionalProperties = false;
+    }
   }
 
   // add array properties


Test patch:
diff --git a/test/unit/property-test.js b/test/unit/property-test.js
index 3b12b7b..baee0de 100644
--- a/test/unit/property-test.js
+++ b/test/unit/property-test.js
@@ -575,6 +575,7 @@ lab.test('parse type object', () => {
       }
     }
   });
+  expect(propertiesNoAlt.parseProperty('x', Joi.object().unknown(false), null, 'body', false, false)).to.equal({type: 'object', additionalProperties: false})
   expect(propertiesNoAlt.parseProperty('x', Joi.object({ a: Joi.string() }), null, 'body', false, false)).to.equal({
     name: 'x',
     type: 'object',
@@ -606,7 +607,7 @@ lab.experiment('property deep - ', () => {
         .max(10)
         .required()
         .label('inner2')
-    })
+    }).unknown(false)
   });
 
   //console.log(JSON.stringify( propertiesNoAlt.parseProperty( deepStructure, {}, {}, null, false ) ));
@@ -631,6 +632,7 @@ lab.experiment('property deep - ', () => {
           required: ['inner1']
         },
         outer2: {
+          additionalProperties: false,
           name: 'outer2',
           type: 'object',
           properties: {