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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</a>
</div>

TypeScript tooling for the [OpenAPI Specification](https://spec.openapis.org/), maintained by [middleapi](https://github.com/middleapi). It lets you work with OpenAPI 3.0, 3.1, and 3.2 documents from one place: precise types for each version, and converters that move a document from a newer version to an older one without losing anything the older version can still express.
TypeScript tooling for the [OpenAPI Specification](https://spec.openapis.org/), maintained by [middleapi](https://github.com/middleapi). It lets you work with OpenAPI 3.0, 3.1, and 3.2 documents from one place: precise types for each version, and small, fast converters that move a document from a newer version to an older one, covering what API frameworks such as [oRPC](https://orpc.dev) generate.

| Package | Description |
| --------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
Expand Down
204 changes: 94 additions & 110 deletions packages/downgrader/README.md

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions packages/downgrader/benches/__shared__/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type * as OpenAPIV3_2 from '@openapi-spec/types/v3.2'
// a few paths and a webhook per resource, around shared schemas, parameters,
// responses, and security schemes. It uses what each step has to rewrite:
// 3.1 schemas with `null` in `type`, `const`, numeric exclusive bounds,
// `examples`, `$defs`, and an `$id`; Path Items reused from
// `examples`, and `$defs`; Path Items reused from
// `components.pathItems`; webhooks; mutual TLS; and, in 3.2 only, `$self`,
// the `query` method, streamed `itemSchema`s, reusable Media Type Objects,
// Server `name`, Tag `summary`, `parent`, and `kind`, Response `summary`,
Expand Down Expand Up @@ -40,14 +40,13 @@ function sharedSchemas(): Record<string, OpenAPIV3_2.SchemaObject> {
default: 'active',
},
Address: {
$id: 'https://api.example.com/schemas/address',
type: 'object',
required: ['line1', 'country'],
properties: {
line1: { type: 'string' },
line2: { type: ['string', 'null'] },
postalCode: { type: 'string', pattern: '^[0-9A-Z -]{3,10}$' },
country: { $ref: '#/$defs/Country' },
country: schemaRef('Address/$defs/Country'),
},
$defs: {
Country: { type: 'string', minLength: 2, maxLength: 2, examples: ['US'] },
Expand Down
3 changes: 1 addition & 2 deletions packages/downgrader/benches/__shared__/graphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import type * as OpenAPIV3_2 from '@openapi-spec/types/v3.2'

// Small inputs that reach the same objects along exponentially many paths,
// or around cycles. Converting each object once keeps the work linear, so a
// regression here costs orders of magnitude, not percent. The tests that
// count this work are the ones named "... once".
// regression here costs orders of magnitude, not percent.

function info(): OpenAPIV3_2.InfoObject {
return { title: 'Graph', version: '1.0.0' }
Expand Down
8 changes: 7 additions & 1 deletion packages/downgrader/benches/chained.bench.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// There is no direct 3.2 → 3.0 converter: the two steps compose (see the
// package README), and this is what that costs end to end.
// package README), and this is what that costs end to end, as oRPC pays it
// for every 3.0 document it generates.

import type * as OpenAPIV3_2 from '@openapi-spec/types/v3.2'

import { downgradeSpecV31ToV30, downgradeSpecV32ToV31 } from '@openapi-spec/downgrader'
import { bench, describe } from 'vitest'
import { corpusV32 } from '../tests/corpus'
import { doc as orpcDocument } from '../tests/orpc-document'
import { createApiV32 } from './__shared__/api'

const API_100_RESOURCES = createApiV32(100)
Expand All @@ -21,6 +23,10 @@ describe('downgradeSpecV32ToV31 + downgradeSpecV31ToV30', () => {
}
})

bench('oRPC document', () => {
downgradeTwice(orpcDocument)
})

bench('generated api, 100 resources', () => {
downgradeTwice(API_100_RESOURCES)
})
Expand Down
Loading
Loading