Skip to content

Commit 46fec66

Browse files
authored
feat: always use superjson to serialize/deserialize in the api layer (#585)
1 parent 32c7279 commit 46fec66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+6441
-1518
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"author": "",
1515
"license": "MIT",
1616
"devDependencies": {
17-
"@changesets/cli": "^2.26.0"
17+
"@changesets/cli": "^2.26.0",
18+
"concurrently": "^7.4.0",
19+
"tsup": "^7.1.0"
1820
}
1921
}

packages/plugins/openapi/src/rest-generator.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,12 +536,16 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
536536
required: ['version'],
537537
properties: {
538538
version: { type: 'string' },
539-
meta: this.ref('_meta'),
540539
},
541540
},
542541
_meta: {
543542
type: 'object',
544-
description: 'Meta information about the response',
543+
description: 'Meta information about the request or response',
544+
properties: {
545+
serialization: {
546+
description: 'Superjson serialization metadata',
547+
},
548+
},
545549
additionalProperties: true,
546550
},
547551
_resourceIdentifier: {
@@ -759,14 +763,15 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
759763
required: ['data'],
760764
properties: {
761765
data: this.generateModelEntity(model, 'create'),
766+
meta: this.ref('_meta'),
762767
},
763768
};
764769

765770
result[`${model.name}UpdateRequest`] = {
766771
type: 'object',
767772
description: `Input for updating a "${model.name}"`,
768773
required: ['data'],
769-
properties: { data: this.generateModelEntity(model, 'update') },
774+
properties: { data: this.generateModelEntity(model, 'update'), meta: this.ref('_meta') },
770775
};
771776

772777
const relationships: Record<string, OAPI.ReferenceObject> = {};
@@ -790,7 +795,7 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
790795
type: 'object',
791796
properties: { relationships: { type: 'object', properties: relationships } },
792797
}),
793-
798+
meta: this.ref('_meta'),
794799
included: {
795800
type: 'array',
796801
items: this.ref('_resource'),
@@ -811,6 +816,7 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
811816
properties: { relationships: { type: 'object', properties: relationships } },
812817
})
813818
),
819+
meta: this.ref('_meta'),
814820
included: {
815821
type: 'array',
816822
items: this.ref('_resource'),
@@ -895,14 +901,17 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
895901
case 'BigInt':
896902
return { type: 'integer' };
897903
case 'Float':
898-
case 'Decimal':
899904
return { type: 'number' };
905+
case 'Decimal':
906+
return this.oneOf({ type: 'number' }, { type: 'string' });
900907
case 'Boolean':
901908
return { type: 'boolean' };
902909
case 'DateTime':
903910
return { type: 'string', format: 'date-time' };
911+
case 'Bytes':
912+
return { type: 'string', format: 'byte', description: 'Base64 encoded byte array' };
904913
case 'Json':
905-
return { type: 'object' };
914+
return {};
906915
default: {
907916
const fieldDecl = type.reference?.ref;
908917
invariant(fieldDecl);

0 commit comments

Comments
 (0)