swagger-tools/test/fixtures/openapi-31.yaml
rimskij 58c91615b9 feat: add OpenAPI 3.1 TypeScript generation support
- Handle type arrays: type: ['string', 'null'] → string | null
- Handle const keyword: const: "active" → 'active' literal type
- Handle nullable (OpenAPI 3.0 backward compatibility)
- Extract and display webhook count in metadata
- Add security escaping for string literals and JSDoc comments
- Add OpenAPI 3.1 test fixture and 12 unit tests

Fixes #365

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 21:20:13 +01:00

181 lines
3.8 KiB
YAML

openapi: 3.1.0
info:
title: OpenAPI 3.1 Test Spec
version: 1.0.0
description: Test fixture for OpenAPI 3.1 specific features
servers:
- url: https://api.example.com/v1
paths:
/users:
get:
operationId: listUsers
summary: List all users
tags:
- Users
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
post:
operationId: createUser
summary: Create a user
tags:
- Users
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/CreateUserRequest'
responses:
'201':
description: User created
/users/{id}:
get:
operationId: getUser
summary: Get a user by ID
tags:
- Users
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
'200':
description: Successful response
webhooks:
userCreated:
post:
operationId: userCreatedWebhook
summary: User created event
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UserEvent'
responses:
'200':
description: Webhook acknowledged
userDeleted:
post:
operationId: userDeletedWebhook
summary: User deleted event
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UserEvent'
responses:
'200':
description: Webhook acknowledged
components:
schemas:
# Test: type as array (OpenAPI 3.1)
NullableString:
type:
- string
- 'null'
description: A string that can be null (3.1 style)
# Test: multiple types in array
StringOrNumber:
type:
- string
- number
description: Can be either string or number
# Test: const keyword (OpenAPI 3.1)
StatusActive:
const: active
description: Always the literal value 'active'
StatusCode:
const: 200
description: Always the number 200
# Test: nullable with complex type
NullableInteger:
type:
- integer
- 'null'
# Test: object with nullable properties (3.1 style)
User:
type: object
required:
- id
- email
- status
properties:
id:
type: string
description: User ID
email:
type: string
format: email
name:
type:
- string
- 'null'
description: Optional name (can be null)
age:
type:
- integer
- 'null'
description: Optional age
status:
const: active
metadata:
type:
- object
- 'null'
description: Optional metadata
# Test: object with OpenAPI 3.0 style nullable (for backward compat)
LegacyUser:
type: object
properties:
id:
type: string
nickname:
type: string
nullable: true
description: Nickname (nullable 3.0 style)
CreateUserRequest:
type: object
required:
- email
properties:
email:
type: string
name:
type:
- string
- 'null'
UserEvent:
type: object
required:
- eventType
- userId
properties:
eventType:
type: string
userId:
type: string
timestamp:
type: string
format: date-time