Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Comments

Close side panel

Treat single element allOf/oneOf/anyOf schemas as the nested schema#39

Merged
liamnichols merged 6 commits intoCreateAPI:mainCreateAPI/CreateAPI:mainfrom
liamnichols:ln/inlining-testsliamnichols/CreateAPI:ln/inlining-testsCopy head branch name to clipboard
Jun 10, 2022
Merged

Treat single element allOf/oneOf/anyOf schemas as the nested schema#39
liamnichols merged 6 commits intoCreateAPI:mainCreateAPI/CreateAPI:mainfrom
liamnichols:ln/inlining-testsliamnichols/CreateAPI:ln/inlining-testsCopy head branch name to clipboard

Conversation

@liamnichols
Copy link
Member

@liamnichols liamnichols commented Jun 10, 2022

# Background

In our schema, we frequently do something like the following:

{
  "type": "object",
  "required": [
    "user"
  ],
  "properties": {
    "user": {
      "nullable": false,
      "allOf": [
        {
          "$ref": "#/components/schemas/User"
        }
      ]
    }
  }
}

In the above example, the user property needs to be nullable, but the schema of the property is actually a reference to a non-nullable component. The semi-official (but not ideal) way that was established to handle this case is to nest the $ref in an allOf/anyOf/oneOf array and mark it as nullable (you can't have other annotations alongside $ref).

While this approach works in our Android code generator, and our server-side validator, it produces unexpected results in CreateAPI when using isInliningPropertiesFromReferencedSchemas because CreateAPI will attempt to inline the allOf as a new type instead of referencing the actual type as an optional property.

Changes

To reproduce the issue locally, I first needed to setup some test coverage since we hadn't tested it before now. To do that, I've added a new inlining.yml schema and setup a few scenarios that test this behaviour in general.

Finally, I applied the actual fix in 48237df

@liamnichols liamnichols marked this pull request as ready for review June 10, 2022 14:24
@liamnichols liamnichols requested review from ainame and imjn June 10, 2022 14:24
@liamnichols liamnichols self-assigned this Jun 10, 2022
@liamnichols
Copy link
Member Author

I have confirmed that this works as intended on a larger codebase too 👍

Copy link
Member

@imjn imjn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes and the tests both look great to me 👍🏽 Thank you 🥇

Sources/CreateAPI/Generator/Generator+Schemas.swift Outdated Show resolved Hide resolved
@liamnichols liamnichols merged commit ddd56c6 into CreateAPI:main Jun 10, 2022
@liamnichols liamnichols deleted the ln/inlining-tests branch June 10, 2022 15:33
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.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.