Repository: fastify/fast-json-stringify (JavaScript)

Issue:
Cannot use 'in' operator to search for 'maxProperties' in true error while using Draft-07 official meta schema
### Prerequisites

- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported


### Fastify version

3.29.1

### Plugin version

_No response_

### Node.js version

14

### Operating system

macOS

### Operating system version (i.e. 20.04, 11.3, 10)

macOS Monterey 12.4

### Description

I'm trying to validate a route response that will return a properties JSON Schema that should be validated. I'm using the official Draft-07 JSON schema meta schema (https://json-schema.org/draft-07/schema), but when running fastify on this particular schema (see the repro repo below) I get this error:

```
FastifyError [Error]: Failed building the serialization schema for PATCH: /api/devices, due to error Cannot use 'in' operator to search for 'maxProperties' in true
    at Boot.<anonymous> (/Users/giovannibertoncelli/workspace/tbo/backend/node_modules/fastify/lib/route.js:325:19)
    at Object.onceWrapper (events.js:519:28)
    at Boot.emit (events.js:412:35)
    at /Users/giovannibertoncelli/workspace/tbo/backend/node_modules/avvio/boot.js:153:12
    at /Users/giovannibertoncelli/workspace/tbo/backend/node_modules/avvio/plugin.js:269:7
    at done (/Users/giovannibertoncelli/workspace/tbo/backend/node_modules/avvio/plugin.js:201:5)
    at check (/Users/giovannibertoncelli/workspace/tbo/backend/node_modules/avvio/plugin.js:225:9)
    at internal/process/task_queues.js:141:7
    at AsyncResource.runInAsyncScope (async_hooks.js:197:9)
    at AsyncResource.runMicrotask (internal/process/task_queues.js:138:8) {
```

I do not know what I'm doing wrong and I opened the issue here since it seems that the error is coming from this plugin.
I catched the original error and it's something like this:

```
TypeError: Cannot use 'in' operator to search for 'maxProperties' in true
    at inferTypeByKeyword (/Users/giovannibertoncelli/workspace/tbo/backend/node_modules/fast-json-stringify/index.js:198:17)
    at nested (/Users/giovannibertoncelli/workspace/tbo/backend/node_modules/fast-json-stringify/index.js:1169:26)
    at /Users/giovannibertoncelli/workspace/tbo/backend/node_modules/fast-json-stringify/index.js:774:22
    at Array.forEach (<anonymous>)
    at buildCode (/Users/giovannibertoncelli/workspace/tbo/backend/node_modules/fast-json-stringify/index.js:703:40)
    at buildCodeWithAllOfs (/Users/giovannibertoncelli/workspace/tbo/backend/node_modules/fast-json-stringify/index.js:846:23)
    at buildInnerObject (/Users/giovannibertoncelli/workspace/tbo/backend/node_modules/fast-json-stringify/index.js:857:18)
    at buildObject (/Users/giovannibertoncelli/workspace/tbo/backend/node_modules/fast-json-stringify/index.js:966:9)
    at nested (/Users/giovannibertoncelli/workspace/tbo/backend/node_modules/fast-json-stringify/index.js:1202:19)
    at /Users/giovannibertoncelli/workspace/tbo/backend/node_modules/fast-json-stringify/index.js:1288:3
```

### Steps to Reproduce

https://codesandbox.io/s/fastify-meta-schema-issue-copved?file=/src/metaschema.json

### Expected Behavior

It should run smoothly.


Discussion:
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.
@mcollina Sorry, I've no idea how to fix this...
You are looking for [@fastify/response-validation](https://github.com/fastify/fastify-response-validation)

fast-json-stringify is not a validator (it is a serializer) and it supports a Draft-7 subset.
So it won't throw an error when the schema is invalid, it will just ignore the unknown fields.

In any case, I think the metaschema should be supported by fjs, so there should be a bug here
Thank you @Eomm. Do you have by any chance some insights on this?



Patch:
diff --git a/index.js b/index.js
index 5be295ad..f26ee30b 100644
--- a/index.js
+++ b/index.js
@@ -772,6 +772,10 @@ function generateFuncName () {
 function buildValue (location, input) {
   let schema = location.schema
 
+  if (typeof schema === 'boolean') {
+    return `json += JSON.stringify(${input})`
+  }
+
   if (schema.$ref) {
     location = resolveRef(location, schema.$ref)
     schema = location.schema


Test patch:
diff --git a/test/basic.test.js b/test/basic.test.js
index a225a589..1c8f370c 100644
--- a/test/basic.test.js
+++ b/test/basic.test.js
@@ -359,3 +359,16 @@ test('render a single quote as JSON', (t) => {
   t.equal(output, JSON.stringify(toStringify))
   t.ok(validate(JSON.parse(output)), 'valid schema')
 })
+
+test('returns JSON.stringify if schema type is boolean', t => {
+  t.plan(1)
+
+  const schema = {
+    type: 'array',
+    items: true
+  }
+
+  const array = [1, true, 'test']
+  const stringify = build(schema)
+  t.equal(stringify(array), JSON.stringify(array))
+})