| 172 | } |
| 173 | |
| 174 | func TestDowngrade(t *testing.T) { |
| 175 | // Test that we can downgrade a v3 OpenAPI document to v2. |
| 176 | v31 := &huma.OpenAPI{ |
| 177 | OpenAPI: "3.1.0", |
| 178 | Info: &huma.Info{ |
| 179 | Title: "Test API", |
| 180 | Version: "1.0.0", |
| 181 | }, |
| 182 | Paths: map[string]*huma.PathItem{ |
| 183 | "/test": { |
| 184 | Get: &huma.Operation{ |
| 185 | Responses: map[string]*huma.Response{ |
| 186 | "200": { |
| 187 | Description: "OK", |
| 188 | Content: map[string]*huma.MediaType{ |
| 189 | "application/json": { |
| 190 | Schema: &huma.Schema{ |
| 191 | Type: "object", |
| 192 | Properties: map[string]*huma.Schema{ |
| 193 | "test": { |
| 194 | Type: "integer", |
| 195 | ExclusiveMinimum: Ptr(0.0), |
| 196 | ExclusiveMaximum: Ptr(100.0), |
| 197 | Nullable: true, |
| 198 | Examples: []any{100}, |
| 199 | }, |
| 200 | "encoding": { |
| 201 | Type: huma.TypeString, |
| 202 | ContentEncoding: "base64", |
| 203 | }, |
| 204 | }, |
| 205 | }, |
| 206 | }, |
| 207 | "application/octet-stream": {}, |
| 208 | }, |
| 209 | }, |
| 210 | }, |
| 211 | }, |
| 212 | }, |
| 213 | }, |
| 214 | } |
| 215 | |
| 216 | v30, err := v31.Downgrade() |
| 217 | require.NoError(t, err) |
| 218 | |
| 219 | expected := `{ |
| 220 | "openapi": "3.0.3", |
| 221 | "info": { |
| 222 | "title": "Test API", |
| 223 | "version": "1.0.0" |
| 224 | }, |
| 225 | "paths": { |
| 226 | "/test": { |
| 227 | "get": { |
| 228 | "responses": { |
| 229 | "200": { |
| 230 | "description": "OK", |
| 231 | "content": { |