Repository: ogen-go/ogen
Pull request #187 (2022-02-14 20:23:10)

fix(ir): do not panic, if generating postfix for Any type
Prevent panic in boxing cases like "array of Any"



Patch:
diff --git a/internal/ir/type.go b/internal/ir/type.go
index 6a41cf98..a6991793 100644
--- a/internal/ir/type.go
+++ b/internal/ir/type.go
@@ -210,12 +210,13 @@ func (t *Type) NamePostfix() string {
 		}
 	case KindArray:
 		return t.Item.NamePostfix() + "Array"
+	case KindAny:
+		return "Any"
 	case KindPointer:
 		return t.PointerTo.NamePostfix() + "Pointer"
 	case KindStruct, KindMap, KindAlias, KindInterface, KindGeneric, KindEnum, KindSum, KindStream:
 		return t.Name
 	default:
-		// KindAny and KindPointer must not be wrapped.
 		panic(fmt.Sprintf("unexpected kind: %s", t.Kind))
 	}
 }


Test patch:
diff --git a/_testdata/positive/pokemon-api.json b/_testdata/positive/pokemon-api.json
new file mode 100644
index 00000000..aae4d94e
--- /dev/null
+++ b/_testdata/positive/pokemon-api.json
@@ -0,0 +1,177 @@
+{
+  "info": {
+    "license": {
+      "name": "Not specified"
+    },
+    "title": "Not specified",
+    "version": "Not specified"
+  },
+  "openapi": "3.0.3",
+  "paths": {
+    "/pokemonByName": {
+      "get": {
+        "parameters": [
+          {
+            "in": "query",
+            "name": "name",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          }
+        ],
+        "responses": {
+          "200": {
+            "content": {
+              "application/json": {
+                "schema": {
+                  "properties": {
+                    "pokemon": {
+                      "nullable": true,
+                      "properties": {
+                        "attacks": {
+                          "description": "The attacks of this Pokémon",
+                          "nullable": true,
+                          "properties": {
+                            "special": {
+                              "description": "The special attacks of this Pokémon",
+                              "items": {
+                                "properties": {
+                                  "damage": {
+                                    "description": "The damage of this Pokémon attack",
+                                    "nullable": true,
+                                    "type": "integer"
+                                  },
+                                  "name": {
+                                    "description": "The name of this Pokémon attack",
+                                    "nullable": true,
+                                    "type": "string"
+                                  },
+                                  "type": {
+                                    "description": "The type of this Pokémon attack",
+                                    "nullable": true,
+                                    "type": "string"
+                                  }
+                                },
+                                "type": "object"
+                              },
+                              "nullable": true,
+                              "type": "array"
+                            }
+                          },
+                          "type": "object"
+                        },
+                        "evolutions": {
+                          "description": "The evolutions of this Pokémon",
+                          "items": {
+                            "properties": {
+                              "attacks": {
+                                "description": "The attacks of this Pokémon",
+                                "nullable": true,
+                                "properties": {
+                                  "fast": {
+                                    "description": "The fast attacks of this Pokémon",
+                                    "items": {
+                                      "properties": {
+                                        "damage": {
+                                          "description": "The damage of this Pokémon attack",
+                                          "nullable": true,
+                                          "type": "integer"
+                                        },
+                                        "name": {
+                                          "description": "The name of this Pokémon attack",
+                                          "nullable": true,
+                                          "type": "string"
+                                        },
+                                        "type": {
+                                          "description": "The type of this Pokémon attack",
+                                          "nullable": true,
+                                          "type": "string"
+                                        }
+                                      },
+                                      "type": "object"
+                                    },
+                                    "nullable": true,
+                                    "type": "array"
+                                  }
+                                },
+                                "type": "object"
+                              },
+                              "id": {
+                                "description": "The ID of an object",
+                                "nullable": false,
+                                "type": "string"
+                              },
+                              "name": {
+                                "description": "The name of this Pokémon",
+                                "nullable": true,
+                                "type": "string"
+                              },
+                              "number": {
+                                "description": "The identifier of this Pokémon",
+                                "nullable": true,
+                                "type": "string"
+                              },
+                              "weight": {
+                                "description": "The minimum and maximum weight of this Pokémon",
+                                "nullable": true,
+                                "properties": {
+                                  "maximum": {
+                                    "description": "The maximum value of this dimension",
+                                    "nullable": true,
+                                    "type": "string"
+                                  },
+                                  "minimum": {
+                                    "description": "The minimum value of this dimension",
+                                    "nullable": true,
+                                    "type": "string"
+                                  }
+                                },
+                                "type": "object"
+                              }
+                            },
+                            "type": "object"
+                          },
+                          "nullable": true,
+                          "type": "array"
+                        },
+                        "locations": {
+                          "description": "Locations Pokémon lives",
+                          "nullable": true,
+                          "type": "array"
+                        },
+                        "name": {
+                          "description": "The name of this Pokémon",
+                          "nullable": true,
+                          "type": "string"
+                        },
+                        "number": {
+                          "description": "The identifier of this Pokémon",
+                          "nullable": true,
+                          "type": "string"
+                        },
+                        "pokemonId": {
+                          "description": "The ID of an object",
+                          "nullable": false,
+                          "type": "string"
+                        }
+                      },
+                      "type": "object"
+                    }
+                  },
+                  "type": "object"
+                }
+              }
+            },
+            "description": "response"
+          }
+        }
+      }
+    }
+  },
+  "servers": [
+    {
+      "url": "/"
+    }
+  ]
+}