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][dart / dart-dio] additionalProperties crashes the generator in oneOf objects on OAS 3.1 #20441

Open
5 of 6 tasks
Victoria-Casasampere-BeeTheData opened this issue Jan 10, 2025 · 0 comments · May be fixed by #20475
Open
5 of 6 tasks

Comments

@Victoria-Casasampere-BeeTheData
Copy link
Contributor

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Defining additionalProperties (set either to true or false) in a schema of type: object with a oneOf property, crashes both dart generators when using the OAS version 3.1. The generators do not crash when using OAS version 3.0.
This issue is not present in other generators (I have tried all C++ generators, all Rust generators, TS angular, python fastapi and JS)

openapi-generator version

I have found the issue is present on 7.11.0-SNAPSHOT, and it goes all the way back to at least 7.9.0, and may go even further back.

OpenAPI declaration file content or URL
openapi: 3.1.1 # error
#openapi: 3.0.4 # works

info:
  title: Dart API
  version: 1.0.0
  description: Dart generator crash

paths:
  /user:
    get:
      summary: User API
      description: "User API description"
      responses:
        '204':
          description: Success

components:
  schemas:
    mainType:
      type: object
      additionalProperties: true
      oneOf:
        - type: integer
Generation Details

Default settings, with either the dart or dart-dio generators, with any openapi: 3.1 schema that uses additionalProperties in a schema with a oneOf property.

Steps to reproduce
  • Use the provided definition using openapi: 3.1.1
  • java -Dcolor -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g dart -o outoutout -i test.yaml or -g dart-dio
  • Crash!
Exception in thread "main" java.lang.RuntimeException: Could not process model 'mainType'.Please make sure that your schema is correct!
	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:528)
	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:453)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:1303)
	at org.openapitools.codegen.cmd.Generate.execute(Generate.java:535)
	at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.ClassCastException: class io.swagger.v3.oas.models.media.JsonSchema cannot be cast to class io.swagger.v3.oas.models.media.ComposedSchema (io.swagger.v3.oas.models.media.JsonSchema and io.swagger.v3.oas.models.media.ComposedSchema are in unnamed module of loader 'app')
	at org.openapitools.codegen.languages.AbstractDartCodegen.fromProperty(AbstractDartCodegen.java:596)
	at org.openapitools.codegen.DefaultCodegen.addParentContainer(DefaultCodegen.java:5777)
	at org.openapitools.codegen.DefaultCodegen.addAdditionPropertiesToCodeGenModel(DefaultCodegen.java:3614)
	at org.openapitools.codegen.DefaultCodegen.updateModelForObject(DefaultCodegen.java:2853)
	at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:3077)
	at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1765)
	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:523)
	... 5 more
Related issues/PRs

None

Suggest a fix

I cannot find the reason as to why the crash happens, but there are a few issues with the dart generators and additionalProperties already reported, which may or may not be related and could fix the issue if they get fixed.

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

Successfully merging a pull request may close this issue.

1 participant