-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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][SPRING] x-field-extra-annotation missing in 6.5.0 #15408
Comments
@tofi86 could you please share plugin configuration/CLI command that you are using |
i'm seeing this from gradle plugin tasks.register('generateEventRouter', GenerateTask) {
generatorName.set("spring")
inputSpec.set(eventRouter)
outputDir.set("$buildDir/generated/openapi")
apiPackage.set("eventRouter.rest")
modelPackage.set("eventRouter.model")
configOptions.set([
interfaceOnly: "true"
])
} i tried versions back to |
@jkt628 can you create minimal reproducible example? I've tried latest master, but it works as expected |
@borsch sure, this is my maven configuration: <configuration>
<inputSpec>${project.basedir}/src/main/resources/test-15408.yaml</inputSpec>
<generatorName>spring</generatorName>
<library>spring-boot</library>
<apiPackage>org.example.backend.api.generated</apiPackage>
<invokerPackage>org.example.backend.api.generated.handler</invokerPackage>
<modelPackage>org.example.backend.data.generated</modelPackage>
<globalProperties>
<!--
Don't skip form model (multipart/form-data) generation as this has a bug as described in:
https://github.com/OpenAPITools/openapi-generator/issues/12036
-->
<skipFormModel>false</skipFormModel><!-- default: true -->
</globalProperties>
<configOptions>
<basePackage>org.example.backend.api</basePackage>
<configPackage>org.example.backend.api.v1.config</configPackage>
<!-- Use interfaceOnly pattern... -->
<interfaceOnly>true</interfaceOnly><!-- default: false -->
<!-- Use Java 8 LocalDate/LocalDateTime classes for dates -->
<dateLibrary>java8-localdatetime</dateLibrary><!-- default: java8 -->
<!-- Enable OpenAPI Jackson Nullable library for models -->
<openApiNullable>true</openApiNullable><!-- default: false -->
<!-- Use Bean Validation Impl. to perform BeanValidation -->
<useBeanValidation>true</useBeanValidation><!-- default: true -->
<performBeanValidation>true</performBeanValidation><!-- default: false -->
<!-- Use Optional<> classes for non-required request params -->
<useOptional>true</useOptional><!-- default: false -->
<!-- Hides the generation timestamp when files are generated -->
<hideGenerationTimestamp>true</hideGenerationTimestamp><!-- default: false -->
<!-- Do not generate springdoc/springfox docs -->
<documentationProvider>none</documentationProvider><!-- default: springdoc -->
</configOptions>
<typeMappings>
<typeMapping>time=java.time.LocalTime</typeMapping>
</typeMappings>
</configuration> And this is the test spec I was using for the example: openapi: 3.0.3
info:
title: "API"
description: "REST API"
version: 0.0.1
license:
name: "GNU General Public License v3.0"
url: "https://choosealicense.com/licenses/gpl-3.0/"
contact:
name: "Team"
email: "[email protected]"
url: "https://www.example.org.de"
servers:
- url: http://localhost:8080
description: Local development server
components:
securitySchemes:
BearerAuth:
description: JWT authorization header using the Bearer scheme.
type: http
scheme: bearer
bearerFormat: JWT
schemas:
CompanyDto:
type: object
properties:
priceCategory:
description: The price category
nullable: true
x-field-extra-annotation: '@IgnoreForRoles("MEDIA_ADMIN")'
allOf:
- $ref: '#/components/schemas/SamplingPriceCategoryEnum'
SamplingPriceCategoryEnum:
description: The price category of a sampling action
type: string
enum:
- FREE
- PRICE_TIER_1
- PRICE_TIER_2
security:
- bearerAuth: [ ]
paths:
/company:
summary: Represents a Company Generated Java code looks like this: public class CompanyDto {
private JsonNullable<SamplingPriceCategoryEnum> priceCategory = JsonNullable.undefined();
public CompanyDto priceCategory(SamplingPriceCategoryEnum priceCategory) {
this.priceCategory = JsonNullable.of(priceCategory);
return this;
}
/**
* Get priceCategory
* @return priceCategory
*/
@Valid
@JsonProperty("priceCategory")
public JsonNullable<SamplingPriceCategoryEnum> getPriceCategory() {
return priceCategory;
}
public void setPriceCategory(JsonNullable<SamplingPriceCategoryEnum> priceCategory) {
this.priceCategory = priceCategory;
}
... |
minimal(ish) example: https://github.com/jkt628/x-field-extra-annotation |
i found an ugly way to at least mark the first field with |
Unfortunately you can't use both EventRouterMessage:
type: object
x-class-extra-annotation: |-
@javax.persistence.Entity
@javax.persistence.Table(name="event_router_requests")
properties:
guid:
x-field-extra-annotation: |-
@javax.persistence.Id
@javax.persistence.Column(name = "id")
type: string <--- this is the change. use direct configuration here instead of $ref
pattern: '^[0-9A-Fa-f]{8}-(?:[0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$'
accounting:
$ref: '#/components/schemas/Accounting'
event:
$ref: '#/components/schemas/Event' |
@tofi86 same issue with yours spec - swagger can't handle both CompanyDto:
type: object
properties:
priceCategory:
description: The price category
nullable: true
x-field-extra-annotation: '@IgnoreForRoles("MEDIA_ADMIN")'
type: string <---- this is the change. Move enum here instead of allOf + $ref
enum:
- FREE
- PRICE_TIER_1
- PRICE_TIER_2
title: SamplingPriceCategoryEnum |
@borsch Sure, this could be a valid solution for this issue. But on the other hand
|
Oh, now I see the |
I'll check 6.4.0 version |
unfortunately, i'm coming around to recognize openapi-generator is just not flexible enough for what i want to do without a lot of customization. in the long run it will be more maintainable to find another way to meet my needs. |
@borsch why closed? You wanted to check v6.4.0 where this worked 🤷 |
@tofi86 could you please create minimal project which generate expected code with 6.4.0, but not with 6.5.0. I've tried this project, but getting same code with both versions
Also based on diff v6.4.0...v6.5.0 I also haven't found anything suspicious yet |
@borsch cannot speak for the repo you mentioned as it isn't mine. Did you try with my example code from further above? -> #15408 (comment) If this doesn't help or work for you I can try to set up a small project later today or tomorrow... |
@tofi86 I've finally found what the issue here. This regression was introduced after #14882 where special handling was added for @jkt628 BTW. This fix should also work for you if use simple change EventRouterMessage:
type: object
x-class-extra-annotation: |-
@javax.persistence.Entity
@javax.persistence.Table(name="event_router_requests")
properties:
guid:
x-field-extra-annotation: |-
@javax.persistence.Id
allOf: <-- this is the change from $ref to allOf+$ref
- $ref: '#/components/schemas/GUID' |
Bug Report Checklist
Description
openapi-generator version
regression in 6.5.0
OpenAPI declaration file content or url
This OA spec snippet
Expected Output
... produced the following output in v6.4.0 (using
openApiNullable = true
):Actual Output
... but produces the following in 6.5.0:
The text was updated successfully, but these errors were encountered: