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

Fix: Respect parent properties in case of merged schemas by allOf #1415

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

musaprg
Copy link

@musaprg musaprg commented Jan 2, 2024

fixes #697

Currently, oapi-codegen ignores original (parent) fields if allOf is defined. OpenAPI schema doesn't seem to refuse a combination of general fields (properties) and allOf.

For example, the following schema

    PersonWithMorePropertiesOutsideOfAllOf:
      type: object
      description: |
        This is a person record as returned from a Create endpoint. It contains
        all the fields of a Person, with an additional property outside of allOf directives.
      properties:
        additionalProperty:
          type: string
      required: [ additionalProperty ]
      allOf:
        - $ref: "#/components/schemas/Person"

will be converted into the following type definition, which seems to be wrong result.

type PersonWithMorePropertiesOutsideOfAllOf = Person

The expected result would be like:

type PersonWithMorePropertiesOutsideOfAllOf struct {
	// Embedded struct due to allOf(#/components/schemas/Person)
	Person `yaml:",inline"`
	// Embedded fields due to inline allOf schema
	AdditionalProperty string `json:"additionalProperty"`
}

The known approach is normalization as proposed in other similar project like REFACTOR_ALLOF_WITH_PROPERTIES_ONLY in opneapi-generator. This PR is inspired by the idea.

REFACTOR_ALLOF_WITH_PROPERTIES_ONLY: When set to true, refactor schema with allOf and properties in the same level to a schema with allOf only and, the allOf contains a new schema containing the properties in the top level.
https://github.com/OpenAPITools/openapi-generator/blob/8b5b5a74c333b809c5a651366656257ec8a6fef3/docs/customization.md?plain=1#L567

Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
… schema

Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
@musaprg
Copy link
Author

musaprg commented Jan 27, 2024

@jamietanna Would you take a look at this PR? Thanks.

@musaprg musaprg changed the title Respect parent properties in case of merged schemas by allOf fix: Respect parent properties in case of merged schemas by allOf Feb 14, 2024
@musaprg musaprg changed the title fix: Respect parent properties in case of merged schemas by allOf Fix: Respect parent properties in case of merged schemas by allOf Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More properties near allof are ignored
1 participant