Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spicy-beers-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ucdjs/fetch": minor
---

feat: add fetch client
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- changed-files:
- any-glob-to-any-file: packages/utils/**

"pkg: fetch":
- changed-files:
- any-glob-to-any-file: packages/fetch/**

"pkg: schema-gen":
- changed-files:
- any-glob-to-any-file: packages/schema-gen/**
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-preview.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: deploy to production
name: deploy to preview

on:
workflow_dispatch:
Expand Down
201 changes: 2 additions & 199 deletions apps/api/.spectral.yml
Original file line number Diff line number Diff line change
@@ -1,199 +1,2 @@
extends: [[spectral:oas, all], [spectral:asyncapi, all]]
rules:
operation-tags: off
operation-operationId: off
operation-success-response: error

# ----------------------------#
# UCD.js OAS v2.0, v3.0 rules #
# ----------------------------#

ucdjs-paths-kebab-case:
description: All YAML/JSON paths MUST follow kebab-case
severity: warn
recommended: true
message: "{{property}} is not kebab-case: {{error}}"
given: $.paths[*]~
then:
function: pattern
functionOptions:
match: "^\/([a-z0-9]+(-[a-z0-9]+)*)?(\/[a-z0-9]+(-[a-z0-9]+)*|\/{.+})*$" # doesn't allow /asasd{asdas}sadas pattern or not closed braces

ucdjs-path-parameters-camelCase-alphanumeric:
description: Path parameters MUST follow camelCase
severity: warn
recommended: true
message: "{{property}} path parameter is not camelCase: {{error}}"
given: $..parameters[?(@.in == 'path')].name
then:
function: pattern
functionOptions:
match: "^[a-z][a-zA-Z0-9]+$"

ucdjs-definitions-camelCase-alphanumeric:
description: All YAML/JSON definitions MUST follow fields-camelCase and be ASCII alphanumeric characters or `_` or `$`.
severity: error
recommended: true
message: "{{property}} MUST follow camelCase and be ASCII alphanumeric characters or `_` or `$`."
given: $.definitions[*]~
then:
function: pattern
functionOptions:
match: "/^[a-z$_]{1}[A-Z09$_]*/"

ucdjs-properties-camelCase-alphanumeric:
description: All JSON Schema properties MUST follow fields-camelCase and be ASCII alphanumeric characters or `_` or `$`.
severity: error
recommended: true
message: "{{property}} MUST follow camelCase and be ASCII alphanumeric characters or `_` or `$`."
given: $.definitions..properties[*]~
then:
function: pattern
functionOptions:
match: "/^[a-z$_]{1}[A-Z09$_]*/"

ucdjs-request-GET-no-body:
description: "A 'GET' request MUST NOT accept a 'body` parameter"
severity: error
given: $.paths..get.parameters..in
then:
function: pattern
functionOptions:
notMatch: /^body$/

ucdjs-headers-no-x-headers:
description: "All 'HTTP' headers SHOULD NOT include 'X-' headers (https://tools.ietf.org/html/rfc6648)."
severity: warn
given: "$..parameters[?(@.in == 'header')].name"
message: "HTTP headers SHOULD NOT include 'X-' prefix."
recommended: true
type: style
then:
function: pattern
functionOptions:
notMatch: "/^(x|X)-/"

ucdjs-headers-hyphenated-pascal-case:
description: All `HTTP` headers MUST use `Hyphenated-Pascal-Case` notation
severity: error
given: "$..parameters[?(@.in == 'header')].name"
message: "'HTTP' headers MUST follow 'Hyphenated-Pascal-Case' notation"
recommended: true
type: style
then:
function: pattern
functionOptions:
match: "/^([A-Z][a-z0-9]-)*([A-Z][a-z0-9])+/"

# ----------------------#
# UCD.js OAS v2.0 rules #
# ----------------------#

ucdjs-oas2-protocol-https-only:
description: ALL requests MUST go through `https` protocol only
formats:
- oas2
recommended: true
severity: error
type: style
message: Schemes MUST be https and no other value is allowed.
given: $
then:
field: schemes
function: schema
functionOptions:
schema:
type: array
items:
type: string
enum: [https]
maxItems: 1

ucdjs-oas2-request-support-json:
description: Every request SHOULD support `application/json` media type
formats:
- oas2
severity: warn
message: "{{description}}: {{error}}"
recommended: true
given: $..consumes
then:
function: schema
functionOptions:
schema:
type: array
contains:
type: string
enum:
- application/json

ucdjs-oas2-example-exists-in-parameters:
description: All models MUST have a valid example.
severity: error
recommended: true
formats:
- oas2
message: "{{ property }} MUST have a valid example."
given: "$..parameters..[?(@.in == 'body' && (@.example || @.schema.$ref))]"
then:
function: truthy

ucdjs-oas2-response-error-problem: # schemas and/or produces
description: All error responses MUST be of media type `application/problem+json`
severity: error
formats:
- oas2
given: $.paths..responses[?( @property >= 400 && @property < 600 )]
recommended: true
type: style
message: "Error response document MUST follow application/problem+json: {{error}}"
then:
field: schema.example
function: schema
functionOptions:
schema:
title: Problem Details for HTTP APIs
description: Definition of [RFC7807](https://tools.ietf.org/html/rfc7807) problem detail
type: object
properties:
type:
type: string
title:
type: string
status:
type: number
detail:
type: string
instance:
type: string
required:
- title
- detail

# ----------------------#
# UCD.js OAS v3.0 rules #
# ----------------------#

ucdjs-oas3-request-support-json:
description: Every request MUST support `application/json` media type
formats:
- oas3
recommended: true
severity: error
message: "{{description}}: {{error}}"
given: $.paths.[*].requestBody.content[?(@property.indexOf('json') === -1)]^
then:
function: falsy

ucdjs-oas3-protocol-https-only:
description: ALL requests MUST go through `https` protocol only
formats:
- oas3
recommended: true
severity: error
message: Servers MUST be https and no other protocol is allowed.
given: $.servers..url
then:
function: pattern
functionOptions:
match: "/^https:/"
extends:
- "@luxass/spectral-ruleset"
2 changes: 2 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
"dependencies": {
"@hono/zod-openapi": "catalog:workers",
"@luxass/unicode-utils-new": "catalog:prod",
"@luxass/utils": "catalog:prod",
"@scalar/hono-api-reference": "catalog:workers",
"hono": "catalog:workers",
"zod": "catalog:prod"
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "catalog:testing",
"@luxass/eslint-config": "catalog:linting",
"@luxass/spectral-ruleset": "catalog:linting",
"@stoplight/spectral-cli": "catalog:linting",
"eslint": "catalog:linting",
"eslint-plugin-format": "catalog:linting",
Expand Down
8 changes: 7 additions & 1 deletion apps/api/src/openapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { OpenAPIHono } from "@hono/zod-openapi";
import { dedent } from "@luxass/utils";

export type OpenAPIObjectConfig = Parameters<OpenAPIHono["getOpenAPI31Document"]>[0];

Expand Down Expand Up @@ -27,7 +28,12 @@ export function buildOpenApiConfig(version: string, servers: NonNullable<OpenAPI
},
{
name: "Unicode Proxy",
description: "Endpoints for proxying requests to unicode-proxy.ucdjs.dev.",
description: dedent`
Endpoints for proxying requests to unicode-proxy.ucdjs.dev.

Just call the single endpoint with the path you want to proxy, and don't think about there being any other endpoints.
This is a fix for OpenAPI not supporting splat routes.
`,
},
],
servers,
Expand Down
Loading
Loading