Skip to content

Exception is thrown if a $ref points to an other file #474

@erosb

Description

@erosb

Hello,

First of all, thank you for all your work put into this project.

I tried to use fabrikt to generate code from an openapi yaml which has $refs pointing to external files.

Reproducer:

minimal-api.yaml:

openapi: "3.1.0"
info:
  title: Partners API
  version: "1.0"
paths:
  /api/dummy:
    post:
      operationId: createDummy
      requestBody:
        content:
          application/json:
            schema:
              $ref: "./dummy/DummyCreationRequest.yaml"
        required: true
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "./dummy/Dummy.yaml"
          description: OK

dummy/DummyCreationRequest.yaml:

$schema: https://json-schema.org/draft/2020-12/schema
type: object
additionalProperties: false
properties:
  name:
    type: string
    minLength: 4
    maxLength: 30

dummy/Dummy.yaml:

$schema: https://json-schema.org/draft/2020-12/schema
type: object
additionalProperties: false
properties:
  id:
    type: integer
  name:
    type: string
    minLength: 4
    maxLength: 30

The command was:

java -jar ./fabrikt/build/libs/fabrikt*.jar \
  --output-directory 'src/main/kotlin' \
  --base-package 'com.example' \
  --api-file './minimal-api.yaml' \
  --targets 'controllers' \
  --validation-library javax_validation

And finally, the exception:

Nov 02, 2025 7:29:12 PM com.cjbooms.fabrikt.cli.CodeGen generate
INFO: Generating code and dumping to src/main/kotlin/
Exception in thread "main" java.lang.IllegalArgumentException: simpleNames must not contain empty items: []
	at com.squareup.kotlinpoet.ClassName.<init>(ClassName.kt:58)
	at com.cjbooms.fabrikt.generators.model.ModelGenerator$Companion.generatedType(ModelGenerator.kt:170)
	at com.cjbooms.fabrikt.generators.model.ModelGenerator$Companion.toClassName(ModelGenerator.kt:162)
	at com.cjbooms.fabrikt.generators.model.ModelGenerator$Companion.toModelType(ModelGenerator.kt:90)
	at com.cjbooms.fabrikt.generators.model.ModelGenerator$Companion.toModelType$default(ModelGenerator.kt:84)
	at com.cjbooms.fabrikt.generators.controller.ControllerGeneratorUtils.happyPathResponse(ControllerGeneratorUtils.kt:27)
	at com.cjbooms.fabrikt.generators.controller.SpringControllerInterfaceGenerator.buildFunction(SpringControllerInterfaceGenerator.kt:71)
	at com.cjbooms.fabrikt.generators.controller.AnnotationBasedControllerInterfaceGenerator.buildController(AnnotationBasedControllerInterfaceGenerator.kt:36)
	at com.cjbooms.fabrikt.generators.controller.SpringControllerInterfaceGenerator.generate(SpringControllerInterfaceGenerator.kt:50)
	at com.cjbooms.fabrikt.generators.controller.SpringControllerInterfaceGenerator.generate(SpringControllerInterfaceGenerator.kt:36)
	at com.cjbooms.fabrikt.cli.CodeGenerator.controllers(CodeGenerator.kt:98)
	at com.cjbooms.fabrikt.cli.CodeGenerator.generateControllerInterfaces(CodeGenerator.kt:47)
	at com.cjbooms.fabrikt.cli.CodeGenerator.generateCode(CodeGenerator.kt:39)
	at com.cjbooms.fabrikt.cli.CodeGenerator.generate(CodeGenerator.kt:34)
	at com.cjbooms.fabrikt.cli.CodeGen.generate(CodeGen.kt:65)
	at com.cjbooms.fabrikt.cli.CodeGen.main(CodeGen.kt:38)

The rest of the tooling we use for openapi has no problems with recognizing such schemas, so I think in theory this should work with fabrikt as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions