Skip to content

[BUG] [Spring] allOf conversion issue #21275

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

Open
4 of 5 tasks
giuseppe-pagliaro opened this issue May 13, 2025 · 0 comments
Open
4 of 5 tasks

[BUG] [Spring] allOf conversion issue #21275

giuseppe-pagliaro opened this issue May 13, 2025 · 0 comments

Comments

@giuseppe-pagliaro
Copy link

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

When a schema is extended, using allOf, and some constraints are applied to the properties of the original object, but the constraints are inserted above the reference to the original schema; the constraints are not applied in the generated code. Whereas, the swagger UI seems to render the schemas correctly.

openapi-generator version

version "7.12.0"

OpenAPI declaration file content or url
# Base Schema

    PlantOfferEditRequest:
      type: object
      properties:
        name:
          type: string
        imageURL:
          type: string
        averageDaysToHarvest:
          type: integer
        price:
          $ref: '#/components/schemas/Price'

# Not Working Schema

PlantOfferCreateRequest:
      allOf:
        - type: object
          properties:
            gardenId:
              type: integer
              format: int64
          required:
            - gardenId
            - name
            - imageURL
            - averageDaysToHarvest
            - price
        - $ref: '#/components/schemas/PlantOfferEditRequest'

# Working Schema

PlantOfferCreateRequest:
      allOf:
        - type: object
          properties:
            gardenId:
              type: integer
              format: int64
          required:
            - gardenId
        - $ref: '#/components/schemas/PlantOfferEditRequest'
        - type: object
          required:
            - name
            - imageURL
            - averageDaysToHarvest
            - price
Expected vs Actual Output

Expected:

public class PlantOfferCreateRequest {

private String name;

private String imageURL;

private Integer averageDaysToHarvest;

private Price price;

private Long gardenId;
}

Actual:

public class PlantOfferCreateRequest {

private @nullable String name;

private @nullable String imageURL;

private @nullable Integer averageDaysToHarvest;

private @nullable Price price;

private Long gardenId;
}

Generation Details

The gradle plugin configuration:

openApiGenerate {
    generatorName.set("spring")
    inputSpec.set("$projectDir/src/main/resources/openapi.yaml")
    outputDir.set("$buildDir/generated")
    apiPackage.set("com.myname.prjname.api")
    modelPackage.set("com.myname.prjname.model")
    configOptions.set(
        mapOf(
            "library" to "spring-boot",
            "useSpringBoot3" to "true",
            "language" to "Kotlin",
            "interfaceOnly" to "true",
            "useTags" to "true",
        	"useOperationId" to "true"
        )
    )
	typeMappings.set(
		mapOf(
			"Page" to "org.springframework.data.domain.Page",
			"Pageable" to "org.springframework.data.domain.Pageable",
			"Sort" to "org.springframework.data.domain.Sort",
			"PageGardenInfo" to "org.springframework.data.domain.Page<com.myname.prjname.model.GardenInfo>",
			"PagePlantOffer" to "org.springframework.data.domain.Page<com.myname.prjname.model.PlantOffer>",
			"PagePlantedPlant" to "org.springframework.data.domain.Page<com.myname.prjname.model.PlantedPlant>",
			"PageGardener" to "org.springframework.data.domain.Page<com.myname.prjname.model.Gardener>"
		)
	)
}
Steps to reproduce

1 - Create a schema with some non-required properties.
2 - Create another schema, using the allOf construct, that extends the first one.
3 - Add some constraints to the properties from the previous schema, listing above the reference to the previous schema.

Suggest a fix

Instead of iterating over the schemas and applying the constraints as they come, store them in a secondary location and apply them all at the end.

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