Skip to content

Commit

Permalink
update format in schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostrider-05 committed Oct 18, 2024
1 parent f1efb9e commit 467e503
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 78 deletions.
8 changes: 8 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ export default [
jsdoc,
},
rules: {
'jsdoc/check-tag-names': [
'warn',
{
definedTags: [
'format',
]
}
],
'no-trailing-spaces': [
'error'
],
Expand Down
50 changes: 8 additions & 42 deletions src/schemas/v2/api/components/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PatreonWebhookTrigger, Type } from '../../../../v2'
import { getJsDocDescription, getTypes } from '../../scripts/shared'
import { getJsDocDescription, getJsDocTags, getTypes } from '../../scripts/shared'

interface ResourceSchemaOptions<T extends string> {
schemas: T[]
Expand All @@ -8,14 +8,13 @@ interface ResourceSchemaOptions<T extends string> {
interfaceName: string
fileName: string
documentation: Record<'description' | 'url', string>
formatMap?: Record<string, 'uri' | 'date-time'>
}
}

// eslint-disable-next-line jsdoc/require-jsdoc
function createResourceSchemas <T extends string> (options: ResourceSchemaOptions<T>) {
return options.schemas.reduce((schemas, schema) => {
const { documentation, fileName, interfaceName, formatMap } = options.getDetails(schema)
const { documentation, fileName, interfaceName } = options.getDetails(schema)

const declaration = getTypes(`${options.folder}${fileName}.ts`)
.getInterfaceOrThrow(interfaceName)
Expand All @@ -31,10 +30,8 @@ function createResourceSchemas <T extends string> (options: ResourceSchemaOption
const type = property.getType().getNonNullableType(), nullType = 'null'
const nullable = property.getType().isNullable()
const baseType = type.getBaseTypeOfLiteralType().getText()
const format = formatMap?.[property.getName()]
const examples = property.getJsDocs().at(0)?.getTags()
.filter(tag => tag.getTagName() === 'example')
.map(tag => tag.getCommentText())
const format = getJsDocTags(property, 'format')?.at(0)
const examples = getJsDocTags(property, 'example')

return {
...properties,
Expand All @@ -55,7 +52,10 @@ function createResourceSchemas <T extends string> (options: ResourceSchemaOption
),
...(format != undefined ? { format } : {}),
description: getJsDocDescription(property),
...(examples != undefined && examples.length ? { examples: examples } : {}),
...(examples != undefined && examples.length
? { examples: baseType === 'number' ? examples.map(Number) : examples }
: {}
),
}
}
}, {})
Expand Down Expand Up @@ -83,40 +83,6 @@ export default {
description: `Official documentation for the ${interfaceName} resource`,
url: `https://docs.patreon.com/#${header}`
},
// TODO: temperary solution to use this map
formatMap: {
'created_at': 'date-time',
'next_deliverable_due_date': 'date-time',
'completed_at': 'date-time',
'due_at': 'date-time',
'reached_at': 'date-time',
'upload_expires_at': 'date-time',
'last_charge_date': 'date-time',
'next_charge_date': 'date-time',
'pledge_relationship_start': 'date-time',
'published_at': 'date-time',
'edited_at': 'date-time',
'date': 'date-time',
'unpublished_at': 'date-time',
'created': 'date-time',
'last_attempted_at': 'date-time',
'image_small_url': 'uri',
'image_url': 'uri',
'main_video_url': 'uri',
// Campaign.pledge_url is relative, so not typed as uri
'rss_artwork_url': 'uri',
'thanks_video_url': 'uri',
'download_url': 'uri',
'upload_url': 'uri',
'icon_url': 'uri',
'privacy_policy_url': 'uri',
// 'redirect_uris': 'uri',
'tos_url': 'uri',
'embed_url': 'uri',
'url': 'uri',
'thumb_url': 'uri',
'uri': 'uri',
}
}
}
}),
Expand Down
57 changes: 36 additions & 21 deletions src/schemas/v2/generated/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,7 @@
"address": {
"type": "object",
"title": "Address",
"description": "",
"description": "A patron's shipping address.",
"externalDocs": {
"description": "Official documentation for the Address resource",
"url": "https://docs.patreon.com/#address"
Expand Down Expand Up @@ -2569,7 +2569,7 @@
"benefit": {
"type": "object",
"title": "Benefit",
"description": "",
"description": "A benefit added to the campaign, which can be added to a tier to be delivered to the patron.",
"externalDocs": {
"description": "Official documentation for the Benefit resource",
"url": "https://docs.patreon.com/#benefit"
Expand Down Expand Up @@ -2832,7 +2832,7 @@
"client": {
"type": "object",
"title": "OauthClient",
"description": "",
"description": "A client created by a developer, used for getting OAuth2 access tokens.",
"externalDocs": {
"description": "Official documentation for the OauthClient resource",
"url": "https://docs.patreon.com/#oauthclient"
Expand Down Expand Up @@ -2862,6 +2862,7 @@
"string",
"null"
],
"format": "uri",
"description": "The domain provided during client setup."
},
"icon_url": {
Expand Down Expand Up @@ -2895,14 +2896,17 @@
},
"version": {
"type": "number",
"description": "The Patreon API version the client is targeting."
"description": "The Patreon API version the client is targeting.",
"examples": [
2
]
}
}
},
"deliverable": {
"type": "object",
"title": "Deliverable",
"description": "",
"description": "The record of whether or not a patron has been delivered the benefit they are owed because of their member tier.",
"externalDocs": {
"description": "Official documentation for the Deliverable resource",
"url": "https://docs.patreon.com/#deliverable"
Expand Down Expand Up @@ -2945,7 +2949,7 @@
"media": {
"type": "object",
"title": "Media",
"description": "",
"description": "A file uploaded to patreon.com, usually an image.",
"externalDocs": {
"description": "Official documentation for the Media resource",
"url": "https://docs.patreon.com/#media"
Expand All @@ -2963,7 +2967,7 @@
},
"file_name": {
"type": "string",
"description": ""
"description": "File name."
},
"image_urls": {
"type": "object",
Expand Down Expand Up @@ -3019,7 +3023,7 @@
"member": {
"type": "object",
"title": "Member",
"description": "",
"description": "The record of a user's membership to a campaign.\nRemains consistent across months of pledging.",
"externalDocs": {
"description": "Official documentation for the Member resource",
"url": "https://docs.patreon.com/#member"
Expand Down Expand Up @@ -3104,7 +3108,7 @@
"type": "number",
"description": "Number of months between charges\n\nNote: this will be `1` if Campaign.is_monthly is `true`",
"examples": [
"1"
1
]
},
"pledge_relationship_start": {
Expand All @@ -3119,15 +3123,15 @@
"type": "number",
"description": "The amount in cents the user will pay at the next pay cycle",
"examples": [
"500"
500
]
}
}
},
"post": {
"type": "object",
"title": "Post",
"description": "",
"description": "Content posted by a creator on a campaign page.",
"externalDocs": {
"description": "Official documentation for the Post resource",
"url": "https://docs.patreon.com/#post-v2"
Expand Down Expand Up @@ -3215,15 +3219,18 @@
"pledge-event": {
"type": "object",
"title": "PledgeEvent",
"description": "",
"description": "The record of a pledging action taken by the user, or that action's failure.",
"externalDocs": {
"description": "Official documentation for the PledgeEvent resource",
"url": "https://docs.patreon.com/#pledge-event"
},
"properties": {
"amount_cents": {
"type": "number",
"description": "Amount (in the currency in which the patron paid) of the underlying event"
"description": "Amount (in the currency in which the patron paid) of the underlying event",
"examples": [
500
]
},
"currency_code": {
"type": "string",
Expand Down Expand Up @@ -3269,14 +3276,14 @@
"pledge_delete",
"subscription"
],
"description": ""
"description": "Event type."
}
}
},
"tier": {
"type": "object",
"title": "Tier",
"description": "",
"description": "A membership level on a campaign, which can have benefits attached to it.",
"externalDocs": {
"description": "Official documentation for the Tier resource",
"url": "https://docs.patreon.com/#tier"
Expand Down Expand Up @@ -3375,7 +3382,7 @@
"user": {
"type": "object",
"title": "User",
"description": "",
"description": "The Patreon user, which can be both patron and creator.",
"externalDocs": {
"description": "Official documentation for the User resource",
"url": "https://docs.patreon.com/#user-v2"
Expand All @@ -3402,14 +3409,15 @@
},
"email": {
"type": "string",
"format": "email",
"description": "The user's email address.\nRequires certain scopes to access.\nSee the scopes section of the documentation"
},
"first_name": {
"type": [
"string",
"null"
],
"description": ""
"description": "First name."
},
"full_name": {
"type": "string",
Expand All @@ -3436,7 +3444,7 @@
"string",
"null"
],
"description": ""
"description": "Last name."
},
"like_count": {
"type": "number",
Expand Down Expand Up @@ -3468,7 +3476,7 @@
"webhook": {
"type": "object",
"title": "Webhook",
"description": "",
"description": "Webhooks are fired based on events happening on a particular campaign.",
"externalDocs": {
"description": "Official documentation for the Webhook resource",
"url": "https://docs.patreon.com/#webhook"
Expand All @@ -3481,7 +3489,11 @@
},
"num_consecutive_times_failed": {
"type": "number",
"description": "Number of times the webhook has failed consecutively, when in an error state."
"description": "Number of times the webhook has failed consecutively, when in an error state.",
"examples": [
0,
2
]
},
"paused": {
"type": "boolean",
Expand All @@ -3501,7 +3513,10 @@
"uri": {
"type": "string",
"format": "uri",
"description": "Fully qualified uri where webhook will be sent (e.g. https://www.example.com/webhooks/incoming)."
"description": "Fully qualified uri where webhook will be sent",
"examples": [
"'https://www.example.com/webhooks/incoming'"
]
}
}
},
Expand Down
6 changes: 5 additions & 1 deletion src/schemas/v2/resources/address.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* A patron's shipping address.
*/
export interface Address {
/**
* Full recipient name
Expand All @@ -16,6 +19,7 @@ export interface Address {

/**
* Datetime address was first created
* @format date-time
*/
created_at: string

Expand Down Expand Up @@ -43,4 +47,4 @@ export interface Address {
* State or province name
*/
state: string | null
}
}
7 changes: 6 additions & 1 deletion src/schemas/v2/resources/benefit.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* A benefit added to the campaign, which can be added to a tier to be delivered to the patron.
*/
export interface Benefit {
/**
* The third-party external ID this reward is associated with
Expand All @@ -16,6 +19,7 @@ export interface Benefit {

/**
* Datetime this benefit was created
* @format date-time
*/
created_at: string

Expand Down Expand Up @@ -51,6 +55,7 @@ export interface Benefit {

/**
* The next due date (after EOD today) for this benefit
* @format date-time
*/
next_deliverable_due_date: string | null

Expand All @@ -73,4 +78,4 @@ export interface Benefit {
* Display title
*/
title: string
}
}
Loading

0 comments on commit 467e503

Please sign in to comment.