Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
5 tasks done
dexterxx-pl opened this issue Feb 13, 2024 · 2 comments

Comments

@dexterxx-pl
Copy link

dexterxx-pl commented Feb 13, 2024

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.

@dexterxx-pl
Copy link
Author

dexterxx-pl commented Mar 4, 2024

Yo, motivated that no one is interested in resolving this + listening complains colleges from work...

I've found, that this is Swagger Parser issue, placing logger just after loading specification:

# org/openapitools/codegen/config/CodegenConfigurator.java:653
         SwaggerParseResult result = new OpenAPIParser().readLocation(inputSpec, authorizationValues, options);
+        LOGGER.error("parser result: {}", result.getOpenAPI());

Linux:

        }, SomeEnum=class Schema {
            type: null
            format: null
            $ref: #/components/schemas/some-enum
            description: null
            title: null

Windows

        }, SomeEnum=class Schema {
            type: null
            format: null
            $ref: #/components/schemas/schemas\some-enum
            description: null
            title: null

I've bumped swagger-parser locally to latest 2.1.20, but didn't changes this behavior.

Looks like I need to redirect this issue to swagger-parser project...

edit:
Or even no -- looks like I've found PR that probably would resolve this issue -- swagger-api/swagger-parser#1959

@dexterxx-pl
Copy link
Author

Workaround for above example case

So you can use other tool to combine schema into one file, which won't refer any external files.

redocly bundle api.yaml -o api.yaml

and after that use generator on your file... should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant