{"record":{"id":"9f280638ce8fce6b","repo":"OpenAPITools/openapi-generator","slug":"generated-field-number-is-in-reserved-range-19000","errorCode":null,"errorMessage":"Generated field number is in reserved range (19000, 19999).","messagePattern":"Generated field number is in reserved range \\(19000, 19999\\)\\.","errorType":"exception","errorClass":"ProtoBufIndexComputationException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java","lineNumber":1847,"sourceCode":"\n    @Override\n    public String getTypeDeclaration(Schema p) {\n        if (ModelUtils.isArraySchema(p)) {\n            Schema inner = ModelUtils.getSchemaItems(p);\n            return getSchemaType(p) + \"[\" + getTypeDeclaration(inner) + \"]\";\n        } else if (ModelUtils.isMapSchema(p)) {\n            Schema inner = ModelUtils.getAdditionalProperties(p);\n            return getSchemaType(p) + \"<string, \" + getTypeDeclaration(inner) + \">\";\n        }\n        return super.getTypeDeclaration(p);\n    }\n\n    private int generateFieldNumberFromString(String name) throws ProtoBufIndexComputationException {\n        // Max value from developers.google.com/protocol-buffers/docs/proto3#assigning_field_numbers\n        int fieldNumber = Math.abs(name.hashCode() % 536870911);\n        if (19000 <= fieldNumber && fieldNumber <= 19999) {\n            LOGGER.error(\"Generated field number is in reserved range (19000, 19999) for %s, %d\", name, fieldNumber);\n            throw new ProtoBufIndexComputationException(\"Generated field number is in reserved range (19000, 19999).\");\n        }\n        return fieldNumber;\n    }\n\n    /**\n     * Extracts enum properties from models and creates separate enum model files.\n     * Also adds imports to the parent models for the extracted enums.\n     *\n     * @param objs the models map containing all models\n     * @return the modified models map with extracted enum models added\n     */\n    private ModelsMap extractEnumsToSeparateFiles(ModelsMap objs) {\n        List<Map<String, String>> enumImports = new ArrayList<>();\n\n        Map<String, CodegenModel> extractedEnums = this.extractEnums(objs);\n        for (String enumName : extractedEnums.keySet()) {\n          // Add an import for this enum to the parent model\n          String enumImportPath = toModelImport(toModelName(enumName));","sourceCodeStart":1829,"sourceCodeEnd":1865,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java#L1829-L1865","documentation":"The protobuf-schema generator does not let you write field numbers in the .proto output; it derives them deterministically from each property name via Math.abs(name.hashCode() % 536870911). Protocol Buffers reserves field numbers 19000-19999 for the protobuf implementation itself, so when a computed hash lands in that window the generator aborts with ProtoBufIndexComputationException instead of emitting an invalid .proto file that protoc would reject.","triggerScenarios":"Running openapi-generator with -g protobuf-schema against a spec that contains a property (or any named field that goes through generateFieldNumberFromString) whose Java String.hashCode mod 536870911 falls in 19000..19999. The failure is deterministic: the same property name always fails, every run.","commonSituations":"Adding or renaming a property in the OpenAPI spec changes its hash and can suddenly push it into the reserved window (~0.19% chance per field). Teams with large specs hit it eventually; it also appears when migrating an existing spec to the protobuf-schema generator, and the same spec generates fine for other languages because only this generator hashes names into field numbers.","solutions":["Rename the offending property in the OpenAPI spec (the error log line prints the name and number); any rename changes the hash and moves the number out of 19000-19999","Pre-compute the field number for every property name (abs(javaHash(name) % 536870911)) to find all colliding names before generation, then rename each one","If the wire name must not change, introduce a wrapper/rename at the API layer or maintain the .proto by hand instead of using -g protobuf-schema","Report/upvote the issue on openapi-generator GitHub so explicit field numbers (e.g. via a vendor extension) get supported"],"exampleFix":"# before: spec property whose hash lands in 19000-19999\ncomponents:\n  schemas:\n    Pet:\n      properties:\n        keyCode:   # abs(hashCode % 536870911) in reserved range -> generation fails\n          type: string\n# after: rename the property (wire name changes, hash moves out of range)\ncomponents:\n  schemas:\n    Pet:\n      properties:\n        keyCodeValue:\n          type: string","handlingStrategy":"validation","validationCode":"# Pre-check every property name against the generator's field-number hash (Python):\ndef java_hash(s: str) -> int:\n    h = 0\n    for c in s:\n        h = (31 * h + ord(c)) & 0xFFFFFFFF\n    if h >= 0x80000000:\n        h -= 0x100000000\n    return h\n\ndef reserved(name: str) -> bool:\n    return 19000 <= abs(java_hash(name) % 536870911) <= 19999\n\nbad = [p for p in all_property_names(spec) if reserved(p)]\nassert not bad, f'rename these properties, they hash into 19000-19999: {bad}'","typeGuard":null,"tryCatchPattern":"try {\n    new DefaultGenerator().opts(clientOptInput).generate();\n} catch (ProtoBufIndexComputationException e) {\n    // log the property name from the preceding LOGGER.error line and fail the build fast\n    throw new IllegalStateException('protobuf field number reserved-range collision, rename the reported property', e);\n}","preventionTips":["Run the hash pre-check in CI for every spec change before invoking -g protobuf-schema","Treat a protobuf-schema failure mentioning one property as deterministic: renaming that property is the only spec-side fix","Keep generated .proto files in review so an unexpected rename that shifts hashes is visible"],"tags":["protobuf","codegen","field-number","hash-collision","openapi-generator"],"backgroundTag":"protobuf-field-number-conflict","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}