openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

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

Open dexterxx-pl opened this issue 2 years ago • 0 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] 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?
  • [x] Have you searched for related issues/PRs?
  • [x] 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

7.0.0 - 7.3.0 (+ older probably)

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.

dexterxx-pl avatar Feb 13 '24 15:02 dexterxx-pl