-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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] OpenAPI 4.0.2 not able to generate anyOf models. #4576
Comments
have you tried the latest version? |
yes the problem still exists with version 4.2.3 |
I'm also seeing this in |
I'm seeing this in the latest using the typescript-fetch generator. It improperly returns invalid javascript that points to a class, a typescript single pipe, and a function that isn't actually defined.
|
I am also getting inappropriate model generated for anyOf in golang generators,
It is generated like this. Any fix for this? |
Still seeing this in |
I have the same issue. Generating for Javascript. AnyOf file which is required in the model just doesn't exist. Looks like the generator does not generate it. No errors and warnings during the generation process.
Doesn't solves the problem |
I stumbled on the same bug and built a minimal reproduction before I found this issue. I am using OpenAPI spec:
|
We've implemented oneOf, anyOf support in other generators such as Java, C#, Python, PowerShell, Go, Ruby and more. If anyone has time to help with the implementation of oneOf/anyOf in the |
@wing328 |
@DennisNilssonB3 please try 5.1.0 or the latest stable version |
Same here, anyOf is not generating the necessary class when using spring generator spring-cloud library. Using latest generator, also tested on 6.0.0 latest snapshot and 5.2 latest snapshot just now. Using this schema Error:
type: object
example:
timestamp: '2021-05-19T16:56:04.969+00:00'
status: 409
error: Conflict
message: Application already exits
path: /public/subscriptions
properties:
timestamp:
type: string
format: date-time
status:
type: integer
error:
type: string
message:
type: string
debugMessage:
type: string
path:
type: string
errors:
type: array
items:
anyOf:
- $ref: '#/components/schemas/ValidationError'
ValidationError:
title: ValidationError
type: object
description: ''
properties:
object:
type: string
field:
type: string
rejectedValue:
type: object
message:
type: string and this configuration of the maven plugin: <plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.0</version>
<executions>
<execution>
<id>Java Spring server stub generation</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/openapi/subscription.yaml</inputSpec>
<generatorName>spring</generatorName>
<generateApis>true</generateApis>
<generateModels>true</generateModels>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>true</generateSupportingFiles>
<configOptions>
<unhandledException>true</unhandledException>
<library>spring-cloud</library>
<openApiNullable>false</openApiNullable>
<dateLibrary>java8</dateLibrary>
</configOptions>
<output>${project.build.directory}/generated-sources/java-server</output>
</configuration>
</execution>
</executions>
</plugin> |
I am having a similar issue with anyoff in Java and Python. I have tried 5.2.0 as well as 5.2.1 latest stable. The required class is missing in the generated code. This my swagger def:
Any idea how can we fix this |
I've tried 5.2.1 version for generation java server (as well as swagger-codegen) - it generates interface with name AnyOfobjectobjectobjectб but no realisation for this interface :-(((( @wing328 should i use some options during generation or to do something else? i tried simple way - "openapi-generator-cli generate -g java" |
@sauravInfoObject did you get a fix working yet? Could you share it, if so? Thanks a lot :) |
I just encountered the same problem today with openapi-generator-maven-plugin version 5.3.0 for generating java with resttemplate library. |
Same bug persists when generating java client with version 5.4 |
I'm running into the same issues using the Gradle plugin version 5.4.0 and the spring server generator. Anybody found a workaround for this issues perhaps? |
@wing328 Any ETA by which the issue will be fixed? |
the issue is happening for me while attempting to generate the openapi spec for Alpaca api, specifically for a java client using the resttemplate library |
Happens to me with 6.0.0-beta with java... |
Everyone is welcome to implement a fix |
After stumbling on this issue last year, I decided to create a new generator that would generate complex types (inline or not). It has been working great for me, you can find it here: https://github.com/Embraser01/typoas P.S.: The main goal here isn't to advertise my project, just to propose a solution to this issue. If wanted, I can remove the link to the project and let users find it through my profile |
resttempalte doesnt' support anyOf/oneOf yet. Only okhttp-gson, jersey2 and native supports anyOf/oneOf. We welcome PRs to plot the implementation of anyOf/oneOf to resttemplate or other libraries supported by the java client generator. |
I really appreciate the response @wing328 ! was just looking to be pointed in the right direction. I will use one of the other libraries! |
Hey @wing328 just in case to inform other people using go.
The result is the schema seems to generate but it looks like it is limited to the first element of the allOf or anyOff
Also we get some errors when producing |
@uri200 can you please give it another try in the latest master or stable version v6.6.0? I think it should be resolved. |
@wing328 I'm encountering a similar issue with the Go generator. The schema openapi: 3.0.2
info:
title: Minimal repro of anyOf bug
version: 1.0.0
servers:
- url: http://localhost:8080/api/v1
description: Development server
paths:
/:
get:
responses:
201:
description: Filler
components:
schemas:
Model:
type: object
required:
- value
properties:
value:
anyOf:
- type: number
- type: string
- type: array
items:
type: string
- type: array
items:
type: number run with openapi-generator generate \
-i ./schema.yaml \
-g go \
-o entity \
--global-property models,supportingFiles=utils.go,modelDocs=false \
--additional-properties enumClassPrefix=true,packageName=entity produces type ModelValue struct {
[]float32 *[]float32
[]string *[]string
float32 *float32
string *string
} which is invalid |
Description
I have created a swagger file
openapi: 3.0.0
having Account and Contact as references in anyOf something like this:openapi-generator version
4.0.2
Steps to reproduce
After running
mvn generate-sources
command swagger generates models in /target folder. The issue here is that swagger is not able to generate classAnyOfAccountContact
which it should be.The error looks like this:
The text was updated successfully, but these errors were encountered: