-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- 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
According to the docs for the jaxrs-spec generator it should support the x-field-extra-annotation extension on the OPERATION_PARAMETER level. This is false.
The generated code looks something like this:
@Path("/asset")
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", comments = "Generator version: 7.19.0")
public interface AssetApi {
@GET
@Path("/{id}")
@Produces({ "application/json" })
Response getAsset(@PathParam("id") UUID id,@HeaderParam("X-Locale") String xLocale);
}It should look like this instead.
@Path("/asset")
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", comments = "Generator version: 7.19.0")
public interface AssetApi {
@GET
@Path("/{id}")
@Produces({ "application/json" })
Response getAsset(@PathParam("id") @org.hibernate.validator.constraints.UUID(version = {7}) @jakarta.validation.constraints.NotNull UUID id);
}openapi-generator version
7.19.0
OpenAPI declaration file content or url
paths:
/asset/{id}:
get:
tags:
- asset
operationId: getAsset
parameters:
- $ref: "#/components/parameters/Identifier"
responses:
"200":
description: Asset found
components:
parameters:
Identifier:
name: id
in: path
required: true
schema:
type: string
format: uuid
nullable: false
description: |
The unique identifier of the resource. Must be a valid UUID.
# noinspection YAMLSchemaValidation
x-field-extra-annotation:
- "@org.hibernate.validator.constraints.UUID(version = {7})"
- "@jakarta.validation.constraints.NotNull"Generation Details
I use maven 3.9.11 and java 21 to generate my server files. The configuration is completely in the maven plugin under <configOptions>. For readability, these are the parameters I configured that affect the code generation:
generatorName: jaxrs-spec
configOptions:
library: quarkus
sourceFolder: src/gen/java/main
apiPackage: com.test
dateLibrary: java8
modelPackage: com.test.model
returnResponse: true
Steps to reproduce
- generate the code
- look into the generated
AssetApi.javafile and see that the annotations that should be on thegetAssetmethod are missing.
Related issues/PRs
Suggest a fix
The template for the jaxrs-spec generator looks like this:
JavaJaxRS/spec/queryParams.mustache
{{#isPathParam}}@PathParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}{{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}}{{#useMicroProfileOpenAPIAnnotations}}{{#description}} @org.eclipse.microprofile.openapi.annotations.parameters.Parameter(description="{{.}}"){{/description}}{{/useMicroProfileOpenAPIAnnotations}} {{{dataType}}} {{paramName}}{{/isPathParam}}In comparison the template for spring looks like this:
JavaSpring/queryParams.mustache
{{#isPathParam}}{{#vendorExtensions.x-field-extra-annotation}}{{{.}}} {{/vendorExtensions.x-field-extra-annotation}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}{{>paramDoc}} @PathVariable("{{baseName}}"){{>dateTimeParam}}{{#isDeprecated}} @Deprecated{{/isDeprecated}} {{>optionalDataType}} {{paramName}}{{/isPathParam}}The jaxrs-spec template seems to be missing the {{#vendorExtensions.x-field-extra-annotation}} templating parameter.