Skip to content

Commit

Permalink
Update Schema
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanoverna committed Aug 26, 2024
1 parent 20bc4ff commit 61e4957
Show file tree
Hide file tree
Showing 10 changed files with 713 additions and 104 deletions.
22 changes: 12 additions & 10 deletions generate/extractInfoFromSchema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import JsonRefParser, {
type JSONSchema,
} from '@apidevtools/json-schema-ref-parser';
import * as JsonRefParser from '@apidevtools/json-schema-ref-parser';
import fetch from 'cross-fetch';
import { compile as hyperschemaToTypings } from 'hyperschema-to-ts';
import simplifySchema from './generateSimplifiedSchema';
Expand Down Expand Up @@ -67,21 +65,25 @@ type JSONHyperschemaLink = {
title: string;
href: string;
private?: boolean;
hrefSchema?: JSONSchema;
schema?: JSONSchema;
targetSchema?: JSONSchema;
jobSchema?: JSONSchema;
hrefSchema?: JsonRefParser.JSONSchema;
schema?: JsonRefParser.JSONSchema;
targetSchema?: JsonRefParser.JSONSchema;
jobSchema?: JsonRefParser.JSONSchema;
};

type JSONSchemaWithLinks = JSONSchema & { links: JSONHyperschemaLink[] };
type JSONSchemaWithLinks = JsonRefParser.JSONSchema & {
links: JSONHyperschemaLink[];
};

const relToMethodName: Record<string, string> = {
instances: 'list',
self: 'find',
me: 'findMe',
};

function hasLinks(schema: JSONSchema): schema is JSONSchemaWithLinks {
function hasLinks(
schema: JsonRefParser.JSONSchema,
): schema is JSONSchemaWithLinks {
return 'links' in schema;
}

Expand Down Expand Up @@ -261,7 +263,7 @@ function findPropertiesInDataProperty(
function generateResourceInfo(
isCma: boolean,
jsonApiType: string,
schema: JSONSchema,
schema: JsonRefParser.JSONSchema,
): ResourceInfo {
if (!hasLinks(schema)) {
throw new Error('Missing links!');
Expand Down
76 changes: 53 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Stefano Verna <[email protected]>",
"license": "MIT",
"devDependencies": {
"@apidevtools/json-schema-ref-parser": "^9.0.9",
"@apidevtools/json-schema-ref-parser": "^11.7.0",
"@biomejs/biome": "1.8.3",
"@total-typescript/ts-reset": "^0.5.1",
"@types/jest": "^29.5.6",
Expand Down
31 changes: 29 additions & 2 deletions packages/cma-client/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -3008,7 +3008,8 @@
"http_basic_password",
"enabled",
"payload_api_version",
"nested_items_in_payload"
"nested_items_in_payload",
"auto_retry"
],
"relationships": []
},
Expand Down Expand Up @@ -3051,7 +3052,8 @@
"http_basic_password",
"enabled",
"payload_api_version",
"nested_items_in_payload"
"nested_items_in_payload",
"auto_retry"
],
"relationships": []
},
Expand Down Expand Up @@ -3150,6 +3152,31 @@
"name": "list",
"rawName": "rawList"
},
{
"returnsCollection": false,
"docUrl": "https://www.datocms.com/docs/content-management-api/resources/webhook-call/self",
"rel": "self",
"urlTemplate": "/webhook_calls/${webhookCallId}",
"method": "GET",
"comment": "Retrieve a webhook call",
"urlPlaceholders": [
{
"variableName": "webhookCallId",
"isEntityId": true,
"relType": "WebhookCallData"
}
],
"entityIdPlaceholder": {
"variableName": "webhookCallId",
"isEntityId": true,
"relType": "WebhookCallData"
},
"optionalRequestBody": false,
"queryParamsRequired": false,
"responseType": "WebhookCallSelfTargetSchema",
"name": "find",
"rawName": "rawFind"
},
{
"returnsCollection": false,
"docUrl": "https://www.datocms.com/docs/content-management-api/resources/webhook-call/resend_webhook",
Expand Down
Loading

0 comments on commit 61e4957

Please sign in to comment.