@unispechq/unispec-schema 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +170 -162
- package/examples/README.md +128 -0
- package/examples/invalid/config/additional-properties.json +26 -0
- package/examples/invalid/config/missing-service-name.json +22 -0
- package/examples/invalid/config/missing-version.json +6 -0
- package/examples/invalid/graphql-additional-properties.json +22 -0
- package/examples/invalid/graphql-missing-arg-type.json +26 -0
- package/examples/invalid/graphql-missing-name.json +19 -0
- package/examples/invalid/graphql-missing-schema.json +19 -0
- package/examples/invalid/mixed-invalid-protocol.json +26 -0
- package/examples/invalid/mixed-missing-graphql-schema.json +33 -0
- package/examples/invalid/mixed-multiple-errors.json +41 -0
- package/examples/invalid/rest-additional-properties.json +25 -0
- package/examples/invalid/rest-invalid-identifiers.json +29 -0
- package/examples/invalid/rest-invalid-method.json +23 -0
- package/examples/invalid/rest-missing-required.json +21 -0
- package/examples/invalid/websocket-additional-properties.json +27 -0
- package/examples/invalid/websocket-invalid-direction.json +27 -0
- package/examples/invalid/websocket-missing-channel-name.json +25 -0
- package/examples/invalid/websocket-missing-message-name.json +25 -0
- package/examples/valid/config/complete.json +61 -0
- package/examples/valid/config/minimal.json +8 -0
- package/examples/valid/graphql-complete.json +348 -0
- package/examples/valid/graphql-simple.json +34 -0
- package/examples/valid/mixed-complete.json +799 -0
- package/examples/valid/mixed-simple.json +56 -0
- package/examples/valid/rest-complete.json +539 -0
- package/examples/valid/rest-simple.json +279 -0
- package/examples/valid/websocket-complete.json +471 -0
- package/examples/valid/websocket-simple.json +116 -0
- package/index.cjs +7 -7
- package/index.d.ts +9 -9
- package/index.mjs +9 -9
- package/package.json +15 -6
- package/schema/index.json +19 -19
- package/schema/types/common.schema.json +195 -195
- package/schema/types/graphql.schema.json +172 -172
- package/schema/types/rest.schema.json +221 -226
- package/schema/types/schemas.schema.json +84 -84
- package/schema/types/service.schema.json +158 -158
- package/schema/types/websocket.schema.json +185 -190
- package/schema/unispec-config.schema.json +509 -509
- package/schema/unispec-tests.schema.json +368 -378
- package/schema/unispec.schema.json +18 -23
package/README.md
CHANGED
|
@@ -1,163 +1,171 @@
|
|
|
1
|
-
# UniSpec Specification
|
|
2
|
-
|
|
3
|
-
Official specification of the UniSpec API definition language
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
UniSpec is a modern, multi-protocol API specification format designed to unify REST, GraphQL, WebSocket, and event-driven API documentation under a single, consistent model.
|
|
8
|
-
|
|
9
|
-
This repository is the single source of truth for the UniSpec format.
|
|
10
|
-
It contains everything required to understand, validate, and evolve the language:
|
|
11
|
-
|
|
12
|
-
- Machine-readable JSON Schemas
|
|
13
|
-
- Human-readable reference documentation
|
|
14
|
-
- Official examples (REST, GraphQL, WebSocket, mixed APIs)
|
|
15
|
-
- A companion test specification (UniSpec Tests) for executable test documents
|
|
16
|
-
## Repository Structure
|
|
17
|
-
```pgsql
|
|
18
|
-
unispec-spec/
|
|
19
|
-
├─ schema/ # JSON Schemas defining the UniSpec format
|
|
20
|
-
│ ├─ unispec.schema.json # Core UniSpec document
|
|
21
|
-
│ ├─ unispec-tests.schema.json # UniSpec Tests document
|
|
22
|
-
│ ├─ unispec-config.schema.json # UniSpec Config document
|
|
23
|
-
│ └─ types/ # Shared schema types
|
|
24
|
-
│ ├─ common.schema.json # Common definitions
|
|
25
|
-
│ ├─ service.schema.json # Service definition
|
|
26
|
-
│ ├─ rest.schema.json # REST protocol
|
|
27
|
-
│ ├─ graphql.schema.json # GraphQL protocol
|
|
28
|
-
│ ├─ websocket.schema.json # WebSocket protocol
|
|
29
|
-
│ └─ schemas.schema.json # Reusable schemas
|
|
30
|
-
│
|
|
31
|
-
├─ examples/ # Real-world examples in YAML/JSON
|
|
32
|
-
│ ├─ *.yaml # UniSpec document examples
|
|
33
|
-
│ └─ unispec.config.json # Config example
|
|
34
|
-
│
|
|
35
|
-
├─ docs/ # Detailed format documentation
|
|
36
|
-
│ ├─ unispec.md # UniSpec document format
|
|
37
|
-
│ ├─ unispec-tests.md # UniSpec Tests format
|
|
38
|
-
│ └─ unispec-config.md # UniSpec Config format
|
|
39
|
-
│
|
|
40
|
-
├─ reference/ # Human-readable reference docs
|
|
41
|
-
│ ├─ fields.md # Complete field reference
|
|
42
|
-
│ ├─ versioning.md # Versioning guidelines
|
|
43
|
-
│ └─ style-guide.md # Documentation style guide
|
|
44
|
-
└─ CHANGELOG.md # Release notes
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Purpose of This Repository
|
|
48
|
-
|
|
49
|
-
This repo defines the UniSpec language, not its implementation.
|
|
50
|
-
|
|
51
|
-
### This repository contains:
|
|
52
|
-
|
|
53
|
-
- Format specification
|
|
54
|
-
- JSON Schemas
|
|
55
|
-
- Examples and documentation
|
|
56
|
-
- Rules for versioning and compatibility
|
|
57
|
-
- Documented process for evolving the format over time
|
|
58
|
-
|
|
59
|
-
### This repository does NOT contain:
|
|
60
|
-
|
|
61
|
-
- UniSpec Core engine
|
|
62
|
-
- CLI implementation
|
|
63
|
-
- Framework adapters
|
|
64
|
-
- Portal or Registry code
|
|
65
|
-
- Runtime logic
|
|
66
|
-
|
|
67
|
-
These live in other repositories of the UniSpec organization.
|
|
68
|
-
|
|
69
|
-
## Format Philosophy
|
|
70
|
-
|
|
71
|
-
UniSpec is built on the following principles:
|
|
72
|
-
|
|
73
|
-
1. Multi-protocol by design
|
|
74
|
-
- One format supports:
|
|
75
|
-
- REST
|
|
76
|
-
- GraphQL
|
|
77
|
-
- WebSocket
|
|
78
|
-
- (future) gRPC, AsyncAPI, message buses
|
|
79
|
-
|
|
80
|
-
2. Developer-first
|
|
81
|
-
- Readable YAML for humans, strict JSON Schema for machines.
|
|
82
|
-
|
|
83
|
-
3. Strong structure, minimal ambiguity
|
|
84
|
-
- No vague fields or implicit semantics.
|
|
85
|
-
- Every field has a precise definition and validation rules.
|
|
86
|
-
|
|
87
|
-
4.
|
|
88
|
-
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
-
|
|
101
|
-
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
- `
|
|
120
|
-
- `
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
1
|
+
# UniSpec Specification
|
|
2
|
+
|
|
3
|
+
Official specification of the UniSpec API definition language
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
UniSpec is a modern, multi-protocol API specification format designed to unify REST, GraphQL, WebSocket, and event-driven API documentation under a single, consistent model.
|
|
8
|
+
|
|
9
|
+
This repository is the single source of truth for the UniSpec format.
|
|
10
|
+
It contains everything required to understand, validate, and evolve the language:
|
|
11
|
+
|
|
12
|
+
- Machine-readable JSON Schemas
|
|
13
|
+
- Human-readable reference documentation
|
|
14
|
+
- Official examples (REST, GraphQL, WebSocket, mixed APIs)
|
|
15
|
+
- A companion test specification (UniSpec Tests) for executable test documents
|
|
16
|
+
## Repository Structure
|
|
17
|
+
```pgsql
|
|
18
|
+
unispec-spec/
|
|
19
|
+
├─ schema/ # JSON Schemas defining the UniSpec format
|
|
20
|
+
│ ├─ unispec.schema.json # Core UniSpec document
|
|
21
|
+
│ ├─ unispec-tests.schema.json # UniSpec Tests document
|
|
22
|
+
│ ├─ unispec-config.schema.json # UniSpec Config document
|
|
23
|
+
│ └─ types/ # Shared schema types
|
|
24
|
+
│ ├─ common.schema.json # Common definitions
|
|
25
|
+
│ ├─ service.schema.json # Service definition
|
|
26
|
+
│ ├─ rest.schema.json # REST protocol
|
|
27
|
+
│ ├─ graphql.schema.json # GraphQL protocol
|
|
28
|
+
│ ├─ websocket.schema.json # WebSocket protocol
|
|
29
|
+
│ └─ schemas.schema.json # Reusable schemas
|
|
30
|
+
│
|
|
31
|
+
├─ examples/ # Real-world examples in YAML/JSON
|
|
32
|
+
│ ├─ *.yaml # UniSpec document examples
|
|
33
|
+
│ └─ unispec.config.json # Config example
|
|
34
|
+
│
|
|
35
|
+
├─ docs/ # Detailed format documentation
|
|
36
|
+
│ ├─ unispec.md # UniSpec document format
|
|
37
|
+
│ ├─ unispec-tests.md # UniSpec Tests format
|
|
38
|
+
│ └─ unispec-config.md # UniSpec Config format
|
|
39
|
+
│
|
|
40
|
+
├─ reference/ # Human-readable reference docs
|
|
41
|
+
│ ├─ fields.md # Complete field reference
|
|
42
|
+
│ ├─ versioning.md # Versioning guidelines
|
|
43
|
+
│ └─ style-guide.md # Documentation style guide
|
|
44
|
+
└─ CHANGELOG.md # Release notes
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Purpose of This Repository
|
|
48
|
+
|
|
49
|
+
This repo defines the UniSpec language, not its implementation.
|
|
50
|
+
|
|
51
|
+
### This repository contains:
|
|
52
|
+
|
|
53
|
+
- Format specification
|
|
54
|
+
- JSON Schemas
|
|
55
|
+
- Examples and documentation
|
|
56
|
+
- Rules for versioning and compatibility
|
|
57
|
+
- Documented process for evolving the format over time
|
|
58
|
+
|
|
59
|
+
### This repository does NOT contain:
|
|
60
|
+
|
|
61
|
+
- UniSpec Core engine
|
|
62
|
+
- CLI implementation
|
|
63
|
+
- Framework adapters
|
|
64
|
+
- Portal or Registry code
|
|
65
|
+
- Runtime logic
|
|
66
|
+
|
|
67
|
+
These live in other repositories of the UniSpec organization.
|
|
68
|
+
|
|
69
|
+
## Format Philosophy
|
|
70
|
+
|
|
71
|
+
UniSpec is built on the following principles:
|
|
72
|
+
|
|
73
|
+
1. Multi-protocol by design
|
|
74
|
+
- One format supports:
|
|
75
|
+
- REST
|
|
76
|
+
- GraphQL
|
|
77
|
+
- WebSocket
|
|
78
|
+
- (future) gRPC, AsyncAPI, message buses
|
|
79
|
+
|
|
80
|
+
2. Developer-first
|
|
81
|
+
- Readable YAML for humans, strict JSON Schema for machines.
|
|
82
|
+
|
|
83
|
+
3. Strong structure, minimal ambiguity
|
|
84
|
+
- No vague fields or implicit semantics.
|
|
85
|
+
- Every field has a precise definition and validation rules.
|
|
86
|
+
|
|
87
|
+
4. Transparent evolution
|
|
88
|
+
- All major changes must be clearly documented.
|
|
89
|
+
- Minor changes and clarifications must maintain backward compatibility.
|
|
90
|
+
|
|
91
|
+
## JSON Schema
|
|
92
|
+
|
|
93
|
+
The canonical, machine-readable definition of UniSpec lives in the schema/ directory.
|
|
94
|
+
|
|
95
|
+
### Rules:
|
|
96
|
+
|
|
97
|
+
- Must follow JSON Schema Draft 2020-12
|
|
98
|
+
- Must use $defs for reusable components
|
|
99
|
+
- Must clearly describe field semantics and constraints
|
|
100
|
+
- All examples must validate against the schema
|
|
101
|
+
- Breaking changes require explicit agreement and a major version bump
|
|
102
|
+
|
|
103
|
+
## Documentation
|
|
104
|
+
|
|
105
|
+
### Format specifications
|
|
106
|
+
- **[UniSpec Document](docs/unispec.md)** — Core API specification format
|
|
107
|
+
- **[UniSpec Tests](docs/unispec-tests.md)** — Executable test cases format
|
|
108
|
+
- **[UniSpec Config](docs/unispec-config.md)** — Service discovery and configuration
|
|
109
|
+
|
|
110
|
+
### Reference documentation
|
|
111
|
+
- `reference/` — Detailed field-by-field reference, versioning, and style guides
|
|
112
|
+
|
|
113
|
+
## Examples
|
|
114
|
+
|
|
115
|
+
The `examples/` directory contains official examples:
|
|
116
|
+
- `simple-rest.yaml` — minimal REST service
|
|
117
|
+
- `graphql.yaml` — GraphQL API
|
|
118
|
+
- `websocket.yaml` — WebSocket channels
|
|
119
|
+
- `mixed-api.yaml` — multi-protocol service
|
|
120
|
+
- `unispec.config.json` — configuration example
|
|
121
|
+
|
|
122
|
+
All examples are validated as part of CI.
|
|
123
|
+
|
|
124
|
+
## Versioning
|
|
125
|
+
|
|
126
|
+
UniSpec follows Semantic Versioning (SemVer):
|
|
127
|
+
|
|
128
|
+
- MAJOR — breaking changes
|
|
129
|
+
- MINOR — new backward-compatible features
|
|
130
|
+
- PATCH — fixes, clarifications, corrections
|
|
131
|
+
|
|
132
|
+
All changes must be recorded in CHANGELOG.md.
|
|
133
|
+
|
|
134
|
+
## Format Changes and Contributions
|
|
135
|
+
|
|
136
|
+
Any change that alters:
|
|
137
|
+
|
|
138
|
+
- structure of the UniSpec format
|
|
139
|
+
- semantics of existing fields
|
|
140
|
+
- compatibility rules
|
|
141
|
+
- supported protocols
|
|
142
|
+
|
|
143
|
+
should be proposed and discussed in a pull request before being applied here.
|
|
144
|
+
|
|
145
|
+
## Installation
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
# Install dependencies with pnpm
|
|
149
|
+
pnpm install
|
|
150
|
+
|
|
151
|
+
# Or with npm (legacy support)
|
|
152
|
+
npm install
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Contributing
|
|
156
|
+
|
|
157
|
+
Contributions are welcome!
|
|
158
|
+
|
|
159
|
+
To contribute:
|
|
160
|
+
|
|
161
|
+
1. Install dependencies: `pnpm install`
|
|
162
|
+
2. Read the reference docs.
|
|
163
|
+
3. Discuss substantial format changes in an issue or pull request.
|
|
164
|
+
4. Submit a PR with clear explanation and schema validation.
|
|
165
|
+
|
|
166
|
+
All contributions must preserve backward compatibility unless explicitly approved otherwise.
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
This repository is open-source and free to implement.
|
|
163
171
|
The UniSpec format is designed to be an open standard.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# UniSpec Examples
|
|
2
|
+
|
|
3
|
+
This directory contains comprehensive examples for testing and validating UniSpec specifications.
|
|
4
|
+
|
|
5
|
+
## Structure
|
|
6
|
+
|
|
7
|
+
### Valid Examples (`examples/valid/`)
|
|
8
|
+
|
|
9
|
+
These examples demonstrate correct UniSpec usage and should pass validation:
|
|
10
|
+
|
|
11
|
+
#### REST API Examples
|
|
12
|
+
- **`rest-complete.json`** - Complete user management API with authentication, pagination, schemas, and comprehensive error handling
|
|
13
|
+
- **`rest-simple.json`** - Simple blog API with basic CRUD operations
|
|
14
|
+
|
|
15
|
+
#### GraphQL API Examples
|
|
16
|
+
- **`graphql-complete.json`** - Full-featured GraphQL API with users, posts, authentication, queries, mutations, and subscriptions
|
|
17
|
+
- **`graphql-simple.json`** - Minimal GraphQL API for blog posts
|
|
18
|
+
|
|
19
|
+
#### WebSocket API Examples
|
|
20
|
+
- **`websocket-complete.json`** - Real-time chat API with multiple channels, authentication, reconnection strategies, and comprehensive message types
|
|
21
|
+
- **`websocket-simple.json`** - Simple notification and status update WebSocket API
|
|
22
|
+
|
|
23
|
+
#### Mixed Protocol Examples
|
|
24
|
+
- **`mixed-complete.json`** - Complete social media platform with REST (media upload), GraphQL (social features), and WebSocket (real-time updates)
|
|
25
|
+
- **`mixed-simple.json`** - Simple API combining REST and GraphQL protocols
|
|
26
|
+
|
|
27
|
+
#### Configuration Examples
|
|
28
|
+
- **`config/complete.json`** - Complete configuration with multiple services, environments, auth, and health checks
|
|
29
|
+
- **`config/minimal.json`** - Minimal configuration with single service
|
|
30
|
+
- **`config/unispec.config.json`** - Existing configuration example (JSON format)
|
|
31
|
+
|
|
32
|
+
### Invalid Examples (`examples/invalid/`)
|
|
33
|
+
|
|
34
|
+
These examples demonstrate common validation errors and should fail validation:
|
|
35
|
+
|
|
36
|
+
#### REST API Validation Errors
|
|
37
|
+
- **`rest-missing-required.json`** - Missing required fields (service name, route path)
|
|
38
|
+
- **`rest-invalid-method.json`** - Invalid HTTP method
|
|
39
|
+
- **`rest-invalid-identifiers.json`** - Invalid identifier patterns with spaces
|
|
40
|
+
- **`rest-additional-properties.json`** - Additional properties not allowed by schema
|
|
41
|
+
|
|
42
|
+
#### GraphQL API Validation Errors
|
|
43
|
+
- **`graphql-missing-schema.json`** - Missing required schema field
|
|
44
|
+
- **`graphql-missing-name.json`** - Missing required operation name
|
|
45
|
+
- **`graphql-missing-arg-type.json`** - Missing required argument type
|
|
46
|
+
- **`graphql-additional-properties.json`** - Additional properties not allowed
|
|
47
|
+
|
|
48
|
+
#### WebSocket API Validation Errors
|
|
49
|
+
- **`websocket-missing-channel-name.json`** - Missing required channel name
|
|
50
|
+
- **`websocket-missing-message-name.json`** - Missing required message name
|
|
51
|
+
- **`websocket-invalid-direction.json`** - Invalid direction enum values
|
|
52
|
+
- **`websocket-additional-properties.json`** - Additional properties not allowed
|
|
53
|
+
|
|
54
|
+
#### Mixed Protocol Validation Errors
|
|
55
|
+
- **`mixed-missing-graphql-schema.json`** - GraphQL protocol missing required schema
|
|
56
|
+
- **`mixed-invalid-protocol.json`** - Invalid protocol property
|
|
57
|
+
- **`mixed-multiple-errors.json`** - Multiple validation errors across protocols
|
|
58
|
+
|
|
59
|
+
#### Configuration Validation Errors
|
|
60
|
+
- **`config/missing-version.json`** - Missing required version field
|
|
61
|
+
- **`config/missing-service-name.json`** - Service without required name field
|
|
62
|
+
- **`config/additional-properties.json`** - Additional properties not allowed
|
|
63
|
+
- **`config/unispec.config.json`** - Existing configuration example (for reference)
|
|
64
|
+
|
|
65
|
+
## Usage in npm
|
|
66
|
+
|
|
67
|
+
These examples are published as part of the `@unispechq/unispec-schema` package and can be imported:
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
// Import all valid examples
|
|
71
|
+
import validExamples from '@unispechq/unispec-schema/examples/valid';
|
|
72
|
+
|
|
73
|
+
// Import specific example
|
|
74
|
+
import restComplete from '@unispechq/unispec-schema/examples/valid/rest-complete';
|
|
75
|
+
|
|
76
|
+
// Import invalid examples for testing validation
|
|
77
|
+
import invalidExamples from '@unispechq/unispec-schema/examples/invalid';
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Testing
|
|
81
|
+
|
|
82
|
+
Use these examples to test your UniSpec validation tools:
|
|
83
|
+
|
|
84
|
+
1. **Positive Testing**: Use valid examples to ensure your validator accepts correct specifications
|
|
85
|
+
2. **Negative Testing**: Use invalid examples to ensure your validator catches errors appropriately
|
|
86
|
+
3. **Edge Case Testing**: Test boundary conditions and complex scenarios with the complete examples
|
|
87
|
+
4. **Protocol Testing**: Validate specific protocol handling with individual REST, GraphQL, and WebSocket examples
|
|
88
|
+
|
|
89
|
+
## Coverage
|
|
90
|
+
|
|
91
|
+
The examples cover:
|
|
92
|
+
|
|
93
|
+
- ✅ All UniSpec protocols (REST, GraphQL, WebSocket)
|
|
94
|
+
- ✅ Authentication and security schemes
|
|
95
|
+
- ✅ Schema definitions and references
|
|
96
|
+
- ✅ Error handling and responses
|
|
97
|
+
- ✅ Pagination and filtering
|
|
98
|
+
- ✅ Real-time communication patterns
|
|
99
|
+
- ✅ Mixed protocol architectures
|
|
100
|
+
- ✅ Configuration management (YAML and JSON)
|
|
101
|
+
- ✅ Environment-specific configurations
|
|
102
|
+
- ✅ Service discovery and health checks
|
|
103
|
+
- ✅ Common validation errors
|
|
104
|
+
- ✅ Edge cases and complex scenarios
|
|
105
|
+
|
|
106
|
+
## Contributing
|
|
107
|
+
|
|
108
|
+
When adding new examples:
|
|
109
|
+
|
|
110
|
+
1. Place valid examples in `examples/valid/`
|
|
111
|
+
2. Place invalid examples in `examples/invalid/`
|
|
112
|
+
3. Use descriptive filenames
|
|
113
|
+
4. Add comments explaining the purpose of the example
|
|
114
|
+
5. Update this README file
|
|
115
|
+
6. Update `package.json` exports if adding new files
|
|
116
|
+
7. Test against the UniSpec schema
|
|
117
|
+
|
|
118
|
+
## Schema Validation
|
|
119
|
+
|
|
120
|
+
All examples should be validated against the UniSpec JSON Schema:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# Validate a specific example
|
|
124
|
+
npx ajv validate -s schema/unispec.schema.json -d examples/valid/rest-complete.json
|
|
125
|
+
|
|
126
|
+
# Validate all examples
|
|
127
|
+
find examples -name "*.json" -exec npx ajv validate -s schema/unispec.schema.json -d {} \;
|
|
128
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"unispecVersion": "0.1.0",
|
|
3
|
+
"service": {
|
|
4
|
+
"name": "config-api",
|
|
5
|
+
"description": "API with additional properties",
|
|
6
|
+
"invalidProperty": "should not exist",
|
|
7
|
+
"protocols": {
|
|
8
|
+
"rest": {
|
|
9
|
+
"routes": [
|
|
10
|
+
{
|
|
11
|
+
"name": "getUsers",
|
|
12
|
+
"path": "/users",
|
|
13
|
+
"method": "GET",
|
|
14
|
+
"responses": {
|
|
15
|
+
"200": {
|
|
16
|
+
"description": "Success",
|
|
17
|
+
"invalidProperty": "should not exist"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"invalidProperty": "should not exist"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"unispecVersion": "0.1.0",
|
|
3
|
+
"service": {
|
|
4
|
+
"description": "Service without required name field",
|
|
5
|
+
"protocols": {
|
|
6
|
+
"rest": {
|
|
7
|
+
"routes": [
|
|
8
|
+
{
|
|
9
|
+
"name": "getUsers",
|
|
10
|
+
"path": "/users",
|
|
11
|
+
"method": "GET",
|
|
12
|
+
"responses": {
|
|
13
|
+
"200": {
|
|
14
|
+
"description": "Success"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"unispecVersion": "0.1.0",
|
|
3
|
+
"service": {
|
|
4
|
+
"name": "invalid-graphql-api",
|
|
5
|
+
"description": "GraphQL API with additional properties",
|
|
6
|
+
"protocols": {
|
|
7
|
+
"graphql": {
|
|
8
|
+
"url": "/graphql",
|
|
9
|
+
"schema": "type Query {\n users: [User!]!\n}\n\ntype User {\n id: ID!\n name: String!\n}\n",
|
|
10
|
+
"queries": [
|
|
11
|
+
{
|
|
12
|
+
"name": "users",
|
|
13
|
+
"description": "Get users",
|
|
14
|
+
"returnType": "[User!]!",
|
|
15
|
+
"invalidProperty": "should not exist"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"invalidProperty": "should not exist"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"unispecVersion": "0.1.0",
|
|
3
|
+
"service": {
|
|
4
|
+
"name": "invalid-graphql-api",
|
|
5
|
+
"description": "GraphQL API with missing argument type",
|
|
6
|
+
"protocols": {
|
|
7
|
+
"graphql": {
|
|
8
|
+
"url": "/graphql",
|
|
9
|
+
"schema": "type Query {\n users(limit: Int): [User!]!\n}\n\ntype User {\n id: ID!\n name: String!\n}\n",
|
|
10
|
+
"queries": [
|
|
11
|
+
{
|
|
12
|
+
"name": "users",
|
|
13
|
+
"description": "Get users",
|
|
14
|
+
"args": [
|
|
15
|
+
{
|
|
16
|
+
"name": "limit",
|
|
17
|
+
"description": "Limit number of results"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"returnType": "[User!]!"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"unispecVersion": "0.1.0",
|
|
3
|
+
"service": {
|
|
4
|
+
"name": "invalid-graphql-api",
|
|
5
|
+
"description": "GraphQL API with missing operation name",
|
|
6
|
+
"protocols": {
|
|
7
|
+
"graphql": {
|
|
8
|
+
"url": "/graphql",
|
|
9
|
+
"schema": "type Query {\n users: [User!]!\n}\n\ntype User {\n id: ID!\n name: String!\n}\n",
|
|
10
|
+
"queries": [
|
|
11
|
+
{
|
|
12
|
+
"description": "Get users",
|
|
13
|
+
"returnType": "[User!]!"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"unispecVersion": "0.1.0",
|
|
3
|
+
"service": {
|
|
4
|
+
"name": "invalid-graphql-api",
|
|
5
|
+
"description": "GraphQL API missing required schema field",
|
|
6
|
+
"protocols": {
|
|
7
|
+
"graphql": {
|
|
8
|
+
"url": "/graphql",
|
|
9
|
+
"queries": [
|
|
10
|
+
{
|
|
11
|
+
"name": "users",
|
|
12
|
+
"description": "Get users",
|
|
13
|
+
"returnType": "[User!]!"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"unispecVersion": "0.1.0",
|
|
3
|
+
"service": {
|
|
4
|
+
"name": "invalid-mixed-api",
|
|
5
|
+
"description": "Mixed protocol API with invalid protocol",
|
|
6
|
+
"protocols": {
|
|
7
|
+
"rest": {
|
|
8
|
+
"routes": [
|
|
9
|
+
{
|
|
10
|
+
"name": "getUsers",
|
|
11
|
+
"path": "/users",
|
|
12
|
+
"method": "GET",
|
|
13
|
+
"responses": {
|
|
14
|
+
"200": {
|
|
15
|
+
"description": "Success"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
"invalidProtocol": {
|
|
22
|
+
"someProperty": "value"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"unispecVersion": "0.1.0",
|
|
3
|
+
"service": {
|
|
4
|
+
"name": "invalid-mixed-api",
|
|
5
|
+
"description": "Mixed protocol API missing GraphQL schema",
|
|
6
|
+
"protocols": {
|
|
7
|
+
"rest": {
|
|
8
|
+
"routes": [
|
|
9
|
+
{
|
|
10
|
+
"name": "getUsers",
|
|
11
|
+
"path": "/users",
|
|
12
|
+
"method": "GET",
|
|
13
|
+
"responses": {
|
|
14
|
+
"200": {
|
|
15
|
+
"description": "Success"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
"graphql": {
|
|
22
|
+
"url": "/graphql",
|
|
23
|
+
"queries": [
|
|
24
|
+
{
|
|
25
|
+
"name": "users",
|
|
26
|
+
"description": "Get users",
|
|
27
|
+
"returnType": "[User!]!"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|