File size: 8,264 Bytes
ab74ec2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# Network Access Management API Definitions

This directory contains the OpenAPI specifications for the Network Access Management API, organized into modular components for better maintainability and reusability.

## Overview

The API definitions have been restructured from a monolithic approach to a modular, component-based architecture. This allows for better code reuse, easier maintenance, and cleaner separation of concerns.

## Folder Structure

```

API_definitions/

├── README.md                                    # This file (authoring & process docs)

├── redocly.yaml                                 # Lint/bundle configuration (Redocly CLI)

├── network-access-management.yaml               # Source API spec with $ref references (committed on main)

├── common/

│   └── CAMARA_common.yaml                       # Shared CAMARA-style error responses

└── modules/                                     # Modular domain-focused component files

    ├── NAM_Common.yaml                          # Shared primitives (UUID, DateTime, ResourceAudit, securitySchemes)

    ├── AccessDetail.yaml                        # Discriminated access detail variants (Wi-Fi, Thread)

    ├── Capabilities.yaml                        # Device capability schemas

    ├── Policy.yaml                              # Trust Domain policy schemas (maxDevices, bandwidth, egress)

    ├── NetworkAccessDevices/                     # Network Access Device resource schemas

    ├── RebootRequests/                           # Reboot Request lifecycle schemas

    ├── Services/                                # Service and ServiceSite schemas

    └── TrustDomains/                            # Trust Domain & related capability schemas

```

## Architecture Rationale

### Why Multiple Files?

**Before:** Single monolithic OpenAPI file (`network-access-management.yaml`)
- ✅ Simple to understand initially
- ❌ Became very large (2000+ lines)
- ❌ Hard to maintain and review
- ❌ Schema duplication across different APIs
- ❌ Merge conflicts in collaborative development
- ❌ No reusability between different API specifications

**After:** Modular component-based structure
- ✅ Each file has a single, clear responsibility
- ✅ Reusable schemas can be shared across APIs
- ✅ Easier to review and maintain individual components
- ✅ Parallel development by different team members
- ✅ Clear separation of concerns
- ✅ Smaller, focused files

### Component Breakdown

| File | Purpose | Reusability |
|------|---------|-------------|
| `Common.yaml` | Base types (UUID, DateTime, ErrorInfo) | High - used across all APIs |
| `Policy.yaml` | Trust Domain governance policies | Medium - Trust Domain specific |
| `AccessDetail.yaml` | Network access configurations | Medium - Network-related APIs |
| `TrustDomains.yaml` | Core Trust Domain schemas | Low - Trust Domain specific |

## Bundling and Validation

### Key Constraint: Bundled Files Are Not Committed on Main

Per the [CAMARA Consumption and Bundling Design](https://github.com/camaraproject/Commonalities/blob/main/documentation/Commonalities-Consumption-and-Bundling-Design.md), **bundled (standalone) API definitions are never committed on `main`**. The committed `network-access-management.yaml` retains its `$ref` references to `common/` and `modules/`. Bundled standalone OAS files are produced only on release branches/tags and for local validation.

This avoids merge conflicts in the large bundled output and keeps `main` as the single source of truth for modular schema authoring.

Bundled output files (`*-bundled.yaml`) are listed in `.gitignore`.

### Prerequisites

Install Redocly CLI:
```bash

npm install -g @redocly/cli

```

### Linting

Validate the spec and all referenced modules resolve correctly:
```bash

cd code/API_definitions

redocly lint network-access-management.yaml

```

### Local Bundling (for Validation or Tooling)

To produce a fully resolved, standalone OAS file locally:
```bash

cd code/API_definitions

redocly bundle network-access-management.yaml --output network-access-management-bundled.yaml

```

The bundled file is useful for:
- Importing into API tools (Swagger UI, Postman, etc.)
- Validating the fully resolved spec with external validators
- Generating SDKs or documentation locally

**Do not commit `*-bundled.yaml` files to `main`.** They are git-ignored.



### Bundling Configuration



The `redocly.yaml` file contains:

- **Linting rules** - Ensures consistency and quality
- **File resolution** - Allows `.yaml` and `.yml` extensions

Key bundling features:
- Resolves all `$ref` references to external files
- Validates schema compatibility
- Generates self-contained OpenAPI specifications
- Preserves examples and documentation

## File Purposes

### API Specification

- **`network-access-management.yaml`** - Source API specification with `$ref` references to `common/` and `modules/`. This is the file committed on `main`. Bundling resolves these refs into a standalone OAS file for release branches and local tooling.

### Component Files

- **`common/CAMARA_common.yaml`** - Shared CAMARA-style error responses and common schemas

- **`modules/NAM_Common.yaml`** - Shared fundamental types (UUID, DateTime, ResourceAudit, securitySchemes)
- **`modules/Policy.yaml`** - Trust Domain policy schemas (maxDevices, bandwidth limits, egress rules)
- **`modules/AccessDetail.yaml`** - Network access configuration schemas (Wi-Fi, Thread, security modes)
- **`modules/Capabilities.yaml`** - Device capability schemas
- **`modules/TrustDomains/TrustDomains.yaml`** - Core Trust Domain schemas and examples
- **`modules/NetworkAccessDevices/NetworkAccessDevices.yaml`** - Network Access Device resource schemas
- **`modules/RebootRequests/RebootRequests.yaml`** - Reboot Request lifecycle schemas
- **`modules/Services/Services.yaml`** - Service schemas
- **`modules/Services/ServiceSites.yaml`** - Service Site schemas

## Best Practices

### When to Create New Component Files
- **High reusability** - Schemas used by multiple APIs
- **Logical grouping** - Related schemas that form a cohesive unit
- **Size management** - When a file exceeds ~500 lines

### Schema Design Guidelines
- Use `$ref` for external schema references
- Keep examples close to their schemas
- Use YAML anchors for internal reuse within files
- Document inheritance and discriminator patterns clearly

### Example Cross-Reference Limitations

**Important:** While schemas can be easily shared across files using `$ref`, examples have significant limitations in the distributed component model:

#### The Problem
```yaml

# ❌ This does NOT work - cannot use $ref inside example values

TrustDomainExample:

  summary: Trust Domain with Wi-Fi access

  value:

    name: "My Network"

    accessDetails:

      - $ref: "modules/AccessDetail.yaml#/components/examples/WiFiExample/value"  # Invalid!

```

#### The Solutions

**Option 1: Local Example Duplication (Recommended)**
```yaml

# ✅ Define examples locally where they're used

TrustDomainExample:

  summary: Trust Domain with Wi-Fi access

  value:

    name: "My Network"

    accessDetails:

      - accessType: "Wi-Fi"

        ssid: "my-network"

        securityMode:

          password: "my-password"

          securityModeType: "WPA2-Personal"

```

**Option 2: YAML Anchors (Within Same File Only)**
```yaml

# ✅ Use anchors for reuse within the same file

_wifi_example: &wifi-access

  accessType: "Wi-Fi"

  ssid: "my-network"

  securityMode:

    password: "my-password"

    securityModeType: "WPA2-Personal"



components:

  examples:

    TrustDomainExample:

      value:

        accessDetails:

          - *wifi-access  # Reuse within same file

```

**Option 3: Component-Level Example References**
```yaml

# ✅ Reference complete examples at component level (not within values)

WiFiAccessExample:

  $ref: "modules/AccessDetail.yaml#/components/examples/WiFiAccessDetailWPA2Personal"



# But you still can't compose these inside other example values

```