OpenAPITools / OpenAPITools/openapi-generator

[BUG][Default][Java][Spring][Typescript-Angular][...?] Different behavior resolving Enum schema referred from sub directories between Linux and Windows generator

Open
#17,856 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)? impossible due $refs, but generator generates OK
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

Enum schemas are generated with additional Prefix which comes from subdirectory name, if object is referred from different files.

openapi-generator version

at lest 7.0.0 - up to master from 2024-03-04 23:00 CET

OpenAPI declaration file content or url

./api.yaml

openapi: 3.0.3
info:
  title: Example of issue with resolving enum names between Windows and Linux generation
  description: potato
  version: 1.0.0
paths:
  /hello-world:
    get:
      summary: whatever
      operationId: whateverGet
      responses:
        '200':
          description: ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ResponseModel'
components:
  schemas:
    ResponseModel:
      properties:
        someEnumField:
          $ref: './shared/shared.yaml#/components/schemas/SomeEnum'

./schemas/some-enum.yaml

type: string
enum:
  - one
  - two

./shared/shared.yaml

title: shared models between apis
components:
  schemas:
    SomeEnum:
      $ref: '../schemas/some-enum.yaml'
Generation Details

Issue looks global - happens on Spring Server stubs generation, Java Client, TypeScript Angular client... I've didn't tested other generators. This ticket only shows example from spring generator.

Also I've spent multiple hours to find similar issue or reason from generator codebase. My assumption and guess is that there's difference sanitizing symbol name because of different path separator in OSes.

Generator output (command below). Left Windows 10, right Debian
Left Windows, Right Linux

File difference
File difference

Yaml file regenerated from source (src/resources/openapi.yaml)
Output yaml file

Log differences (nothing important here imho)
Logs

Issue also appears using maven plugin.

Steps to reproduce
  1. Recreate those three yaml files like in section above
  2. Run on Windows (command from git-bash, doesn't matter):
➜  ./jdk-21.0.2/bin/java -jar /Tools/openapi/openapi-generator-cli-7.3.0.jar generate -i api.yaml -g spring
Related issues/PRs

Didn't found.

Suggest a fix

Align behavior in Windows to Linux output.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Recreate api.yaml, shared/shared.yaml, and schemas/some-enum.yaml, then run the documented spring generator command on Windows and Linux. Compare the generated enum names and trace the $ref resolution and path-separator handling; the work is done when both systems produce matching output.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, java, spring, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.